Browse Source

Merge pull request #314 from Leptopoda/cleanup/globalPopups

neon: make GlobalPopups a singleton
pull/316/head
Kate 2 years ago committed by GitHub
parent
commit
2067de09a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/neon/neon/lib/src/pages/home.dart
  2. 8
      packages/neon/neon/lib/src/router.dart
  3. 44
      packages/neon/neon/lib/src/utils/global_popups.dart

2
packages/neon/neon/lib/src/pages/home.dart

@ -93,6 +93,8 @@ class _HomePageState extends State<HomePage> {
} }
}); });
GlobalPopups().register(context);
unawaited(_checkMaintenanceMode()); unawaited(_checkMaintenanceMode());
} }

8
packages/neon/neon/lib/src/router.dart

@ -8,7 +8,6 @@ class AppRouter extends RouterDelegate<Account> with ChangeNotifier, PopNavigato
}); });
final AccountsBloc accountsBloc; final AccountsBloc accountsBloc;
final _globalPopups = const GlobalPopups();
@override @override
final GlobalKey<NavigatorState> navigatorKey; final GlobalKey<NavigatorState> navigatorKey;
@ -33,15 +32,10 @@ class AppRouter extends RouterDelegate<Account> with ChangeNotifier, PopNavigato
name: 'home', name: 'home',
child: Scaffold( child: Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Stack( body: HomePage(
children: [
_globalPopups,
HomePage(
key: Key(currentConfiguration!.id), key: Key(currentConfiguration!.id),
account: currentConfiguration!, account: currentConfiguration!,
), ),
],
),
), ),
), ),
], ],

44
packages/neon/neon/lib/src/utils/global_popups.dart

@ -1,30 +1,25 @@
part of '../../neon.dart'; part of '../../neon.dart';
class GlobalPopups extends StatefulWidget { class GlobalPopups {
const GlobalPopups({ factory GlobalPopups() => _instance ??= GlobalPopups._();
super.key, GlobalPopups._();
});
@override
State<GlobalPopups> createState() => _GlobalPopupsState();
}
class _GlobalPopupsState extends State<GlobalPopups> { static GlobalPopups? _instance;
late GlobalOptions _globalOptions; bool _registered = false;
late FirstLaunchBloc _firstLaunchBloc;
late NextPushBloc _nextPushBloc;
@override void register(final BuildContext context) {
void initState() { if (_registered) {
super.initState(); return;
}
_globalOptions = Provider.of<GlobalOptions>(context, listen: false); final globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false); final firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false);
_nextPushBloc = Provider.of<NextPushBloc>(context, listen: false); final nextPushBloc = Provider.of<NextPushBloc>(context, listen: false);
_firstLaunchBloc.onFirstLaunch.listen((final _) async { firstLaunchBloc.onFirstLaunch.listen((final _) async {
if (await _globalOptions.pushNotificationsEnabled.enabled.first) { if (await globalOptions.pushNotificationsEnabled.enabled.first) {
if (!mounted) { // ignore: use_build_context_synchronously
if (!context.mounted) {
return; return;
} }
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -45,7 +40,7 @@ class _GlobalPopupsState extends State<GlobalPopups> {
} }
}); });
_nextPushBloc.onNextPushSupported.listen((final _) async { nextPushBloc.onNextPushSupported.listen((final _) async {
await showDialog( await showDialog(
context: context, context: context,
builder: (final context) => AlertDialog( builder: (final context) => AlertDialog(
@ -72,8 +67,7 @@ class _GlobalPopupsState extends State<GlobalPopups> {
), ),
); );
}); });
}
@override _registered = true;
Widget build(final BuildContext context) => Container(); }
} }

Loading…
Cancel
Save