File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
test/commands.shard/permeable/widget_preview Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import '../bundle.dart' as bundle;
2424import '../cache.dart' ;
2525import '../convert.dart' ;
2626import '../device.dart' ;
27+ import '../features.dart' ;
2728import '../globals.dart' as globals;
2829import '../isolated/resident_web_runner.dart' ;
2930import '../project.dart' ;
@@ -389,6 +390,14 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
389390
390391 Future <int > runPreviewEnvironment ({required FlutterProject widgetPreviewScaffoldProject}) async {
391392 try {
393+ // In the rare case that Flutter Web is disabled, the device manager will not return any web
394+ // devices which will cause us to crash.
395+ if (! featureFlags.isWebEnabled) {
396+ throwToolExit (
397+ 'Widget Previews requires Flutter Web to be enabled. Please run '
398+ "'flutter config --enable-web' to enable Flutter Web and try again." ,
399+ );
400+ }
392401 final Device device;
393402 if (boolArg (kWebServer)) {
394403 final List <Device > devices;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import 'package:flutter_tools/src/cache.dart';
1919import 'package:flutter_tools/src/commands/widget_preview.dart' ;
2020import 'package:flutter_tools/src/dart/pub.dart' ;
2121import 'package:flutter_tools/src/device.dart' ;
22+ import 'package:flutter_tools/src/features.dart' ;
2223import 'package:flutter_tools/src/globals.dart' as globals;
2324import 'package:flutter_tools/src/project.dart' ;
2425import 'package:flutter_tools/src/web/web_device.dart' ;
@@ -265,6 +266,37 @@ void main() {
265266 }
266267 expectNoPreviewLaunchTimingEvents ();
267268 });
269+
270+ testUsingContext (
271+ 'Flutter Web is disabled' ,
272+ () async {
273+ try {
274+ await startWidgetPreview (rootProject: await createRootProject ());
275+ fail ('Successfully executed with Flutter Web disabled.' );
276+ } on ToolExit catch (e) {
277+ expect (
278+ e.message,
279+ 'Error: Widget Previews requires Flutter Web to be enabled. Please run '
280+ "'flutter config --enable-web' to enable Flutter Web and try again." ,
281+ );
282+ }
283+ expectNoPreviewLaunchTimingEvents ();
284+ },
285+ overrides: {
286+ FeatureFlags : () => TestFeatureFlags (
287+ // ignore: avoid_redundant_argument_values, readability
288+ isWebEnabled: false ,
289+ ),
290+ Pub : () => Pub .test (
291+ fileSystem: fs,
292+ logger: logger,
293+ processManager: loggingProcessManager,
294+ botDetector: botDetector,
295+ platform: platform,
296+ stdio: mockStdio,
297+ ),
298+ },
299+ );
268300 });
269301
270302 testUsingContext (
You can’t perform that action at this time.
0 commit comments