Flutter auto_route, getter 'key' was called on null - flutter

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.

Related

couldn't create named routes in Flutter

I defined needed routes in Material App and everything works fine, bit I have to add another button which should lead to authorisation page and now I am getting this error:
The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/changeUsers", null) in the _WidgetsAppState.
Make sure your root app widget has provided a way to generate
this route.
Generators for routes are searched for in the following order:
1. For the "/" route, the "home" property, if non-null, is used.
2. Otherwise, the "routes" table is used, if it has an entry for the route.
3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "home" and "routes".
4. Finally if all else fails onUnknownRoute is called.
My code look like this:
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => const AuthorizationPage(),
'/adminLogin': (context) => const AuthInsertLogging(),
'/mainPageUsers': (context) => const TabBarBottomUsers(),
'/mainPageAdmin': (context) => const TabBarBottom(),
"/logout": (_) => new AuthorizationPage(),
'/changeUsers': (_) => AuthorizationPage(),
},
);
}
This is the button I tried to make route:
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/changeUsers');
},
child: Text(
'Change User',
style: GoogleFonts.montserrat(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w500,
letterSpacing: 2),
),
This is because you use the AuthorizationPage for '/' home, '/logout' and '/changeUsers' routes. There is a rule for routes property in Flutter documentation. See details here
If home is specified, then it implies an entry in this table for the
Navigator.defaultRouteName route ( here '/' ), and it is an error to
redundantly provide such a route in the routes table.
The rule says there must be only one home route ( here '/' route ) is specified. Here there are three routes pointing to same page.
So, just remove '/logout' and '/changeUers' routes and write onPressed function as follows.
Navigator.pushNamed(context, '/');

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.

How to solve GoRouter.routeInformationProvider missing error?

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,

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.

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..?