Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with auto_route package after upgrading flutter to 1.22.0

Tags:

flutter

dart

yesterday, I've upgraded flutter to version 1.22.0, and every thing is ok except of this error

Couldn't infer type parameter 'T'. Tried to infer 'dynamic' for 'T' which doesn't work: Type parameter 'T' declared to extend 'RouterBase'. The type 'dynamic' was inferred from: Parameter 'router' declared as 'T' but argument is 'dynamic'. Consider passing explicit type argument(s) to the generic.

this is the code I have

return MaterialApp(
builder: ExtendedNavigator.builder(router: Router()),
...
);

I'm using the auto_route package

like image 648
Adnan Alshami Avatar asked Oct 03 '20 05:10

Adnan Alshami


2 Answers

There is a Type to be associated with the builder constructor now.

try this,

import 'auto_route/auto_route.dart';
import 'router.gr.dart' as r;


  return MaterialApp(
   builder: ExtendedNavigator.builder<r.Router>(router: r.Router()),
   ...
  );

I faced issues that Router was defined in multiple files so use an alias while importing if you face such an issue like above.

like image 198
sameer kashyap Avatar answered Nov 19 '22 08:11

sameer kashyap


This is due to conflict between Router class in library 'package:flutter/src/widgets/router.dart' and the generated file 'router.gr.dart'.

If you are not using the Router class from 'package:flutter/src/widgets/router.dart' in the same file you can hide it while importing material package.

Like:

import 'package:flutter/material.dart' hide Router;

More info on hide

like image 36
Amareesh BP Avatar answered Nov 19 '22 10:11

Amareesh BP