fix: Flutter error when running tests with Flutter drive

This commit is contained in:
Blazebrain 2025-01-16 15:51:30 +01:00
parent 5060cbe55e
commit 85f8ebbfef
2 changed files with 27 additions and 1 deletions

View file

@ -23,6 +23,7 @@ import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/root/root.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/authentication_store.dart';
import 'package:cake_wallet/test_asset_bundles.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
@ -80,8 +81,18 @@ Future<void> runAppWithZone({Key? topLevelKey}) async {
ledgerFile.writeAsStringSync("$content\n${event.message}");
});
}
// Basically when we're running a test
if (topLevelKey != null) {
runApp(
DefaultAssetBundle(
bundle: TestAssetBundle(),
child: App(key: topLevelKey),
),
);
} else {
runApp(App(key: topLevelKey));
}
runApp(App(key: topLevelKey));
isAppRunning = true;
}, (error, stackTrace) async {
if (!isAppRunning) {

View file

@ -0,0 +1,15 @@
import 'dart:convert';
import 'package:flutter/services.dart';
class TestAssetBundle extends CachingAssetBundle {
@override
Future<String> loadString(String key, {bool cache = true}) async {
final ByteData data = await load(key);
return utf8.decode(data.buffer.asUint8List());
}
@override
Future<ByteData> load(String key) async => rootBundle.load(key);
}