LastMonopoly / scaled_app

Scale the entire UI design proportionally, useful when your UI design is fixed-width.
https://pub.dev/packages/scaled_app
BSD 3-Clause "New" or "Revised" License
14 stars 8 forks source link

Trouble getting this to work with Modular ?? #16

Open UNIcodeX opened 3 months ago

UNIcodeX commented 3 months ago

I get the following error with the attached code

Error: Assertion failed: file:///C:/Users/jaredfields/scoop/apps/flutter/3.19.4/packages/flutter/lib/src/foundation/binding.dart:153:12 _debugInitializedType == null "Binding is already initialized to WidgetsFlutterBinding"

Could someone help? :)

import 'package:schedule/common/common.dart';
// import 'package:flutter/rendering.dart';

void main() async {
  initLog();
  await GetStorage.init();
  runAppScaled(
    ModularApp(
      module: ModularConfig(),
      child: StyledToast(
        locale: const Locale("en", "US"),
        child: const MyApp(),
      ),
    ),
    scaleFactor: (deviceSize) {
      const double widthOfDesign = 375;
      return deviceSize.width / widthOfDesign;
    },
  );
  // RendererBinding.instance.setSemanticsEnabled(true);
}

class ModularConfig extends Module {
  @override
  List<Bind> get binds => [
        // APP-WIDE BINDS
        Bind.singleton((i) => AppTitle()),
        Bind.singleton((i) => AppTheme()),
        Bind.singleton((i) => Persistence()),
        // SCHEDULE BINDS
        Bind.singleton((i) => Schedule()),
        Bind.singleton((i) => ScheduleTermsMenu()),
        Bind.singleton((i) => ScheduleCampusMenu()),
        // DIRECTORY BINDS
        Bind.singleton((i) => Directory()),
      ];

  @override
  List<ModularRoute> get routes => [
        ChildRoute(
          '/',
          child: (context, args) => const HomePage(),
        ),
        ChildRoute(
          '/schedule/',
          child: (context, args) => const SchedulePage(),
          transition: TransitionType.fadeIn,
        ),
        ChildRoute(
          '/schedule',
          child: (context, args) => const SchedulePage(),
          transition: TransitionType.fadeIn,
        ),
        ChildRoute(
          '/schedule/:season/:year',
          child: (context, args) => SchedulePage(
            season: args.params["season"],
            year: args.params["year"],
          ),
          transition: TransitionType.fadeIn,
        ),
        ChildRoute(
          '/schedule/:season/:year/:current',
          child: (context, args) => SchedulePage(
            season: args.params["season"],
            year: args.params["year"],
            current: args.params["current"],
          ),
          transition: TransitionType.fadeIn,
        ),
        ChildRoute(
          '/directory',
          child: (context, args) => const DirectoryPage(),
          transition: TransitionType.fadeIn,
        ),
        ChildRoute(
          '/directory/:campus',
          child: (context, args) => DirectoryPage(
            selectedCampus: args.params["campus"],
          ),
          transition: TransitionType.fadeIn,
        ),
        // ChildRoute('/other',
        //     child: (context, args) => const Other(),
        //     transition: TransitionType.fadeIn),
        WildcardRoute(
          child: (context, args) => const NotFoundPage(),
          transition: TransitionType.fadeIn,
        ),
      ];
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    Modular.get<Persistence>().init();
    Modular.get<AppTheme>().init();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    setState(() {
      globalContext = context;
    });
    final themeProvider = context.watch<AppTheme>();
    final titleProvider = context.watch<AppTitle>();
    return MaterialApp.router(
      title: titleProvider.title,
      debugShowCheckedModeBanner: false,
      themeMode: themeProvider.themeMode,
      theme: themeProvider.light,
      darkTheme: themeProvider.dark,
      routeInformationParser: Modular.routeInformationParser,
      routerDelegate: Modular.routerDelegate,
    );
  }
}