How to solve GoRouter.routeInformationProvider missing error? - flutter

The flutter team has given the following flutter project created by them, to learn from. https://github.com/flutter/codelabs/tree/main/boring_to_beautiful
through their codelab.
I cloned the repo and tried to start the app. But it throws the following error.
════════ Exception caught by widgets library
The following assertion was thrown building IconTheme(color: Color(0xdd000000)):
This GoRouteInformationParser needs to be used with GoRouteInformationProvider, did you forget to pass in GoRouter.routeInformationProvider to the Router constructor?
'package:go_router/src/go_route_information_parser.dart':
package:go_router/src/go_route_information_parser.dart:1
Failed assertion: line 148 pos 13: 'routeInformation is DebugGoRouteInformation'
From this error msg, I could understand that 'routeInformationProvider' seems to be missing. But is that possible in a working demo project given by the flutter team to learn from? Should I pass the routeInformationProvider? if so any docs, please.

Just add routeInformationProvider to MaterialApp.router.
Example:
final _router = GoRouter(
...
);
#override
Widget build(BuildContext context) {
return MaterialApp.router(
routeInformationProvider: _router.routeInformationProvider,
...
);
}

I also had this problem, but with the go_router version: ^4.1.0 and following this guide the problem is solved.

Edit: - This should not be marked as the correct answer, as it was just a workaround. Please mark Luca Iaconelli answer as the correct one
Previous answer:
Just go back to version 3.1.1 of GoRouter. It seems latest version has an issue

Add routeinformationProvider at MaterialApp root:
MaterialApp.router(
routeInformationProvider: goRouter.routeInformationProvider,//Add this line
routerDelegate: goRouter.routerDelegate,
routeInformationParser: goRouter.routeInformationParser,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.amber,
),
);

For me, it was solved when I added
the following line of code
routeInformationProvider: _router.routeInformationProvider,
before the following two lines of codes
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,

Related

EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK - WindowsException was thrown running a test: Error 0x00000000 - whilst running a widget test

This is the error message:
The following WindowsException was thrown running a test:
Error 0x00000000: The operation completed successfully.
I am trying to pumpWidget using a ChangeNotifierProvider.
await tester.pumpWidget(
ChangeNotifierProvider<PageViewModel>(
create: (_) => PageViewModel(),
child: MaterialApp(
home: Scaffold(
body: Page(),
),
),
),
);
Reason I am doing the above is because in my Page() I return a Consumer
return Consumer<PageViewModel>(
builder: (context, model, child) => Scaffold()
I don't understand what am I doing wrong.
I have split my problem into parts to understand what was I missing until I bumpped into this and I honestly cannot get out of it.
e.g
Returning just the MaterialApp and calling my page. I read the error message and I have fixed it with the guide flutter was giving.

Issue with Getx 4.6.1

After adding a get:^4.6.1 I got the below error.
Code:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter web One',
home: HomePage(),
);
}
}
Error:
const CupertinoApp({
^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:275:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/app.dart:217:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp.router({
^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:322:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/app.dart:166:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp({
^^^^^^^^^^^
and also if I try to downgrade getx version 4.6.1 to 4.3.8 still i am getting the same error and in the error, it shows get-4.6.1 version.
The above problem is happening in get version >= 4.6.0. Use the exact version below 4.6.0 withing using ^ sign, which upgrades the package to the maximum compatible version.
In pubspec.yaml use get package like below:
get: 4.5.1 #Don't use ^

Problem with update multiprovider flutter

I recently updated some dependencies of my flutter application and I had this problem with the multiprovider, could someone guide me on how is the new syntax or what is the problem here?
the previous provider dependency I was working with was ^ 3.0.0 + 1, now it is at 5.0.0
Never post images of your code, we can't copy from it or reproduce it. Here's a setup of some multiproviders in a project I have:
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<UserState>(create: (ctx) => UserState()),
ChangeNotifierProvider<Cart>(create: (ctx) => Cart()),
ChangeNotifierProvider<LocationProvider>(create: (ctx) => LocationProvider()),
],
child: MaterialApp(theme: ThemeData(
primarySwatch: Colors.blue,
),home: Consumer<UserState>(builder: (context, userState, __) {
if (userState.firstRun) {
userState.getLastUser();
}
return userState.isSignedin ? CustomDrawer(appUser: userState.user) : LoginPageScreen();
}),
),
);
}
There are changes between provider ^3 and ^5, the documentation is pretty decent and does a good job explaining things. The code I posted is using provider: ^5.0.0.

Flutter auto_route, getter 'key' was called on null

import 'package:myapp/core/routes/router.gr.dart' as app_router;
child: MaterialApp(
title: 'MyApp',
debugShowCheckedModeBanner: false,
builder: ExtendedNavigator.builder<app_router.Router>(
router: app_router.Router()
),
I have implememented autoroute however I get an error here that the getter key was called on null
As Masnun pointed out, commenting out the line 37 solves the issue. However, there is a different solution that doesn't involve touching the source of the auto_route.
I fixed this issue by removing .builder from:
builder: ExtendedNavigator.builder(
router: Router(),
...
),
and changed to
builder: ExtendedNavigator(
router: Router(),
...
),
The problem is here is this line (line 37).
key: GlobalObjectKey(nav.key),
Commenting out the line from library works fine for me. It may be a temporary problem.

how to run firstapp flutter 1.5

i tryed testdrive for flutter installed on windows as here https://flutter.dev/docs/get-started/test-drive
defaut application generated work, well, but when i try to follow the snd part at
https://flutter.dev/docs/get-started/codelab
i get errors:
error: The function 'MyApp' isn't defined. (undefined_function at [flutter_app007] lib\main.dart:3)
error: 'MaterialApp' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:8)
error: 'Scaffold' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:10)
error: 'AppBar' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:11)
for this code in main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: const Text('Hello World'),
),
),
);
}
}
i checked flutter doctor, but show nothing bad.. any idea?
go to the project directory and open windows cmd. and try flutter run
ok, i finally resolved the problem.
when i was typed 'flutter_console.bat', i was get after, 'mysql is unknow program '. i finally founded that an install of MySQL Fabric 1.5 & MySQL Utilities 1.5\ setted his path in PATH env variable. this path poisonned result path integration , returning 'mysql is unknow program' and stopping project generation.. . desinstalling the mysql software solved the problem by cleaning path from his entry and now, the project can be created and work as expected..
very strange, no..?