Skip to content

Commit 7368361

Browse files
authored
[material_ui] Remove unconditional dart:io import from about.dart (flutter#12774)
`about.dart` imported `dart:io` unconditionally, only to read `Platform.resolvedExecutable` as the fallback application name when no `Title` ancestor is found. Because `about.dart` is reachable from the `material_ui` barrel, pana 0.23.18's static platform analysis marks the whole package as not supporting the web, which drops the `platform:web` and `is:wasm-ready` tags on pub.dev. It also means that fallback path throws `UnsupportedError` when it is actually reached on the web. This PR moves the executable-name lookup behind a conditional import (`_about_io.dart` / `_about_web.dart`), following the same pattern `package:flutter`'s foundation library uses for `_platform_io.dart` / `_platform_web.dart`. On the web the fallback name is the empty string, matching the existing empty-string default for the application version. The `[Platform.resolvedExecutable]` doc references are kept resolvable with a `@docImport`. Verified locally with pana 0.23.x on this branch: `Supports 6 of 6 possible platforms`, and the `platform:web` / `is:wasm-ready` tags are back. Fixes flutter/flutter#191887 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent b0ae3b2 commit 7368361

5 files changed

Lines changed: 78 additions & 5 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: 13 additions & 5 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 impl;
1921
import 'app_bar.dart';
2022
import 'back_button.dart';
2123
import 'card.dart';
@@ -101,7 +103,9 @@ class AboutListTile extends StatelessWidget {
101103
/// [child]) and as the caption of the [AboutDialog] that is shown.
102104
///
103105
/// Defaults to the value of [Title.title], if a [Title] widget can be found.
104-
/// Otherwise, defaults to [Platform.resolvedExecutable].
106+
/// Otherwise, defaults to the file name of [Platform.resolvedExecutable] on
107+
/// native platforms, or to the empty string on the web, where there is no
108+
/// executable.
105109
final String? applicationName;
106110

107111
/// The version of this build of the application.
@@ -382,7 +386,9 @@ class AboutDialog extends StatelessWidget {
382386
/// The name of the application.
383387
///
384388
/// Defaults to the value of [Title.title], if a [Title] widget can be found.
385-
/// Otherwise, defaults to [Platform.resolvedExecutable].
389+
/// Otherwise, defaults to the file name of [Platform.resolvedExecutable] on
390+
/// native platforms, or to the empty string on the web, where there is no
391+
/// executable.
386392
final String? applicationName;
387393

388394
/// The version of this build of the application.
@@ -631,7 +637,9 @@ class LicensePage extends StatefulWidget {
631637
/// The name of the application.
632638
///
633639
/// Defaults to the value of [Title.title], if a [Title] widget can be found.
634-
/// Otherwise, defaults to [Platform.resolvedExecutable].
640+
/// Otherwise, defaults to the file name of [Platform.resolvedExecutable] on
641+
/// native platforms, or to the empty string on the web, where there is no
642+
/// executable.
635643
final String? applicationName;
636644

637645
/// The version of this build of the application.
@@ -1200,7 +1208,7 @@ String _defaultApplicationName(BuildContext context) {
12001208
// can provide an explicit applicationName to the widgets defined in this
12011209
// file, instead of relying on the default.
12021210
final Title? ancestorTitle = context.findAncestorWidgetOfExactType<Title>();
1203-
return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last;
1211+
return ancestorTitle?.title ?? impl.executableName;
12041212
}
12051213

12061214
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: 43 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,48 @@ 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+
tags: 'reduced-web-test-set',
60+
);
61+
1962
testWidgets('Material3 has sentence case labels', (WidgetTester tester) async {
2063
await tester.pumpWidget(
2164
MaterialApp(

0 commit comments

Comments
 (0)