Could not find the correct Provider<minified:oq> error on web build
Closed this issue · 7 comments
Hi, provider works when I run Flutter on chrome with debug mode. But if I run in release mode or build, it gives me this error.
provider: 3.1.0+1
flutter doctor -v
flutter doctor -v
[✓] Flutter (Channel dev, v1.12.4, on Linux, locale en_US.UTF-8)
• Flutter version 1.12.4 at /home/mirkan/development/flutter
• Framework revision 2461c75600 (27 hours ago), 2019-11-18 12:26:51 -0500
• Engine revision 5fb7eb753b
• Dart version 2.7.0
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /home/mirkan/development/Android/
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /home/mirkan/development/Android/Sdk
• ANDROID_SDK_ROOT = /home/mirkan/development/Android/Sdk
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_232-b09)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Chrome - develop for the web
• Chrome at google-chrome
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/setup/#android-setup for detailed instructions).
[✓] IntelliJ IDEA Ultimate Edition (version 2019.2)
• IntelliJ at /snap/intellij-idea-ultimate/181
• Flutter plugin version 41.0.4
• Dart plugin version 192.7402
[✓] Connected device (2 available)
• Chrome • chrome • web-javascript • Google Chrome 78.0.3904.108
• Web Server • web-server • web-javascript • Flutter Tools
! Doctor found issues in 2 categories.
Hello!
That's fairly unlikely to be a bug with provider considering that logic works mainly through InheritedWidget.
Either it's a bug in the SDK, or on your side.
I am experiencing the same issue, using v1.12.15. The issue must be somewhere in the SDK. Maybe dart2js issue? Since on debug mode, the compiler used is dartdevc.
@mirkancal did you ever manage to solve the problem? Or are you using any other workaround?
One stupid question, on debug build, where are the files stored?
This is an example code that is not working:
Widget buildHome(AuthService authService) {
print('buildHome called ${authService.currentUser}');
if (authService.currentUser != null) {
if (authService.userData.claims['admin'] == true){
return AdminScreen();
} else {
return HomeScreen();
}
}
return StartScreen();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<AuthService>(
create: (_) => AuthService(),
child: Builder(
builder: (context) {
return Consumer<AuthService>(
builder: (_, authService, child) {
print('auth service consumer called ${authService.currentUser}');
return MaterialApp(
// debugShowCheckedModeBanner: false,
title: 'App',
home: buildHome(authService),
theme: _appTheme,
);
},
);
}
)
);
}
The log shows that the consumer is called once at start when the value is still null. After login, AuthService
calls notifyListener()
(confirmed by logging) but the Consumer is not called.
Can you please send a fully working minimalist example?
Alright, I will later today
We have solved the problem! We did it by eliminating all local file imports that was using package:
format to using relative paths. For example, previously we used the following import:
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:my_app/api/auth.dart';
Notice the third line, my_app
is the local package. This causes no problem in mobile build (iOS, android) and web debug mode, but issues (relating to Provider in our case) show up in web release or profile build. Then we changed the import into this:
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:../api/auth.dart';
It ran fine. Took me and my friend a while to discover that. Will try to reproduce on a minimalist project once we have more time, since we were chasing a deadline this past day.
Sounds weird
Consider raising an issue on https://github.com/flutter/flutter or https://github.com/dart-lang/sdk.
What you are explaining is not something that provider has any control over, and I cannot do anything to fix it.
Overall, most of the Provider.of logic is deferred to Flutter anyway, so if it breaks it's 99% sure that it is from Flutter or Dart