Skip to content

Commit 1bb9871

Browse files
committed
[material_ui] Remove unconditional dart:io import from about.dart
about.dart imported dart:io only to read Platform.resolvedExecutable as the fallback application name. Because about.dart is reachable from the package barrel, pana marks material_ui as not supporting the web and drops the platform:web and is:wasm-ready tags. Move the lookup behind a conditional import so the web build never references dart:io. Fixes flutter/flutter#191887
1 parent a3ffe32 commit 1bb9871

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io' show Platform;
6+
7+
/// The file name of the currently running executable.
8+
///
9+
/// Used as the fallback application name by the about dialog widgets when
10+
/// no `Title` ancestor is available.
11+
String get executableName => Platform.resolvedExecutable.split(Platform.pathSeparator).last;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// The file name of the currently running executable.
6+
///
7+
/// There is no executable on the web, so this is always the empty string.
8+
String get executableName => '';

‎packages/material_ui/lib/src/about.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
/// @docImport 'dart:io';
6+
///
57
/// @docImport 'package:cupertino_ui/cupertino_ui.dart';
68
///
79
/// @docImport 'drawer.dart';
810
/// @docImport 'list_tile_theme.dart';
911
library;
1012

1113
import 'dart:developer' show Flow, Timeline;
12-
import 'dart:io' show Platform;
1314

1415
import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoDialogAction;
1516
import 'package:flutter/foundation.dart';
1617
import 'package:flutter/scheduler.dart';
1718
import 'package:flutter/widgets.dart' hide Flow;
1819

20+
import '_about_io.dart' if (dart.library.js_interop) '_about_web.dart' as about;
1921
import 'app_bar.dart';
2022
import 'back_button.dart';
2123
import 'card.dart';
@@ -1201,7 +1203,7 @@ String _defaultApplicationName(BuildContext context) {
12011203
// can provide an explicit applicationName to the widgets defined in this
12021204
// file, instead of relying on the default.
12031205
final Title? ancestorTitle = context.findAncestorWidgetOfExactType<Title>();
1204-
return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last;
1206+
return ancestorTitle?.title ?? about.executableName;
12051207
}
12061208

12071209
String _defaultApplicationVersion(BuildContext context) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Removes the unconditional `dart:io` import from `AboutDialog`, so that `material_ui` is correctly detected as supporting the web platform and `showAboutDialog` no longer throws on the web when no application name is available.
3+
version: patch

‎packages/material_ui/test/about_test.dart‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io' show Platform;
67
import 'dart:ui';
78

89
import 'package:cupertino_ui/cupertino_ui.dart';
@@ -16,6 +17,47 @@ void main() {
1617
LicenseRegistry.reset();
1718
});
1819

20+
Widget buildWithoutTitle(Widget child) {
21+
return MediaQuery(
22+
data: const MediaQueryData(),
23+
child: Localizations(
24+
locale: const Locale('en', 'US'),
25+
delegates: const <LocalizationsDelegate<dynamic>>[
26+
DefaultMaterialLocalizations.delegate,
27+
DefaultWidgetsLocalizations.delegate,
28+
],
29+
child: Directionality(
30+
textDirection: TextDirection.ltr,
31+
child: Theme(data: ThemeData(), child: child),
32+
),
33+
),
34+
);
35+
}
36+
37+
testWidgets(
38+
'AboutDialog defaults the application name to the executable name without a Title ancestor',
39+
(WidgetTester tester) async {
40+
// Regression test for https://github.com/flutter/flutter/issues/191887.
41+
await tester.pumpWidget(buildWithoutTitle(const AboutDialog()));
42+
43+
final String expectedName = Platform.resolvedExecutable.split(Platform.pathSeparator).last;
44+
expect(find.text(expectedName), findsOneWidget);
45+
},
46+
skip: kIsWeb, // [intended] There is no executable name on the web.
47+
);
48+
49+
testWidgets(
50+
'AboutDialog does not throw on the web without a Title ancestor',
51+
(WidgetTester tester) async {
52+
// Regression test for https://github.com/flutter/flutter/issues/191887.
53+
await tester.pumpWidget(buildWithoutTitle(const AboutDialog()));
54+
55+
expect(tester.takeException(), isNull);
56+
expect(find.byType(AboutDialog), findsOneWidget);
57+
},
58+
skip: !kIsWeb, // [intended] Exercises the web-specific fallback.
59+
);
60+
1961
testWidgets('Material3 has sentence case labels', (WidgetTester tester) async {
2062
await tester.pumpWidget(
2163
MaterialApp(

0 commit comments

Comments
 (0)