Relative Content

Tag Archive for androidflutterdartcircular-dependency

Cyclic dependency between `WidgetsFlutterBinding.ensureInitialized` and `HydratedStorage` in Flutter

I’ve inherited a very large Flutter project, and I’ve had to upgrade just about everything because of known security issues with some of the dependent packages.
I’ve run into a cyclic dependency issue.
I really don’t know much about flutter right now.
One of my widgets, AppWrapper has a MultiBlocProvider with three blocks, (at least) one of them is based on HydratedBloc<SessionEvent, SessionState>.
The problem is, the build method is being called during WidgetsFlutterBinding.ensureInitialized so it requires hydrated storage to be initialized.
But in order to initialize hydrated storage, I need a path.
So I’ve used getApplicationDocumentsDirectory from the path_provider package.
But of course (really? why?) getApplicationDocumentsDirectory() complains that WidgetsFlutterBinding.ensureInitialized was not called before calling it, hence, a circular dependency.
The block provider has an argument called lazy, I tried setting it to true, but to no avail, the create method is still being called and the circular dependency is still there.
The target is an Android device.
Any suggestions?