-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
lib/features/app_updates/wrappers/popup_notifications_wrapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:burrito/features/core/alerts/simple_dialog.dart'; | ||
import 'package:burrito/features/notifications/provider/notifications_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class PopupNotificationsWrapper extends ConsumerStatefulWidget { | ||
final Widget child; | ||
|
||
const PopupNotificationsWrapper({super.key, required this.child}); | ||
|
||
@override | ||
ConsumerState<ConsumerStatefulWidget> createState() { | ||
return PopupNotificationsWrapperState(); | ||
} | ||
} | ||
|
||
class PopupNotificationsWrapperState | ||
extends ConsumerState<PopupNotificationsWrapper> { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
final notifications = ref.read(notificationsProvider.notifier).getFuture(); | ||
|
||
notifications.then((notifications) async { | ||
final popups = notifications.where((n) => n.isPopup).toList(); | ||
if (popups.isEmpty) return; | ||
|
||
if (!mounted) return; | ||
|
||
for (final popup in popups) { | ||
final content = popup.content; | ||
if (popup.title == null || popup.content == null) return; | ||
|
||
await showDialog( | ||
context: context, | ||
barrierDismissible: true, | ||
builder: (context) { | ||
return SimpleAppDialog( | ||
title: popup.title!, | ||
content: content!, | ||
showAcceptButton: true, | ||
); | ||
}, | ||
); | ||
} | ||
}).catchError((e, st) { | ||
debugPrint('Error getting popup notifications: $e\n$st'); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return widget.child; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters