-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9Found to occur in 2.9found in release: 3.0Found to occur in 3.0Found to occur in 3.0frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to Reproduce
- Create a basic flutter app which wraps
runAppwithrunZonedand provides a custom zone value:
import 'dart:async';
import 'package:flutter/material.dart';
const zoneKey = Object();
void main() {
runZoned(
() => runApp(const MyApp()),
zoneValues: {zoneKey: 'Hello World'},
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final zoneValue = Zone.current[zoneKey];
print('MyApp.build() $zoneValue'); // NULL during integration_test run
return const MaterialApp();
}
}- Write an integration test:
import 'package:flutter_test/flutter_test.dart';
import 'package:example/main.dart' as app;
void main() {
group('App', () {
testWidgets('renders MyApp', (tester) async {
app.main();
await tester.pumpAndSettle();
expect(find.byType(app.MyApp), findsOneWidget);
});
});
}- Run the integration test
flutter test integration_test - Observe that the zone value is null within the
buildmethod ofMyApp
Expected results:
I'd expect the zone value to be available within the build method since runApp was executed within the zone.
Actual results:
The zone value is null within the build method during the integration_test run.
Additional Context
Even when the entire test suite is wrapped in runZoned, the zone values are not available during an integration_test run:
void main() {
runZoned(() {
final zoneValue = Zone.current[app.zoneKey];
print('test.main(), $zoneValue'); // Hello Test
group('App', () {
final zoneValue = Zone.current[app.zoneKey];
print('test.group(), $zoneValue'); // Hello Test
testWidgets('renders MyApp', (tester) async {
final zoneValue = Zone.current[app.zoneKey];
print('test.testWidgets(), $zoneValue'); // null
app.main();
await tester.pumpAndSettle();
expect(find.byType(app.MyApp), findsOneWidget);
});
});
}, zoneValues: {app.zoneKey: 'Hello Test'});
}It looks like testWidgets runs the body inside a new zone and does not fork the parent zone and inherit the zoneValues.
Related Issues
- Flutter framework does not warn when ensureInitialized is called in a different zone than runAppΒ #94123
- runZoned with zoneValues lost after hot reloadΒ #93676
Logs
{"CFBundleName":"zones","DTXcode":"1310","DTSDKName":"iphonesimulator15.0","UILaunchStoryboardName":"LaunchScreen","CFBundleIcons~ipad":{"CFBundlePrimaryIcon":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60","AppIcon76x76","AppIcon83.5x83.
5"],"CFBundleIconName":"AppIcon"}},"DTSDKBuild":"19A339","CFBundleDevelopmentRegion":"en","CFBundleVersion":"1","BuildMachineOSBuild":"21A559","DTPlatformName":"iphonesimulator","CFBundlePackageType":"APPL","UIMainStoryboardFile":"Main","CFBundleSupportedPlatforms":["iPho
neSimulator"],"CFBundleShortVersionString":"1.0.0","CFBundleInfoDictionaryVersion":"6.0","CFBundleExecutable":"Runner","DTCompiler":"com.apple.compilers.llvm.clang.1_0","UISupportedInterfaceOrientations~ipad":["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortra
itUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],"MinimumOSVersion":"9.0","CFBundleIdentifier":"com.example.zones","UIDeviceFamily":[1,2],"DTPlatformVersion":"15.0","CFBundleSignature":"????","CFBundleIcons":{"CFBundlePrimaryIcon
":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60"],"CFBundleIconName":"AppIcon"}},"DTXcodeBuild":"13A1030d","LSRequiresIPhoneOS":true,"UISupportedInterfaceOrientations":["UIInterfaceOrientationPortrait","UIInterfaceOrientationLandscapeLef
t","UIInterfaceOrientationLandscapeRight"],"UIViewControllerBasedStatusBarAppearance":false,"NSBonjourServices":["_dartobservatory._tcp"],"DTPlatformBuild":"19A339","NSLocalNetworkUsageDescription":"Allow Flutter tools on your computer to connect and debug your
application. This prompt will not appear on release builds."}
[ +4 ms] executing: xcrun simctl launch FCB4BE3E-33DA-49FC-A861-F647555D56A9 com.example.zones --enable-dart-profiling --enable-checked-mode --verify-entry-points --observatory-port=0
[ +205 ms] com.example.zones: 51465
[ +1 ms] Waiting for observatory port to be available...
[ +416 ms] Observatory URL on device: http://127.0.0.1:55348/QIoVQ24XVz0=/
[ +9 ms] Caching compiled dill
[ +51 ms] Connecting to service protocol: http://127.0.0.1:55348/QIoVQ24XVz0=/
[ +167 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:55348/QIoVQ24XVz0=/.
[ +95 ms] DDS is listening at http://127.0.0.1:55351/1RcuH9jFcOE=/.
[ +59 ms] Successfully connected to service protocol: http://127.0.0.1:55348/QIoVQ24XVz0=/
[ +26 ms] DevFS: Creating new filesystem on the device (null)
[ +17 ms] DevFS: Created new filesystem on the device (file:///Users/felix/Library/Developer/CoreSimulator/Devices/FCB4BE3E-33DA-49FC-A861-F647555D56A9/data/Containers/Data/Application/42BE9414-534D-477C-ADEB-EDC73F58B7FA/tmp/zonesEyB4Fm/zones/)
[ +2 ms] Updating assets
[ +63 ms] Syncing files to device iPhone 13...
[ +2 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ +3 ms] <- recompile package:zones/main.dart 7fd16ad6-36b9-4ac5-99dd-f42726cef603
[ ] <- 7fd16ad6-36b9-4ac5-99dd-f42726cef603
[ +64 ms] Updating files.
[ ] DevFS: Sync finished
[ ] Syncing files to device iPhone 13... (completed in 71ms)
[ ] Synced 0.0MB.
[ +1 ms] <- accept
[ +6 ms] Connected to _flutterView/0x7fb30a810c20.
[ +3 ms] Flutter run key commands.
[ +1 ms] r Hot reload. π₯π₯π₯
[ ] R Hot restart.
[ ] h List all available interactive commands.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] πͺ Running with sound null safety πͺ
[ ] An Observatory debugger and profiler on iPhone 13 is available at: http://127.0.0.1:55351/1RcuH9jFcOE=/
[ +490 ms] The Flutter DevTools debugger and profiler on iPhone 13 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:55351/1RcuH9jFcOE=/
[+4486 ms] Skipping target: gen_localizations
[ ] Skipping target: gen_dart_plugin_registrant
[ ] Skipping target: _composite
[ ] complete
[ ] Performing hot reload...
[ +11 ms] Scanned through 528 files in 6ms
[ ] Syncing files to device iPhone 13...
[ ] Compiling dart to kernel with 0 updated files
[ ] <- recompile package:zones/main.dart 564d0ee5-dbd9-4020-bfeb-4217c387483f
[ ] <- 564d0ee5-dbd9-4020-bfeb-4217c387483f
[ +6 ms] Updating files.
[ +2 ms] DevFS: Sync finished
[ ] Syncing files to device iPhone 13... (completed in 9ms)
[ ] Synced 0.0MB.
[ +11 ms] Reassembling application
[ +39 ms] Hot reload performed in 67ms.
[ +1 ms] Performing hot reload... (completed in 73ms)
[ ] Reloaded 0 libraries in 78ms.
No issues found! (ran in 1.9s)
[β] Flutter (Channel beta, 2.7.0-3.1.pre, on macOS 12.0.1 21A559 darwin-x64, locale en-US)
β’ Flutter version 2.7.0-3.1.pre at /Users/felix/fvm/versions/beta
β’ Upstream repository [email protected]:flutter/flutter.git
β’ Framework revision fc7015e35a (3 weeks ago), 2021-10-27 15:18:41 -0700
β’ Engine revision a75e3b80f9
β’ Dart version 2.15.0 (build 2.15.0-178.1.beta)
[β] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
β’ Android SDK at /Users/felix/Library/Android/sdk
β’ Platform android-30, build-tools 29.0.2
β’ 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 13.1)
β’ Xcode at /Applications/Xcode.app/Contents/Developer
β’ CocoaPods version 1.11.2
[β] Chrome - develop for the web
β’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[β] Android Studio (version 4.1)
β’ Android Studio at /Applications/Android Studio.app/Contents
β’ 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 1.8.0_242-release-1644-b3-6222593)
[β] IntelliJ IDEA Community Edition (version 2021.2)
β’ IntelliJ at /Applications/IntelliJ IDEA CE.app
β’ 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
[β] VS Code (version 1.60.1)
β’ VS Code at /Applications/Visual Studio Code.app/Contents
β’ Flutter extension version 3.27.0
[β] VS Code (version 1.63.0-insider)
β’ VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
β’ Flutter extension version 3.28.0
[β] Connected device (3 available)
β’ iPhone 13 (mobile) β’ FCB4BE3E-33DA-49FC-A861-F647555D56A9 β’ ios β’ com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
β’ macOS (desktop) β’ macos β’ darwin-x64 β’ macOS 12.0.1 21A559 darwin-x64
β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 95.0.4638.69
β’ No issues found!
marcossevilla, orestesgaolin, scarletteliza, felangel, allisonryan0002 and 24 more
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsfound in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9Found to occur in 2.9found in release: 3.0Found to occur in 3.0Found to occur in 3.0frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team