Emulator Unit Test Fails Saying "Unable to establish connection on channel" - flutter

I use get_it for simple dependency injection. I have a function that I made sure is called when the app initializes as below:
void initDI() {
// ... the other providers and repositories ...
//--------- //
// Firebase //
//--------- //
// i reference these instances everywhere when i wanna access them
// such as providers, repositories, etc.
GetIt.I.registerLazySingleton<FirebaseAuth>(() => FirebaseAuth.instance);
GetIt.I.registerLazySingleton<FirebaseFirestore>(
() => FirebaseFirestore.instance,
);
GetIt.I.registerLazySingleton<FirebaseFunctions>(
() => FirebaseFunctions.instance,
);
}
In my test directory, I have a file named initializers.dart, which has setup functions for tests for convenience. One that concerns us is as follows:
// test/initializers.dart
Future<void> initFirebaseEmulatorUse() async {
// ensure widget bindings get initialized because firebase requires this for some reason
WidgetsFlutterBinding.ensureInitialized();
// initialize firebase app
await Firebase.initializeApp();
// use functions emulator because there is no mock or fake package for functions, which is reasonable
FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
// unregister default references
GetIt.I.unregister<FirebaseAuth>();
GetIt.I.unregister<FirebaseFirestore>();
// register with mocks and fakes
GetIt.I.registerLazySingleton<FirebaseAuth>(() => MockFirebaseAuth());
GetIt.I.registerLazySingleton<FirebaseFirestore>(
() => FakeFirebaseFirestore(),
);
}
And, an example test is as follows:
// import initializers, we'll need them
import '../initializers.dart';
void main() {
// use in setUpAll, once and for all
late FirebaseFirestore firebaseFirestore;
setUpAll(() {
// returning future here because i've seen setUpAll must return
// an instance of Future when it has to do something in the future
// so, marking it as async is not enough it seems
return Future(() async {
WidgetsFlutterBinding.ensureInitialized(); // just to be double sure
initDI();
await initFirebaseEmulatorUse();
firebaseFirestore = GetIt.I.get(); // get an instance of firestore
});
});
tearDownAll(() {
return Future(() async {
// ... do something to clear all documents in firestore? ...
// ... so it won't affect other tests? ...
// i need to access `firebaseFirestore` instance here to do it
});
});
test('do tests', () async {
// ... test stuff ...
});
}
However, this fails saying:
PlatformException(channel-error, Unable to establish connection on channel., null, null)
FirebaseCoreHostApi.initializeCore
✖ (setUpAll)
LateInitializationError: Local 'firebaseFirestore' has not been initialized.
dart:_internal LateError._throwLocalNotInitialized
main.<fn>.<fn>
===== asynchronous gap ===========================
dart:async new Future
main.<fn>
✖ (tearDownAll)
Exited (1)
When I go to the line where it throws this error, it actually throws in the tearDownAll.
Troubleshooting for a while, I think we've got two problems:
firebaseFirestore is not initialized while in tearDownAll. While I have it initialized in setUpAll, that probably means the Future I return from setUpAll does not finish fast enough until I reach tearDownAll. That's my guess.
That "Unable to establish connection on channel" message is, I believe, because somehow the Firebase cannot connect to my local emulator.
I've been trying to solve these with different methods for hours but couldn't find a way to solve it. Any blog post about setting up Firebase Emulator + Unit Testing is also appreciated. The posts that I've found so far couldn't get me figure out how I can connect to my local Firebase emulator. Thanks in advance.
Environment
Firebase Tools 11.19.0
get_it: ^7.2.0
firebase_core: ^2.3.0
firebase_auth: ^4.1.3
cloud_firestore: ^4.1.0
firebase_crashlytics: ^3.0.6
cloud_functions: ^4.0.5
firebase_analytics: ^10.0.6
fake_cloud_firestore: ^2.1.0 as dev
firebase_auth_mocks: ^0.9.2 as dev
Flutter Doctor
[✓] Flutter (Channel stable, 3.3.9, on Fedora Linux 36 (KDE Plasma) 6.0.14-200.fc36.x86_64, locale en_US.UTF-8)
• Flutter version 3.3.9 on channel stable at /home/erayerdin/.local/lib/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (4 weeks ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/erayerdin/.sdks/android/
• Platform android-33, build-tools 33.0.0
• ANDROID_SDK_ROOT = /home/erayerdin/.sdks/android
• Java binary at: /var/lib/snapd/snap/android-studio/125/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 14.0.5 (Fedora 14.0.5-2.fc36)
• cmake version 3.25.1
• ninja version 1.10.2
• pkg-config version 1.8.0
[✓] Android Studio (version 2021.3)
• Android Studio at /var/lib/snapd/snap/android-studio/125/android-studio
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] VS Code
• VS Code at /snap/code/current
• Flutter extension version 3.56.0
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Fedora Linux 36 (KDE Plasma) 6.0.14-200.fc36.x86_64
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.124
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!

Related

Cannot see Flutter Web activity history in Firebase Analytics

I have added Firebase Analytics to a game I have developed as a Flutter web project and can see real-time data bars coming through for users in the last 30 minutes, but cannot see any historic user or event data. I added Firebase to my project yesterday and had a number of users access it, but cannot see any record of those events today.
I have gone through the set-up process again to check that everything is set up correctly and I believe that it is.
Accessing the web site this morning, I saw a real-time record of me accessing the app as below:
However, the historic user activity over time graph shows nothing:
I have created a Singleton to be able to access the analytics instances as follows:
// Singleton class to hold the Analytics for for Firebase
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:septuple/firebase_options.dart';
class Analytics {
Analytics._();
// Generate an instance of the firebase analytics class
final FirebaseAnalytics analytics = FirebaseAnalytics.instance;
// Create an instance of this class as a singleton
static final Analytics _instance = Analytics._();
// Initialise firebase for the app
static Future<void> init() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
getData().setAnalyticsCollectionEnabled(true);
}
//Get the FirebaseAnalystics object to do event logging
static FirebaseAnalytics getData() {
return _instance.analytics;
}
}
I have initialised this in my main() method as follows:
void main() async {
//
// Initialise the Hive database
await Hive.initFlutter();
await Hive.openBox('septupleBox');
//
// Initialise firebase in the Analytics singleton to enable event logging
//
await Analytics.init();
//
// Run the app
runApp(Game());
}
I am logging events in my state manager class, for example when the user guesses the word, as follows:
void setWin(int attempts) {
// Log end of game and that the user guessed correctly
Analytics.getData().logLevelEnd(
levelName: 'septuple',
success: attempts,
);
gameState = GameState.win;
_box.put(_gameStateName, gameState.toString());
_game.gameTimer.startCountdown();
notifyListeners();
}
"logLevelEnd is a default event type so I am assuming that this should just appear in Firebase Analytics. Do I need to configure anything so that it actively captures and retains this?
I am using the following dependencies for the project:
dependencies:
flutter:
sdk: flutter
hive: ^2.2.3
hive_flutter: ^1.1.0
responsive_sizer: ^3.1.1
#flutter_launcher_icons: ^0.10.0
toggle_switch: ^2.0.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^2.3.0
firebase_analytics: ^10.0.6
And finally, I have a firebase_options.dart file that is configured for web.
For completeness, here is the output from flutter doctor -v:
flutter doctor -v
[√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [Version 10.0.22621.819], locale en-GB)
• Flutter version 3.3.9 on channel stable at D:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (10 days ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
• Android SDK at C:\Users\LaptopBob\AppData\Local\Android\Sdk
• Platform android-33, build-tools 32.0.0-rc1
• ANDROID_HOME = C:\Users\LaptopBob\AppData\Local\Android\Sdk
• ANDROID_SDK_ROOT = D:\Users\LaptopBob\Android_SDK\avd
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.20)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.32929.386
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[√] VS Code (version 1.73.1)
• VS Code at C:\Users\LaptopBob\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.54.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.819]
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.71
• Edge (web) • edge • web-javascript • Microsoft Edge 107.0.1418.56
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
As per this post, I have waited 24 hours for the data to come through (it is now 26 hours since I started getting bars on the "Users in last 30 minutes" panel).
Does anyone have any ideas why I am not seeing historic user or event data in Firebase Analytics?
The solution to this problem is "wait". The data turned up some time between 30 and 42 hours after the first event was posted to Firebase. Events from the following day also showed up (only 18 hours delay), so maybe there is an initial, longer delay when you first use the service. The only reference to updates I could find in the Firebase Analytics documentation says that the data is updated 'periodically' so I'm not sure how often the data will be updated.

Flutter - image picker issue at release apk

i am a newbe at programming, i am very interested in flutter(dart).
Now i am facing my first big problem and i hope someone can help me out.
I would like use the flutter image picker pakage to get a image from my gallary or camera and show my users on the screen. So far so good and it works on emulator, also on my device but just if its connected to my pc, but if i build a release apk and send it to any device it doesent work. Watch at the videos.
Here it works:
https://streamable.com/3nj93j
Here the release apk Version
https://streamable.com/ba7eil
What i tried:
I have found few similar problams and i thounght it is a storage problem, i used:
android:requestLegacyExternalStorage="true"
but it doesent help, also i tried set the sdk from 30 to 28, nothing helps
Update: I build the app-debug.apk and send it to my device, it works fine.
I dont get it why the app-relase.apk ist not working???
Here my Methode:
Future getImage() async {
PickedFile pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
I hope anyone have a idea
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.18363.1316], locale de-AT)
• Flutter version 1.22.6 at C:\Flutter\flutter
• Framework revision 9b2d32b605 (3 weeks ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:/Users/acas1/AppData/Local/Android/Sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = C:/Users/acas1/AppData/Local/Android/Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin installed
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• SM F916B (mobile) • R3CN80VJP2V • android-arm64 • Android 11 (API 30)

Error: TimeoutException Future not completed And TypeError: T.as is not a function at _Future.new.[_setValue]

I got this error while dealing with Flutter web and Firebase Storage:
Error: TimeoutException after 0:00:05.000000: Future not completed
at Object.createErrorWithStack (http://localhost:65534/dart_sdk.js:4478:12)
at Object._rethrow (http://localhost:65534/dart_sdk.js:37394:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:65534/dart_sdk.js:37388:13)
Then followed by this error (always in pairs)
TypeError: T.as is not a function
at _Future.new.[_setValue] (http://localhost:60098/dart_sdk.js:32317:11)
at Function._propagateToListeners (http://localhost:60098/dart_sdk.js:32660:30)
at async._AsyncCallbackEntry.new.callback (http://localhost:60098/dart_sdk.js:32357:27)
at Object._microtaskLoop (http://localhost:60098/dart_sdk.js:37220:13)
at _startMicrotaskLoop (http://localhost:60098/dart_sdk.js:37226:13)
at http://localhost:60098/dart_sdk.js:32848:9
I have spent the whole 2 days to figure out where this comes from.
So far with the best of my knowledge it seems to come from when I upload an image to Firebase Storage:
Here is the code:
final uploadTask = _storageRef.child(_path).put(_file,
fb.UploadMetadata(
contentType: _file.type, customMetadata: customMetaData));
// Listening to the progress.
final StreamSubscription<fb.UploadTaskSnapshot> stream =
uploadTask.onStateChanged.listen((event) => event);
stream.onDone(() {
uploadTask.cancel();
stream.cancel();
});
And just in case someone asks, here's my flutter doctor -v
[✓] Flutter (Channel dev, 1.20.0-0.0.pre, on Mac OS X 10.15.5 01, locale
en-US)
• Flutter version 1.20.0-0.0.pre at /Applications/flutter
• Framework revision d9653445f4 (7 days ago), 2020-06-09 18:43:03 -0400
• Engine revision e8c13aa012
• Dart version 2.9.0 (build 2.9.0-14.0.dev 5c1376615e)
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Applications/Android/sdk
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = /Applications/Android/sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 47.0.2-dev.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.46.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.11.0
[✓] Connected device (2 available)
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 83.0.4103.106
• No issues found!
Any help is appreciated. Thank you
I just encountered this issue too; it seems to be caused by some quirk in the JS-interop feature of dart (I created an issue in dart-lang/sdk attempting to get some clarification!)
The root cause of this particular problem was an issue with the internal implementation of the onStateChanged Stream in the UploadTask class, here.
The original code was defining the onCompletion callback of the UploadTask as:
var onCompletion = allowInterop(() => _changeController.close());
But whatever .close() was returning was unexpected in the js-interop layer and causing this crash, so I replaced it by:
var onCompletion = allowInterop(() {
_changeController.close();
});
Which did the trick, at least on the firebase_storage_web plugin I'm working on!
The fix has been published as firebase:^7.3.1
PS: Looking at the package:firebase code, I bet the OP wouldn't have any issues if they used uploadTask.future, instead of uploadTask.onStateChanged, but of course you can't have upload progress then. Docs.

What is _CompactLinkedHashSet in flutter?

I am trying to run my first flutter app and I am getting a redscreen error when I run it on my iPhone but it runs without a problem on the simulator:
type '_CompactLinkedHashSet' is not a subtype of type 'Widget'.
Does anyone know what this error refers to? The error-causing widget is a FutureBuilder. The type of the FutureBuilder is the same as the Future.
Flutter doctor:
[✓] Flutter (Channel dev, v1.18.0, on Mac OS X 10.15.4 19E287, locale en-AU)
• Flutter version 1.18.0 at /Users/Josh/Developer/flutter
• Framework revision 8f7327f83a (11 days ago), 2020-04-06 22:11:01 -0400
• Engine revision 49891e0653
• Dart version 2.8.0 (build 2.8.0-dev.20.0 1210d27678)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/Josh/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
class DisclaimerData {
bool agreed;
String version;
DisclaimerData({this.agreed, this.version});
}
class DisclaimerView extends StatefulWidget {
#override
_DisclaimerViewState createState() => _DisclaimerViewState();
}
class _DisclaimerViewState extends State<DisclaimerView> {
Future<DisclaimerData> _getAgreed() async {
final preferences = await SharedPreferences.getInstance();
final disclaimerValues = DisclaimerData();
disclaimerValues.agreed = preferences.getBool('disclaimer_agreed') ?? false;
disclaimerValues.version =
preferences.getString('disclaimer_version') ?? '0';
return disclaimerValues;
}
#override
Widget build(BuildContext context) {
return FutureBuilder<DisclaimerData>(
future: _getAgreed(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Scaffold(
...
_CompactLinkedHashSet is an alternative name for Set. It is internal default Set implementation that dart uses to optimize Set's data structure.
_CompactLinkedHashSet (default Set implementation) and _InternalLinkedHashMap (default Map) have good asymptotic storage efficiency as the size of the collection grows. They are always better than conveniently available alternatives above 10 elements and are designed for a better locality.
source:
https://github.com/dart-lang/sdk/issues/26081

Images are not visible during flutter_driver tests

When running UI tests with flutter driver the assets are not displayed on iPhone simulator. They are displayed when app is run in debug mode from VS Code.
I tried to reproduce it on the example project generated by flutter create -i swift -a kotlin --androidx --org com.example example but without success. I followed exactly the same process of introducing flutter_driver tests in both apps according to this article. Unfortunately, in my app the images are not shown, and in example app they appear just fine. I compared project.pbxproj and pubspec.yaml files and they look fine to me.
For instance my pubspec.yaml:
dev_dependencies:
flutter_driver:
sdk: flutter
test: any
flutter_test:
sdk: flutter
screenshots:
flutter:
uses-material-design: true
assets:
- assets/lang/pl.json
- assets/images/
Is there anything that can help me with this issue? What can I do to debug the problem?
Logs
Beware, this is a very long log output.
flutter drive --target=test_driver/app.dart --verbose
https://gist.github.com/orestesgaolin/861c4f191773ca152b400d97ced2daeb
Flutter doctor
flutter doctor -v
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.6 18G87, locale pl-PL)
• Flutter version 1.7.8+hotfix.4 at /Users/dominik/Library/flutter
• Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/dominik/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_SDK_ROOT = /Users/dominik/Library/Android/sdk
• Java binary at: /Users/dominik/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.5791312/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5
[✓] iOS tools - develop for iOS devices
• ios-deploy 1.9.4
[✓] Android Studio (version 3.5)
• Android Studio at /Users/dominik/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.5791312/Android Studio.app/Contents
• Flutter plugin version 37.1.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.37.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.3.0
[✓] Connected device (1 available)
• iPhone Xs Max • C1A5534A-AE3A-4FB3-95F6-993E351FF2D3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)
• No issues found!
So the solution was to create separate main_test.dart file that wraps whole app in DefaultAssetBundle like so:
runApp(DefaultAssetBundle(
bundle: TestAssetBundle(),
child: App(),
));
and TestAssetBundle is like so:
class TestAssetBundle extends CachingAssetBundle {
#override
Future<String> loadString(String key, {bool cache = true}) async {
final ByteData data = await load(key);
if (data == null) throw FlutterError('Unable to load asset');
return utf8.decode(data.buffer.asUint8List());
}
#override
Future<ByteData> load(String key) async => rootBundle.load(key);
}
And in app.dart you have to reference correct file:
import 'package:flutter_driver/driver_extension.dart';
import 'package:playoo_league_player/main_test.dart' as app;
void main() {
// This line enables the extension.
enableFlutterDriverExtension();
// Call the `main()` function of the app, or call `runApp` with
// any widget you are interested in testing.
app.main();
}
Full explanation can be found here: https://medium.com/#sardox.vl/flutter-test-and-randomly-missing-assets-in-goldens-ea959cdd336a
Those Images are not loading because of cache issues .For that we can
use
PRE CACHE IMAGES to preload the images
class App extends StatefulWidget {
#override
State<App> createState() => _AppState();
}
class _AppState extends State<App>{
late image image1
late image image2
#override
void initState() {
super.initState();
image1 = Image.asset('assets/images/');
image2 = Image.asset('assets/images/');
}
#override
void didChangeDependencies() {
pre cacheImage(image1.image, context);
pre cacheImage(image2.image, context);
super.didChangeDependencies();
}
#override
Widget build(BuildContext context) {
return Container
}
if it is multiple assets or images you can save this method as class and
initialise it from main.dart .