sunny_lifecycle 0.7.1 copy "sunny_lifecycle: ^0.7.1" to clipboard
sunny_lifecycle: ^0.7.1 copied to clipboard

outdated

Sunny Lifecycle

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:logging_config/logging_config.dart';
import 'package:sunny_lifecycle/modules/lifecycle_modules.dart';
import 'package:sunny_lifecycle/modules/testing_modules.dart';
import 'package:sunny_fluro/sunny_fluro.dart';
import 'package:sunny_lifecycle/routing/route_history.dart';
import 'package:sunny_lifecycle/routing2/fluro_routing_system.dart';
import 'package:sunny_lifecycle/routing2/frouter_portal.dart';
import 'package:sunny_lifecycle/sunny_lifecycle.dart';
import 'test_routing_widgets.dart';

final globalNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'global');
final tabNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'tabs');
final page1NavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'page1');
void main() async {
  var history = TestCaptureHistoryObserver();

  WidgetsFlutterBinding.ensureInitialized();
  var testAppWidget = await buildTestApp(historyObserver: history);

  runApp(testAppWidget);
}

Future<Widget> buildTestApp({String initialPage = '/', required HistoryObserver historyObserver}) async {
  configureLogging(LogConfig(handler: LoggingHandler.dev()));

  // var firebase = await Firebase.initializeApp();

  // final firebase = await Firebase.initializeApp();

  return await (AppBootstrap(
    identifier: 'TEST',
    appTitle: 'TEST',
    appInfo: TestAppInfoModule(),
    deviceInfo: TestDeviceInfoModule(),
    userPrefs: TestUserPrefsModule(),
    localization: TestLocalizationModule(),
    analyticsInit: DefaultAnalyticsModule([]),
    routing: FluroRoutingModule(
      path: initialPage,
      navigatorKey: globalNavigatorKey,
      preferUpdates: true,
      historyObservers: [historyObserver],
      initialRoute: initialPage,
      routes: buildMainRouter(historyObserver),
    ),
  ).buildRootWidget());
}

FRouter buildMainRouter(HistoryObserver observer) {
  final FRouter routes = newTestRouter();

  routes.page(
      "/",
      (context, parameters) => Builder(
            builder: (context) => Scaffold(
              bottomNavigationBar: RouteTestTabs(
                pageCount: 3,
              ),
              body: RoutingPortal(
                routing: FluroRoutingModule(
                  path: '/',
                  routes: buildTabRouter(observer),
                  preferUpdates: true,
                  navigatorKey: tabNavigatorKey,
                  initialRoute: '/page2',
                  historyObservers: [observer],
                ),
              ),
            ),
          ));

  return routes;
}

FRouter buildTabRouter(HistoryObserver observer) {
  final FRouter tabRoutes = newTestRouter();

  tabRoutes.page(
      "/page1",
      (context, parameters) => RoutingPortal(
            routing: FluroRoutingModule(
              routes: buildPage1Routes(),
              navigatorKey: page1NavigatorKey,
              preferUpdates: false,
              initialRoute: '/page1/home',
              historyObservers: [observer],
              path: '/page1',
            ),
          ));
  tabRoutes.page("/page2", (context, parameters) => RouteTestPage(title: 'Page 2'));
  tabRoutes.page("/page3", (context, parameters) => RouteTestPage(title: 'Page 3'));

  return tabRoutes;
}

FRouter buildPage1Routes() {
  final FRouter innerRoutes = newTestRouter();

  innerRoutes.page<dynamic, RouteParams>(
    "/page1/home",
    (context, params) => RouteTestPage(title: 'Page 1'),
  );
  innerRoutes.page<dynamic, RouteParams>("/page1/{recordId}", (context, parameters) {
    final recordId = parameters['recordId'] as String?;
    return RouteTestPage(title: 'Record ${recordId}');
  });

  return innerRoutes;
}

typedef WidgetListBuilder = List<Widget> Function(BuildContext context);