-
-
Notifications
You must be signed in to change notification settings - Fork 153
Can't register AutoRoute v6 with GetIt #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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<AutoRoute> 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<void> 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: