3 errors in any main.dart

I am getting those errors in any main.dart. Even those which worked fine before probably flutter of dart update.
The type of ‘_favQsApi’ can’t be inferred because it depends on itself through the cycle: _favQsApi, _userRepository.
The type of ‘_userRepository’ can’t be inferred because it depends on itself through the cycle: _favQsApi, _userRepository.
The type of ‘_routerDelegate’ can’t be inferred because it depends on itself through the cycle: _routerDelegate.

3 Likes

This error started to appear after flutter’s latest update, I am not exactly sure why though, but if you want it to work revert back to flutter 3.3.10 at most and the errors should be gone.
It would be nice to be able to use the same setup in the latest version of flutter, I am still trying to figure it out. Most probably what’s causing the problem is the deprecation of the RouteSettings.copywith function in flutter.

1 Like

Use the keyword “dynamic”:

late final dynamic _favQsApi = FavQsApi( ....
(...)
late final dynamic _routerDelegate = RoutemasterDelegate(
6 Likes

Dear @cznlde,

The book is written in a way that all the materials work with Flutter 3.3.0. Due to the fast-changing nature of the Flutter framework, we can’t guarantee that the app will work on the newer versions of Flutter. Therefore I strongly suggest that you downgrade Flutter to version 3.3.0, which should resolve your issues.

The materials will be updated to the latest version of Flutter with the next edition of the book.
Sincerely
Vid

1 Like

Unfortunately this doesn’t work anymore — at least for Flutter 3.7.12 & Dart 2.19.6 configuration.
Use this solution instead.

1 Like