Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions lib/widgets/reminder_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,55 @@ class _ReminderWidgetsState extends State<ReminderWidgets> {
),
);
children.addAll(
// the dismissible widgets that show each reminder, swiping left deletes the reminder
reminders.map(
(r) => ReminderWidget(
rtid: r.rtid,
stopName: getStopNameFromID(r.stpid),
eta: r.eta,
(r) => Dismissible(
key: Key('${r.stpid}|${r.rtid}'),
direction: DismissDirection.endToStart,
// the red background with the trash/delete icon that shows when swiping
background: Container(
color: Colors.red, // red background for delete action
alignment: Alignment.centerRight,
padding: EdgeInsets.only(right: 20.0),
child: Icon(Icons.delete, color: Colors.white), // white trash icon
),
// when the user swipes enough to dismiss
// try to remove the reminder from the service
// if it fails put the widget back
confirmDismiss: (direction) async {
try {
await IncomingBusReminderService.removeReminder(
r.stpid,
r.rtid,
);
return true;
} catch (e) {
if (kDebugMode) {
print('Failed to remove reminder: $e');
}
return false;
}
},
// if the reminder was successfully removed from the service
// also remove it from the local list so the widget disappears immediately
onDismissed: (_) {
// Remove from local list immediately so the dismissed
// widget leaves the tree before the async refresh.
setState(() {
reminders.removeWhere(
(x) => x.stpid == r.stpid && x.rtid == r.rtid,
);
});
_resetDataFuture();
},
// the actual reminder widget
child: ReminderWidget(
stpid: r.stpid,
rtid: r.rtid,
stopName: getStopNameFromID(r.stpid),
eta: r.eta,
onDismissed: _resetDataFuture,
),
),
),
);
Expand All @@ -231,14 +275,18 @@ class _ReminderWidgetsState extends State<ReminderWidgets> {
class ReminderWidget extends StatelessWidget {
const ReminderWidget({
super.key,
required this.stpid,
required this.rtid,
required this.stopName,
required this.eta,
this.onDismissed,
});

final String stpid;
final String rtid;
final String stopName;
final int? eta;
final VoidCallback? onDismissed; // called when the reminder is dismissed

@override
Widget build(BuildContext context) {
Expand Down