TopAppWidget constructor

const TopAppWidget({
  1. Key? key,
  2. dynamic didChangeAppLifecycleState(
    1. AppLifecycleState
    )?,
  3. Widget onWaiting()?,
  4. List<Future> ensureInitialization()?,
  5. Widget onError(
    1. dynamic error,
    2. void refresh()
    )?,
  6. required Widget builder(
    1. BuildContext
    ),
})

Widget to put on top of the app.

It disposes all non auto disposed injected model when the app closes.

Useful also to dispose resources and reset injected states for test.

It is also use to provide and listen to InjectedTheme, InjectedI18N

It can also be used to display a splash screen while initialization plugins.

Example of TopAppWidget used to provide InjectedTheme and InjectedI18N

Provide and listen to the InjectedTheme.

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return TopAppWidget(//Use TopAppWidget
      injectedTheme: themeRM, //Set the injectedTheme
      injectedI18N: i18nRM, //Set the injectedI18N
      builder: (context) {
        return MaterialApp(
          //
          theme: themeRM.activeTheme(),
          //
          locale: i18nRM.locale,
          localeResolutionCallback: i18nRM.localeResolutionCallback,
          localizationsDelegates: i18n.localizationsDelegates,,
          home: HomePage(),
        );
      },
    );
  }
}

Implementation

const TopAppWidget({
  Key? key,
  Function(AppLifecycleState)? didChangeAppLifecycleState,
  Widget Function()? onWaiting,
  List<Future> Function()? ensureInitialization,
  Widget Function(dynamic error, void Function() refresh)? onError,
  // this.injectedAuth,
  required this.builder,
})  : _onWaiting = onWaiting,
      _onError = onError,
      _ensureInitialization = ensureInitialization,
      _didChangeAppLifecycleState = didChangeAppLifecycleState,
      assert(
        ensureInitialization == null || onWaiting != null,
        'You have to define a waiting splash screen '
        'using onWaiting parameter',
      ),
      super(key: key);