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" , ..);