further refactoring, conversion to stream
This commit is contained in:
@ -4,8 +4,12 @@ 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';
|
||||
import 'package:sendtrain/helpers/media_helpers.dart';
|
||||
import 'package:sendtrain/models/activity_timer_model.dart';
|
||||
import 'package:sendtrain/widgets/activities/activity_view.dart';
|
||||
import 'package:sendtrain/widgets/builders/dialogs.dart';
|
||||
import 'package:sendtrain/widgets/generic/elements/card_image.dart';
|
||||
import 'package:sendtrain/widgets/generic/elements/generic_progress_indicator.dart';
|
||||
|
||||
class ActivityCard extends StatefulWidget {
|
||||
final Activity activity;
|
||||
@ -43,49 +47,15 @@ class ActivityCardState extends State<ActivityCard> {
|
||||
: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: InkWell(
|
||||
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:
|
||||
ActivityView(activity: widget.activity)));
|
||||
},
|
||||
barrierDismissible: true,
|
||||
barrierLabel: '',
|
||||
context: context,
|
||||
pageBuilder: (context, animation1, animation2) {
|
||||
return Container();
|
||||
}),
|
||||
onTap: () => showGenericDialog(
|
||||
ActivityView(activity: widget.activity), context),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
// visualDensity: VisualDensity(horizontal: VisualDensity.maximumDensity),
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
|
||||
child: Container(
|
||||
// padding: EdgeInsets.only(top: 5, bottom: 5),
|
||||
width: 60,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.fill,
|
||||
image:
|
||||
findMediaByType(mediaItems, 'image')),
|
||||
// color: Colors.blue,
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.elliptical(8, 8)),
|
||||
),
|
||||
)),
|
||||
leading: CardImage(
|
||||
image: findMediaByType(mediaItems, 'image')),
|
||||
title: Consumer<ActivityTimerModel>(
|
||||
builder: (context, atm, child) {
|
||||
if (atm.activity?.id == widget.activity.id) {
|
||||
@ -112,95 +82,27 @@ class ActivityCardState extends State<ActivityCard> {
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
showRemovalDialog(
|
||||
'Activity Removal',
|
||||
'Would you like to permanently remove this activity from the current session?',
|
||||
context,
|
||||
ActivitiesDao(
|
||||
Provider.of<AppDatabase>(
|
||||
context,
|
||||
listen: false)),
|
||||
widget.activity)
|
||||
.then((result) {
|
||||
setState(() {});
|
||||
});
|
||||
},
|
||||
)
|
||||
])
|
||||
// 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'),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ))
|
||||
),
|
||||
])),
|
||||
],
|
||||
)),
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: SizedBox(
|
||||
height: 50.0,
|
||||
width: 50.0,
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
return GenericProgressIndicator();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
// Element is not found
|
||||
return const AssetImage('assets/images/placeholder.jpg');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user