7

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

Adnan Alshami
  • 949
  • 1
  • 7
  • 22

2 Answers2

11

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.

sameer kashyap
  • 1,121
  • 1
  • 9
  • 14
1

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