Closed lukeirvin closed 1 year ago
And that worked with the previous versions? What made it break, the version change of autoroute or get_it? Am 18. Okt. 2023, 00:56 +0200 schrieb lukeirvin @.***>:
I've just updated to the latest version of auto_route & get_it but I am getting a register error. Below I've provided examples of my setup. Here are my versions: Flutter - 3.13.7 Dart - 3.1.3 Xcode - 15.0 CocoaPods - 1.13.0 auto_route: ^7.8.4 get_it: ^7.6.4 auto_route_generator: ^7.0.0 build_runner: ^2.4.6 Error: Bad state: GetIt: Object/factory with type $AppRouter is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?) getit.dart: import 'package:get_it/get_it.dart'; import 'router.gr.dart';
GetIt getIt = GetIt.instance;
void setup() { getIt.registerSingleton($AppRouter); } router.dart: import 'package:auto_route/auto_route.dart'; import 'router.gr.dart';
@AutoRouterConfig() class AppRouter extends $AppRouter { @override List
get routes => [ // my routes ]; } app.dart: import 'package:auto_route/auto_route.dart'; import 'getit.dart'; import 'router.gr.dart'; @override Widget build(BuildContext context) { final appRouter = getIt<$AppRouter>();
return MaterialApp.router( routerConfig: appRouter.config(), routerDelegate: appRouter.delegate( navigatorObservers: () => [ AutoRouteObserver(), ], ), routeInformationParser: appRouter.defaultRouteParser(), builder: (BuildContext context, Widget? child) { // return... }, ); } main.dart: import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'app.dart'; import 'getit.dart';
Future
main() async { WidgetsFlutterBinding.ensureInitialized(); setup(); runApp(const MyApp()); } — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
I was able to resolve this. Closing this issue out.
I've just updated to the latest version of auto_route & get_it but I am getting a register error.
Below I've provided examples of my setup.
Here are my versions: Flutter - 3.13.7 Dart - 3.1.3 Xcode - 15.0 CocoaPods - 1.13.0 auto_route: ^7.8.4 get_it: ^7.6.4 auto_route_generator: ^7.0.0 build_runner: ^2.4.6
Error:
getit.dart:
router.dart:
app.dart:
main.dart: