session and activity delete
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:sendtrain/daos/activities_dao.dart';
|
||||
import 'package:sendtrain/daos/media_items_dao.dart';
|
||||
import 'package:sendtrain/database/database.dart';
|
||||
import 'package:sendtrain/extensions/string_extensions.dart';
|
||||
@ -56,7 +57,8 @@ class ActivityCardState extends State<ActivityCard> {
|
||||
return SlideTransition(
|
||||
position: custom,
|
||||
child: Dialog.fullscreen(
|
||||
child: ActivityView(activity: widget.activity)));
|
||||
child:
|
||||
ActivityView(activity: widget.activity)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
@ -91,37 +93,91 @@ class ActivityCardState extends State<ActivityCard> {
|
||||
maxLines: 1,
|
||||
"${widget.activity.title.toTitleCase()} (${formattedTime(atm.totalTime)})");
|
||||
} else {
|
||||
return Text(maxLines: 1, widget.activity.title.toTitleCase());
|
||||
return Text(
|
||||
maxLines: 1,
|
||||
widget.activity.title.toTitleCase());
|
||||
}
|
||||
},
|
||||
),
|
||||
subtitle: Text(maxLines: 2, widget.activity.description),
|
||||
trailing: IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: () {
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Activity Removal'),
|
||||
content: const Text(
|
||||
'Would you like to permanently remove this activity from the current session?'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(context, 'Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(context, 'OK'),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
)),
|
||||
subtitle:
|
||||
Text(maxLines: 2, widget.activity.description),
|
||||
contentPadding: EdgeInsets.only(left: 13),
|
||||
trailing: Flex(
|
||||
direction: Axis.vertical,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
IconButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
alignment: Alignment.topCenter,
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: () {
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) =>
|
||||
AlertDialog(
|
||||
title: const Text('Activity Removal'),
|
||||
content: const Text(
|
||||
'Would you like to permanently remove this activity from the current session?'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(
|
||||
context, 'Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => {
|
||||
ActivitiesDao(
|
||||
Provider.of<AppDatabase>(
|
||||
context,
|
||||
listen: false))
|
||||
.remove(widget.activity)
|
||||
.then((result) {
|
||||
setState(() {});
|
||||
}),
|
||||
Navigator.pop(context, 'OK')
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
])
|
||||
// trailing: FittedBox(
|
||||
// alignment: Alignment.topCenter,
|
||||
// fit: BoxFit.fitHeight,
|
||||
// child: IconButton(
|
||||
// padding: EdgeInsets.all(0),
|
||||
// alignment: Alignment.topCenter,
|
||||
// // visualDensity: VisualDensity.compact,
|
||||
// icon: Icon(Icons.close_rounded),
|
||||
// onPressed: () {
|
||||
// showAdaptiveDialog(
|
||||
// context: context,
|
||||
// builder: (BuildContext context) =>
|
||||
// AlertDialog(
|
||||
// title: const Text('Activity Removal'),
|
||||
// content: const Text(
|
||||
// 'Would you like to permanently remove this activity from the current session?'),
|
||||
// actions: <Widget>[
|
||||
// TextButton(
|
||||
// onPressed: () =>
|
||||
// Navigator.pop(context, 'Cancel'),
|
||||
// child: const Text('Cancel'),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () =>
|
||||
// Navigator.pop(context, 'OK'),
|
||||
// child: const Text('OK'),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ))
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
|
@ -44,6 +44,16 @@ class _ActivityViewState extends State<ActivityView> {
|
||||
blur: 10,
|
||||
),
|
||||
children: [
|
||||
FloatingActionButton.extended(
|
||||
icon: const Icon(Icons.upload_outlined),
|
||||
label: Text('Upload Media'),
|
||||
onPressed: () {},
|
||||
),
|
||||
FloatingActionButton.extended(
|
||||
icon: const Icon(Icons.note_add_outlined),
|
||||
label: Text('Add Note'),
|
||||
onPressed: () {},
|
||||
),
|
||||
FloatingActionButton.extended(
|
||||
icon: const Icon(Icons.history_outlined),
|
||||
label: Text('Restart'),
|
||||
@ -54,11 +64,6 @@ class _ActivityViewState extends State<ActivityView> {
|
||||
label: Text('Done'),
|
||||
onPressed: () {},
|
||||
),
|
||||
FloatingActionButton.extended(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
label: Text('Edit'),
|
||||
onPressed: () {},
|
||||
),
|
||||
]),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -1,6 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:sendtrain/daos/media_items_dao.dart';
|
||||
import 'package:sendtrain/daos/sessions_dao.dart';
|
||||
import 'package:sendtrain/database/database.dart' hide ActivityAction;
|
||||
import 'package:sendtrain/extensions/string_extensions.dart';
|
||||
import 'package:sendtrain/widgets/session_view.dart';
|
||||
@ -19,146 +22,193 @@ class SessionCard extends StatelessWidget {
|
||||
? Theme.of(context).colorScheme.primaryContainer
|
||||
: Theme.of(context).colorScheme.surfaceContainerLow;
|
||||
|
||||
if (type == 0) {
|
||||
return Card(
|
||||
color: color,
|
||||
margin: const EdgeInsets.fromLTRB(15, 15, 15, 0),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: InkWell(
|
||||
splashColor: Colors.deepPurple,
|
||||
onTap: () => showGeneralDialog(
|
||||
barrierColor: Colors.black.withOpacity(0.5),
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
transitionBuilder: (BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
Animation<Offset> custom = Tween<Offset>(
|
||||
begin: const Offset(0.0, 1.0),
|
||||
end: const Offset(0.0, 0.0))
|
||||
.animate(animation);
|
||||
return SlideTransition(
|
||||
position: custom,
|
||||
child: Dialog.fullscreen(child: SessionView(session: session)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
context: context,
|
||||
pageBuilder: (context, animation1, animation2) {
|
||||
return Container();
|
||||
}),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
|
||||
child: Container(
|
||||
width: 60,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
image:
|
||||
AssetImage('assets/images/placeholder.jpg')),
|
||||
// color: Colors.blue,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.elliptical(10, 10)),
|
||||
),
|
||||
)),
|
||||
title: Text(maxLines: 1, session.title.toTitleCase()),
|
||||
subtitle: Text(maxLines: 1, dateFormat.format(session.date as DateTime)),
|
||||
trailing: IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: () {
|
||||
showAdaptiveDialog(
|
||||
return FutureBuilder<List<MediaItem>>(
|
||||
future: MediaItemsDao(Provider.of<AppDatabase>(context))
|
||||
.fromSession(session),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
List<MediaItem> mediaItems = snapshot.data!;
|
||||
|
||||
if (type == 0) {
|
||||
return Card(
|
||||
color: color,
|
||||
margin: const EdgeInsets.fromLTRB(15, 15, 15, 0),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: InkWell(
|
||||
splashColor: Colors.deepPurple,
|
||||
onTap: () => showGeneralDialog(
|
||||
barrierColor: Colors.black.withOpacity(0.5),
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
transitionBuilder: (BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
Animation<Offset> custom = Tween<Offset>(
|
||||
begin: const Offset(0.0, 1.0),
|
||||
end: const Offset(0.0, 0.0))
|
||||
.animate(animation);
|
||||
return SlideTransition(
|
||||
position: custom,
|
||||
child: Dialog.fullscreen(
|
||||
child: SessionView(session: session)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Session Removal'),
|
||||
content: const Text(
|
||||
'Would you like to permanently remove this session?'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, 'Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, 'OK'),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
pageBuilder: (context, animation1, animation2) {
|
||||
return Container();
|
||||
}),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.only(left: 15),
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
|
||||
child: Container(
|
||||
width: 60,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
image:
|
||||
findMediaByType(mediaItems, 'image')),
|
||||
// color: Colors.blue,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.elliptical(10, 10)),
|
||||
),
|
||||
)),
|
||||
title: Text(maxLines: 1, session.title.toTitleCase()),
|
||||
subtitle: Text(
|
||||
maxLines: 1,
|
||||
dateFormat.format(session.date as DateTime)),
|
||||
trailing: IconButton(
|
||||
padding: EdgeInsets.all(0),
|
||||
alignment: Alignment.topCenter,
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: () {
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Session Removal'),
|
||||
content: const Text(
|
||||
'Would you like to permanently remove this session?'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => {
|
||||
Navigator.pop(context, 'Cancel'),
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => {
|
||||
SessionsDao(Provider.of<AppDatabase>(
|
||||
context, listen: false))
|
||||
.remove(session).then((result) {
|
||||
// ignore: invalid_use_of_protected_member
|
||||
(context as Element).reassemble();
|
||||
}),
|
||||
Navigator.pop(context, 'OK')
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.fromLTRB(15, 0, 15, 15),
|
||||
title: Text(
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontWeight: FontWeight.w300),
|
||||
session.content),
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.fromLTRB(15, 0, 15, 15),
|
||||
title: Text(
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
const TextStyle(fontWeight: FontWeight.w300),
|
||||
session.content),
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
} else {
|
||||
return Card(
|
||||
color: color,
|
||||
child: InkWell(
|
||||
// overlayColor: MaterialStateColor(Colors.deepPurple as int),
|
||||
splashColor: Colors.deepPurple,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.elliptical(10, 10)),
|
||||
onTap: () => showGeneralDialog(
|
||||
// barrierColor: Colors.black.withOpacity(0.5),
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
transitionBuilder: (BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
Animation<Offset> custom = Tween<Offset>(
|
||||
begin: const Offset(0.0, 1.0),
|
||||
end: const Offset(0.0, 0.0))
|
||||
.animate(animation);
|
||||
return SlideTransition(
|
||||
position: custom,
|
||||
child: Dialog.fullscreen(
|
||||
child: SessionView(session: session)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
context: context,
|
||||
pageBuilder: (context, animation1, animation2) {
|
||||
return Container();
|
||||
}),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
// color: const Color.fromARGB(47, 0, 0, 0),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
image: DecorationImage(
|
||||
colorFilter: ColorFilter.mode(
|
||||
Color.fromARGB(220, 41, 39, 39),
|
||||
BlendMode.hardLight),
|
||||
image: findMediaByType(mediaItems, 'image'),
|
||||
fit: BoxFit.cover),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(
|
||||
maxLines: 3,
|
||||
session.title.toTitleCase(),
|
||||
textAlign: TextAlign.center),
|
||||
subtitle: Text(
|
||||
maxLines: 1,
|
||||
dateFormat
|
||||
.format(session.date as DateTime),
|
||||
textAlign: TextAlign.center),
|
||||
),
|
||||
])))));
|
||||
}
|
||||
} else {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: SizedBox(
|
||||
height: 50.0,
|
||||
width: 50.0,
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ImageProvider findMediaByType(List<MediaItem> media, String type) {
|
||||
Iterable<MediaItem>? found = media.where((m) => m.type == MediaType.image);
|
||||
|
||||
if (found.isNotEmpty) {
|
||||
return NetworkImage(found.first.reference);
|
||||
} else {
|
||||
return Card(
|
||||
color: color,
|
||||
child: InkWell(
|
||||
// overlayColor: MaterialStateColor(Colors.deepPurple as int),
|
||||
splashColor: Colors.deepPurple,
|
||||
borderRadius: const BorderRadius.all(Radius.elliptical(10, 10)),
|
||||
onTap: () => showGeneralDialog(
|
||||
// barrierColor: Colors.black.withOpacity(0.5),
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
transitionBuilder: (BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
Animation<Offset> custom = Tween<Offset>(
|
||||
begin: const Offset(0.0, 1.0),
|
||||
end: const Offset(0.0, 0.0))
|
||||
.animate(animation);
|
||||
return SlideTransition(
|
||||
position: custom,
|
||||
child:
|
||||
Dialog.fullscreen(child: SessionView(session: session)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
context: context,
|
||||
pageBuilder: (context, animation1, animation2) {
|
||||
return Container();
|
||||
}),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
// color: const Color.fromARGB(47, 0, 0, 0),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
image: const DecorationImage(
|
||||
colorFilter: ColorFilter.mode(
|
||||
Color.fromARGB(220, 41, 39, 39),
|
||||
BlendMode.hardLight),
|
||||
image: AssetImage('assets/images/placeholder.jpg'),
|
||||
fit: BoxFit.cover),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(
|
||||
maxLines: 3,
|
||||
session.title.toTitleCase(),
|
||||
textAlign: TextAlign.center),
|
||||
subtitle: Text(
|
||||
maxLines: 1,
|
||||
dateFormat.format(session.date as DateTime),
|
||||
textAlign: TextAlign.center),
|
||||
),
|
||||
])))));
|
||||
// Element is not found
|
||||
return const AssetImage('assets/images/placeholder.jpg');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:sendtrain/daos/activities_dao.dart';
|
||||
import 'package:sendtrain/daos/sessions_dao.dart';
|
||||
|
||||
import 'package:sendtrain/database/database.dart';
|
||||
import 'package:sendtrain/extensions/string_extensions.dart';
|
||||
|
Reference in New Issue
Block a user