[ Widget Previews ] Default to using Flutter Web for the widget preview environment (#166091)

Desktop support is now behind `--desktop` as an escape hatch for now,
but will eventually be removed.
This commit is contained in:
Ben Konyi 2025-03-28 13:12:09 -04:00 committed by GitHub
parent d30c767656
commit 943dd30bfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 16 deletions

View File

@ -129,8 +129,8 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
hide: !verboseHelp,
)
..addFlag(
kUseFlutterWeb,
help: 'Launches the widget preview environment using Flutter Web.',
kUseFlutterDesktop,
help: '(deprecated) Launches the widget preview environment using Flutter Desktop.',
hide: !verboseHelp,
)
..addFlag(
@ -142,7 +142,7 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
static const String kWidgetPreviewScaffoldName = 'widget_preview_scaffold';
static const String kLaunchPreviewer = 'launch-previewer';
static const String kUseFlutterWeb = 'web';
static const String kUseFlutterDesktop = 'desktop';
static const String kHeadlessWeb = 'headless-web';
@override
@ -159,7 +159,7 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
final bool verboseHelp;
bool get isWeb => boolArg(kUseFlutterWeb);
bool get isWeb => !boolArg(kUseFlutterDesktop);
@override
final FileSystem fs;
@ -428,6 +428,9 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
const String? kEmptyRoute = null;
const bool kEnableHotReload = true;
// WARNING: this log message is used by test/integration.shard/widget_preview_test.dart
logger.printStatus('Launching the Widget Preview Scaffold...');
app = await Daemon.createMachineDaemon().appDomain.startApp(
device,
widgetPreviewScaffoldProject.directory.path,
@ -446,7 +449,7 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
widgetPreviewScaffoldProject.packageConfig.uri,
),
),
webEnableExposeUrl: false, // TODO(bkonyi): verify
webEnableExposeUrl: false,
webRunHeadless: boolArg(kHeadlessWeb),
),
kEnableHotReload, // hot mode
@ -457,11 +460,14 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
} on Exception catch (error) {
throwToolExit(error.toString());
}
// Immediately perform a hot restart to ensure new previews are loaded into the prebuilt
// application.
// WARNING: this log message is used by test/integration.shard/widget_preview_test.dart
logger.printStatus('Loading previews into the Widget Preview Scaffold...');
await app.restart(fullRestart: true);
if (!isWeb) {
// Immediately perform a hot restart to ensure new previews are loaded into the prebuilt
// application.
// WARNING: this log message is used by test/integration.shard/widget_preview_test.dart
logger.printStatus('Loading previews into the Widget Preview Scaffold...');
await app.restart(fullRestart: true);
}
// WARNING: this log message is used by test/integration.shard/widget_preview_test.dart
logger.printStatus('Done loading previews.');
return app;

View File

@ -18,18 +18,25 @@ const List<String> firstLaunchMessages = <String>[
'Creating widget preview scaffolding at:',
'Performing initial build of the Widget Preview Scaffold...',
'Widget Preview Scaffold initial build complete.',
'Launching the Widget Preview Scaffold...',
'Loading previews into the Widget Preview Scaffold...',
'Done loading previews.',
];
const List<String> subsequentLaunchMessages = <String>[
'Launching the Widget Preview Scaffold...',
'Loading previews into the Widget Preview Scaffold...',
'Done loading previews.',
];
const List<String> firstLaunchMessagesWeb = <String>[
'Creating widget preview scaffolding at:',
'Loading previews into the Widget Preview Scaffold...',
'Launching the Widget Preview Scaffold...',
'Done loading previews.',
];
const List<String> subsequentLaunchMessagesWeb = <String>[
'Launching the Widget Preview Scaffold...',
'Done loading previews.',
];
@ -61,10 +68,10 @@ void main() {
'widget-preview',
'start',
'--verbose',
if (useWeb) ...<String>[
'--${WidgetPreviewStartCommand.kUseFlutterWeb}',
'--${WidgetPreviewStartCommand.kHeadlessWeb}',
],
if (useWeb)
'--${WidgetPreviewStartCommand.kHeadlessWeb}'
else
'--${WidgetPreviewStartCommand.kUseFlutterDesktop}',
], workingDirectory: tempDir.path);
final Completer<void> completer = Completer<void>();
@ -123,7 +130,7 @@ void main() {
await runWidgetPreview(expectedMessages: firstLaunchMessagesWeb, useWeb: true);
// We shouldn't regenerate the scaffold after the initial run.
await runWidgetPreview(expectedMessages: subsequentLaunchMessages, useWeb: true);
await runWidgetPreview(expectedMessages: subsequentLaunchMessagesWeb, useWeb: true);
});
});
}