The error is within the go_router
package and is related to an assertion failure in the parser.dart
file. The specific assertion that failed is at line 63, position 12, and it checks whether routeInformation.state
is not null. The assertion is there to ensure that the state associated with a route is not null.
'package:go_router/src/parser.dart': Failed assertion: line 63 pos 12: 'routeInformation.state != null': is not true.
my AppRouts class
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:quizapp/screens/home/home.dart';
import '../../screens/error/error_page.dart';
import '../../screens/splash/splash_screen.dart';
import 'app_routers.dart';
class MyAppRouts {
GoRouter route = GoRouter(
routes: [
GoRoute(
name: MyAppRoutesConstent.splashScreenRoutename,
path: '/',
pageBuilder: (context, state) {
return const MaterialPage(child: SplashScreen());
},
),
GoRoute(
name: MyAppRoutesConstent.homeRoutename,
path: '/home',
pageBuilder: (context, state) {
return const MaterialPage(child: HomePage());
},
),
],
errorPageBuilder: (context, state) {
return const MaterialPage(child: ErrorPage());
},
);
}
Im new to GoRouter package what is the problem hear i need lord splash screen as my first screen and this is my main.dart file
import 'package:flutter/material.dart';
import 'project/routes/app_routers_const.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Quiz App',
debugShowCheckedModeBanner: false,
routeInformationParser: MyAppRouts().route.routeInformationParser,
routerDelegate: MyAppRouts().route.routerDelegate,
);
}
}
i need lord splash screen as my first screen
As per the documentation, configure the MaterialApp.router like this:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: MyAppRouts().route,
);
}
}
and set an initial path for splash screen:
GoRouter route = GoRouter(initialLocation : "/splashScreen" , ..);
if you are still wondering what's wrong just make sure you do this,
AppRouts class
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:quizapp/screens/home/home.dart';
import '../../screens/error/error_page.dart';
import '../../screens/splash/splash_screen.dart';
import 'app_routers.dart';
class MyAppRouts {
GoRouter route = GoRouter(
initialLocation: "/", // Any location you want to show first
routes: [
GoRoute(
name: MyAppRoutesConstent.splashScreenRoutename,
path: '/',
pageBuilder: (context, state) {
return const MaterialPage(child: SplashScreen());
},
),
GoRoute(
name: MyAppRoutesConstent.homeRoutename,
path: '/home',
pageBuilder: (context, state) {
return const MaterialPage(child: HomePage());
},
),
],
errorPageBuilder: (context, state) {
return const MaterialPage(child: ErrorPage());
},
);
}
main.dart
import 'package:flutter/material.dart';
import 'project/routes/app_routers_const.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Quiz App',
debugShowCheckedModeBanner: false,
routerConfig: MyAppRouts().route,
//make sure you must not add any other data like
//"routeInformationParser" and "routerDelegate" they'll cause error
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With