gpt4 book ai didi

flutter - flutter_driver 测试期间图像不可见

转载 作者:行者123 更新时间:2023-12-02 10:01:15 26 4
gpt4 key购买 nike

使用 flutter 驱动程序运行 UI 测试时, Assets 不会显示在 iPhone 模拟器上。当应用程序在 VS Code 中以 Debug模式运行时,它们会显示。

我尝试在 flutter create -i swift -a kotlin --androidx --org com.example example 生成的示例项目上重现它,但没有成功。根据本文,我遵循完全相同的过程在两个应用程序中引入 flutter_driver 测试。不幸的是,在我的应用程序中,图像没有显示,在示例应用程序中,它们看起来很好。我比较了 project.pbxproj 和 pubspec.yaml 文件,它们对我来说看起来不错。

例如我的 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/

有什么可以帮助我解决这个问题吗?我可以做什么来调试这个问题?

日志

请注意,这是一个非常长的日志输出。

flutter 驱动 --target=test_driver/app.dart --verbose

https://gist.github.com/orestesgaolin/861c4f191773ca152b400d97ced2daeb

flutter 医生

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!

最佳答案

因此,解决方案是创建单独的 main_test.dart 文件,将整个应用程序包装在 DefaultAssetBundle 中,如下所示:

runApp(DefaultAssetBundle(
bundle: TestAssetBundle(),
child: App(),
));

TestAssetBundle就像这样:

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);
}

app.dart 中,您必须引用正确的文件:

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();
}

完整的解释可以在这里找到:https://medium.com/@sardox.vl/flutter-test-and-randomly-missing-assets-in-goldens-ea959cdd336a

关于flutter - flutter_driver 测试期间图像不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57712781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com