Add macOS to TargetPlatform (#43457)
This PR adds TargetPlatform.macOS to the TargetPlatform enum. This allows us to begin implementation of some adaptive UI based on which target platform is desired.
I haven't updated the tests here, that will come in a follow-up PR.
diff --git a/dev/manual_tests/lib/actions.dart b/dev/manual_tests/lib/actions.dart
index 1429009..99ed1b8 100644
--- a/dev/manual_tests/lib/actions.dart
+++ b/dev/manual_tests/lib/actions.dart
@@ -8,13 +8,17 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(const MaterialApp(
title: 'Actions Demo',
home: FocusDemo(),
diff --git a/dev/manual_tests/lib/animated_icons.dart b/dev/manual_tests/lib/animated_icons.dart
index 4394282..1b4781e 100644
--- a/dev/manual_tests/lib/animated_icons.dart
+++ b/dev/manual_tests/lib/animated_icons.dart
@@ -108,11 +108,16 @@
final String description;
}
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(AnimatedIconsTestApp());
}
diff --git a/dev/manual_tests/lib/drag_and_drop.dart b/dev/manual_tests/lib/drag_and_drop.dart
index 2d5713e..777d561 100644
--- a/dev/manual_tests/lib/drag_and_drop.dart
+++ b/dev/manual_tests/lib/drag_and_drop.dart
@@ -296,13 +296,17 @@
}
}
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(MaterialApp(
title: 'Drag and Drop Flutter Demo',
home: DragAndDropApp(),
diff --git a/dev/manual_tests/lib/focus.dart b/dev/manual_tests/lib/focus.dart
index 36e5255..fa8816e 100644
--- a/dev/manual_tests/lib/focus.dart
+++ b/dev/manual_tests/lib/focus.dart
@@ -8,13 +8,17 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(const MaterialApp(
title: 'Focus Demo',
home: FocusDemo(),
diff --git a/dev/manual_tests/lib/hover.dart b/dev/manual_tests/lib/hover.dart
index bf82fa2..b23e950 100644
--- a/dev/manual_tests/lib/hover.dart
+++ b/dev/manual_tests/lib/hover.dart
@@ -8,13 +8,17 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(const MaterialApp(
title: 'Hover Demo',
home: HoverDemo(),
diff --git a/dev/manual_tests/lib/main.dart b/dev/manual_tests/lib/main.dart
index 3688175..de585eb 100644
--- a/dev/manual_tests/lib/main.dart
+++ b/dev/manual_tests/lib/main.dart
@@ -7,13 +7,17 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(const Directionality(
textDirection: TextDirection.ltr,
child: Center(
diff --git a/dev/manual_tests/lib/material_arc.dart b/dev/manual_tests/lib/material_arc.dart
index ee32036..fc21d2d 100644
--- a/dev/manual_tests/lib/material_arc.dart
+++ b/dev/manual_tests/lib/material_arc.dart
@@ -475,13 +475,17 @@
}
}
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(const MaterialApp(
home: AnimationDemo(),
));
diff --git a/dev/manual_tests/lib/overlay_geometry.dart b/dev/manual_tests/lib/overlay_geometry.dart
index 84caa7d..d05ba18 100644
--- a/dev/manual_tests/lib/overlay_geometry.dart
+++ b/dev/manual_tests/lib/overlay_geometry.dart
@@ -206,13 +206,17 @@
}
}
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
diff --git a/dev/manual_tests/lib/page_view.dart b/dev/manual_tests/lib/page_view.dart
index 4a9d16c..7f89680 100644
--- a/dev/manual_tests/lib/page_view.dart
+++ b/dev/manual_tests/lib/page_view.dart
@@ -141,12 +141,17 @@
}
}
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(MaterialApp(
title: 'PageView',
theme: ThemeData(
diff --git a/dev/manual_tests/lib/raw_keyboard.dart b/dev/manual_tests/lib/raw_keyboard.dart
index bc774e7..7b43869 100644
--- a/dev/manual_tests/lib/raw_keyboard.dart
+++ b/dev/manual_tests/lib/raw_keyboard.dart
@@ -8,13 +8,17 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(MaterialApp(
title: 'Hardware Key Demo',
home: Scaffold(
diff --git a/dev/manual_tests/lib/text.dart b/dev/manual_tests/lib/text.dart
index 7e6e599..556488d 100644
--- a/dev/manual_tests/lib/text.dart
+++ b/dev/manual_tests/lib/text.dart
@@ -12,13 +12,17 @@
int seed = 0;
-void main() {
- if (!kIsWeb && Platform.isMacOS) {
- // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
- // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
+// Sets a platform override for desktop to avoid exceptions. See
+// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+void _enablePlatformOverrideForDesktop() {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
+}
+void main() {
+ _enablePlatformOverrideForDesktop();
runApp(MaterialApp(
title: 'Text tester',
home: const Home(),
diff --git a/examples/flutter_gallery/lib/demo/material/drawer_demo.dart b/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
index 417b8c9..08f69d2 100644
--- a/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
@@ -64,6 +64,7 @@
case TargetPlatform.fuchsia:
return Icons.arrow_back;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return Icons.arrow_back_ios;
}
assert(false);
diff --git a/examples/flutter_gallery/lib/gallery/options.dart b/examples/flutter_gallery/lib/gallery/options.dart
index 865e19f..e1687be 100644
--- a/examples/flutter_gallery/lib/gallery/options.dart
+++ b/examples/flutter_gallery/lib/gallery/options.dart
@@ -360,6 +360,8 @@
return 'Fuchsia';
case TargetPlatform.iOS:
return 'Cupertino';
+ case TargetPlatform.macOS:
+ return 'Material Desktop (macOS)';
}
assert(false);
return null;
diff --git a/examples/flutter_gallery/lib/main.dart b/examples/flutter_gallery/lib/main.dart
index 33f4e1c..cb50e22 100644
--- a/examples/flutter_gallery/lib/main.dart
+++ b/examples/flutter_gallery/lib/main.dart
@@ -14,8 +14,12 @@
// Sets a platform override for desktop to avoid exceptions. See
// https://flutter.dev/desktop#target-platform-override for more info.
+// TODO(gspencergoog): Remove once TargetPlatform includes all desktop platforms.
+// This is only included in the Gallery because Flutter's testing infrastructure
+// uses the Gallery for various tests, and this allows us to test on desktop
+// platforms that aren't yet supported in TargetPlatform.
void _enablePlatformOverrideForDesktop() {
- if (!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
}
diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart
index 0186f69..6aabf02 100644
--- a/packages/flutter/lib/src/cupertino/picker.dart
+++ b/packages/flutter/lib/src/cupertino/picker.dart
@@ -230,6 +230,7 @@
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
+ case TargetPlatform.macOS:
hasSuitableHapticHardware = false;
break;
}
diff --git a/packages/flutter/lib/src/cupertino/switch.dart b/packages/flutter/lib/src/cupertino/switch.dart
index 61d616c..b5cb9e5 100644
--- a/packages/flutter/lib/src/cupertino/switch.dart
+++ b/packages/flutter/lib/src/cupertino/switch.dart
@@ -445,8 +445,9 @@
case TargetPlatform.iOS:
HapticFeedback.lightImpact();
break;
- case TargetPlatform.fuchsia:
case TargetPlatform.android:
+ case TargetPlatform.fuchsia:
+ case TargetPlatform.macOS:
break;
}
}
diff --git a/packages/flutter/lib/src/foundation/_platform_io.dart b/packages/flutter/lib/src/foundation/_platform_io.dart
index 7726331..2b52608 100644
--- a/packages/flutter/lib/src/foundation/_platform_io.dart
+++ b/packages/flutter/lib/src/foundation/_platform_io.dart
@@ -11,6 +11,8 @@
platform.TargetPlatform result;
if (Platform.isIOS) {
result = platform.TargetPlatform.iOS;
+ } else if (Platform.isMacOS) {
+ result = platform.TargetPlatform.macOS;
} else if (Platform.isAndroid) {
result = platform.TargetPlatform.android;
} else if (Platform.isFuchsia) {
diff --git a/packages/flutter/lib/src/foundation/binding.dart b/packages/flutter/lib/src/foundation/binding.dart
index dd85335..2bf607e 100644
--- a/packages/flutter/lib/src/foundation/binding.dart
+++ b/packages/flutter/lib/src/foundation/binding.dart
@@ -163,6 +163,9 @@
case 'iOS':
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
break;
+ case 'macOS':
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ break;
case 'fuchsia':
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
break;
diff --git a/packages/flutter/lib/src/foundation/platform.dart b/packages/flutter/lib/src/foundation/platform.dart
index 908bf3e..e239036 100644
--- a/packages/flutter/lib/src/foundation/platform.dart
+++ b/packages/flutter/lib/src/foundation/platform.dart
@@ -47,6 +47,9 @@
/// iOS: <http://www.apple.com/ios/>
iOS,
+
+ /// macOS: <http://www.apple.com/macos>
+ macOS,
}
/// Override the [defaultTargetPlatform].
diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart
index e4e6400..7bf6ba3 100644
--- a/packages/flutter/lib/src/material/app.dart
+++ b/packages/flutter/lib/src/material/app.dart
@@ -481,6 +481,7 @@
// the base class as well.
switch (getPlatform(context)) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return child;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart
index 0fee5ed..ed0f17c 100644
--- a/packages/flutter/lib/src/material/app_bar.dart
+++ b/packages/flutter/lib/src/material/app_bar.dart
@@ -393,6 +393,7 @@
case TargetPlatform.fuchsia:
return false;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return actions == null || actions.length < 2;
}
return null;
@@ -483,6 +484,7 @@
namesRoute = true;
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
title = DefaultTextStyle(
diff --git a/packages/flutter/lib/src/material/back_button.dart b/packages/flutter/lib/src/material/back_button.dart
index 956220a..17a699c 100644
--- a/packages/flutter/lib/src/material/back_button.dart
+++ b/packages/flutter/lib/src/material/back_button.dart
@@ -34,6 +34,7 @@
case TargetPlatform.fuchsia:
return Icons.arrow_back;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return Icons.arrow_back_ios;
}
assert(false);
diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart
index 6886967..c50110e 100644
--- a/packages/flutter/lib/src/material/bottom_sheet.dart
+++ b/packages/flutter/lib/src/material/bottom_sheet.dart
@@ -283,6 +283,7 @@
String _getRouteLabel(MaterialLocalizations localizations) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return '';
case TargetPlatform.android:
case TargetPlatform.fuchsia:
diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart
index 32e45e6..634bab9 100644
--- a/packages/flutter/lib/src/material/date_picker.dart
+++ b/packages/flutter/lib/src/material/date_picker.dart
@@ -911,6 +911,7 @@
HapticFeedback.vibrate();
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
}
diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart
index f6551f0..c42e6f4 100644
--- a/packages/flutter/lib/src/material/dialog.dart
+++ b/packages/flutter/lib/src/material/dialog.dart
@@ -314,6 +314,7 @@
if (title == null) {
switch (theme.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
label = semanticLabel;
break;
case TargetPlatform.android:
@@ -591,6 +592,7 @@
String label = semanticLabel;
if (title == null) {
switch (theme.platform) {
+ case TargetPlatform.macOS:
case TargetPlatform.iOS:
label = semanticLabel;
break;
diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart
index a1c4b0d..c5c603b 100644
--- a/packages/flutter/lib/src/material/drawer.dart
+++ b/packages/flutter/lib/src/material/drawer.dart
@@ -177,6 +177,7 @@
String label = semanticLabel;
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
label = semanticLabel;
break;
case TargetPlatform.android:
@@ -523,6 +524,7 @@
platformHasBackButton = true;
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
case TargetPlatform.fuchsia:
platformHasBackButton = false;
break;
diff --git a/packages/flutter/lib/src/material/flexible_space_bar.dart b/packages/flutter/lib/src/material/flexible_space_bar.dart
index 910e495..fbc8adf 100644
--- a/packages/flutter/lib/src/material/flexible_space_bar.dart
+++ b/packages/flutter/lib/src/material/flexible_space_bar.dart
@@ -166,7 +166,7 @@
/// Whether the title should be centered.
///
/// By default this property is true if the current target platform
- /// is [TargetPlatform.iOS], false otherwise.
+ /// is [TargetPlatform.iOS] or [TargetPlatform.macOS], false otherwise.
final bool centerTitle;
/// Collapse effect while scrolling.
@@ -239,6 +239,7 @@
case TargetPlatform.fuchsia:
return false;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return true;
}
return null;
@@ -341,6 +342,7 @@
Widget title;
switch (theme.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
title = widget.title;
break;
case TargetPlatform.fuchsia:
@@ -349,6 +351,7 @@
namesRoute: true,
child: widget.title,
);
+ break;
}
// StretchMode.fadeTitle
diff --git a/packages/flutter/lib/src/material/page_transitions_theme.dart b/packages/flutter/lib/src/material/page_transitions_theme.dart
index 9caad1a..8aa7f64 100644
--- a/packages/flutter/lib/src/material/page_transitions_theme.dart
+++ b/packages/flutter/lib/src/material/page_transitions_theme.dart
@@ -486,14 +486,15 @@
class PageTransitionsTheme extends Diagnosticable {
/// Construct a PageTransitionsTheme.
///
- /// By default the list of builders is: [FadeUpwardsPageTransitionsBuilder],
- /// [CupertinoPageTransitionsBuilder] for [TargetPlatform.android]
- /// and [TargetPlatform.iOS] respectively.
+ /// By default the list of builders is: [FadeUpwardsPageTransitionsBuilder]
+ /// for [TargetPlatform.android], and [CupertinoPageTransitionsBuilder] for
+ /// [TargetPlatform.iOS] and [TargetPlatform.macOS].
const PageTransitionsTheme({ Map<TargetPlatform, PageTransitionsBuilder> builders }) : _builders = builders;
static const Map<TargetPlatform, PageTransitionsBuilder> _defaultBuilders = <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
+ TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
};
/// The [PageTransitionsBuilder]s supported by this theme.
diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart
index 79107c4..750e7c2 100644
--- a/packages/flutter/lib/src/material/popup_menu.dart
+++ b/packages/flutter/lib/src/material/popup_menu.dart
@@ -830,6 +830,7 @@
String label = semanticLabel;
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
label = semanticLabel;
break;
case TargetPlatform.android:
@@ -1083,6 +1084,7 @@
case TargetPlatform.fuchsia:
return const Icon(Icons.more_vert);
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return const Icon(Icons.more_horiz);
}
return null;
diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart
index 91af53b..0aeb6e4 100644
--- a/packages/flutter/lib/src/material/scaffold.dart
+++ b/packages/flutter/lib/src/material/scaffold.dart
@@ -2299,6 +2299,7 @@
switch (themeData.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
_addIfNonNull(
children,
GestureDetector(
diff --git a/packages/flutter/lib/src/material/scrollbar.dart b/packages/flutter/lib/src/material/scrollbar.dart
index 2314242..a47c94b 100644
--- a/packages/flutter/lib/src/material/scrollbar.dart
+++ b/packages/flutter/lib/src/material/scrollbar.dart
@@ -86,6 +86,7 @@
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
// On iOS, stop all local animations. CupertinoScrollbar has its own
// animations.
_fadeoutTimer?.cancel();
diff --git a/packages/flutter/lib/src/material/search.dart b/packages/flutter/lib/src/material/search.dart
index 1fa2bfc..b84a708 100644
--- a/packages/flutter/lib/src/material/search.dart
+++ b/packages/flutter/lib/src/material/search.dart
@@ -487,6 +487,7 @@
String routeName;
switch (theme.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
routeName = '';
break;
case TargetPlatform.android:
diff --git a/packages/flutter/lib/src/material/selectable_text.dart b/packages/flutter/lib/src/material/selectable_text.dart
index 169b3d5..e70f8cf 100644
--- a/packages/flutter/lib/src/material/selectable_text.dart
+++ b/packages/flutter/lib/src/material/selectable_text.dart
@@ -70,6 +70,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress,
@@ -93,6 +94,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectWordEdge(cause: SelectionChangedCause.tap);
break;
case TargetPlatform.android:
@@ -110,6 +112,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress,
@@ -462,6 +465,7 @@
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
if (cause == SelectionChangedCause.longPress) {
_editableText?.bringIntoView(selection.base);
}
@@ -529,6 +533,7 @@
switch (themeData.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
forcePressEnabled = true;
textSelectionControls = cupertinoTextSelectionControls;
paintCursorAboveText = true;
diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart
index 025b688..955ed63 100644
--- a/packages/flutter/lib/src/material/slider.dart
+++ b/packages/flutter/lib/src/material/slider.dart
@@ -502,6 +502,7 @@
case TargetPlatform.fuchsia:
return _buildMaterialSlider(context);
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return _buildCupertinoSlider(context);
}
}
@@ -888,14 +889,15 @@
double get _adjustmentUnit {
switch (_platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
// Matches iOS implementation of material slider.
return 0.1;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
- default:
// Matches Android implementation of material slider.
return 0.05;
}
+ return 0.0;
}
void _updateLabelPainter() {
diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart
index d4168d4..466f835 100644
--- a/packages/flutter/lib/src/material/switch.dart
+++ b/packages/flutter/lib/src/material/switch.dart
@@ -354,6 +354,7 @@
case TargetPlatform.fuchsia:
return buildMaterialSwitch(context);
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return buildCupertinoSwitch(context);
}
}
diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart
index efc1cef..c9047c9 100644
--- a/packages/flutter/lib/src/material/text_field.dart
+++ b/packages/flutter/lib/src/material/text_field.dart
@@ -59,6 +59,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress,
@@ -82,6 +83,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectWordEdge(cause: SelectionChangedCause.tap);
break;
case TargetPlatform.android:
@@ -100,6 +102,7 @@
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress,
@@ -868,6 +871,7 @@
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
if (cause == SelectionChangedCause.longPress) {
_editableText?.bringIntoView(selection.base);
}
@@ -923,6 +927,7 @@
switch (themeData.platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
forcePressEnabled = true;
textSelectionControls = cupertinoTextSelectionControls;
paintCursorAboveText = true;
diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart
index 0c6ccb4..11ddaed 100644
--- a/packages/flutter/lib/src/material/theme_data.dart
+++ b/packages/flutter/lib/src/material/theme_data.dart
@@ -873,9 +873,10 @@
/// In a test environment, the platform returned is [TargetPlatform.android]
/// regardless of the host platform. (Android was chosen because the tests
/// were originally written assuming Android-like behavior, and we added
- /// platform adaptations for iOS later). Tests can check iOS behavior by
- /// setting the [platform] of the [Theme] explicitly to [TargetPlatform.iOS],
- /// or by setting [debugDefaultTargetPlatformOverride].
+ /// platform adaptations for other platforms later). Tests can check behavior
+ /// for other platforms by setting the [platform] of the [Theme] explicitly to
+ /// another [TargetPlatform] value, or by setting
+ /// [debugDefaultTargetPlatformOverride].
final TargetPlatform platform;
/// Configures the hit test size of certain Material widgets.
diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart
index 6ee0ef9..73aa100 100644
--- a/packages/flutter/lib/src/material/time_picker.dart
+++ b/packages/flutter/lib/src/material/time_picker.dart
@@ -209,6 +209,7 @@
_announceToAccessibility(context, MaterialLocalizations.of(context).anteMeridiemAbbreviation);
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
_togglePeriod();
@@ -224,6 +225,7 @@
_announceToAccessibility(context, MaterialLocalizations.of(context).postMeridiemAbbreviation);
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
_togglePeriod();
@@ -1525,6 +1527,7 @@
});
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
}
diff --git a/packages/flutter/lib/src/material/typography.dart b/packages/flutter/lib/src/material/typography.dart
index 47c28b2..13c0436 100644
--- a/packages/flutter/lib/src/material/typography.dart
+++ b/packages/flutter/lib/src/material/typography.dart
@@ -88,10 +88,11 @@
class Typography extends Diagnosticable {
/// Creates a typography instance.
///
- /// If [platform] is [TargetPlatform.iOS], the default values for [black] and
- /// [white] are [blackCupertino] and [whiteCupertino] respectively. Otherwise
- /// they are [blackMountainView] and [whiteMoutainView]. If [platform] is
- /// null then both [black] and [white] must be specified.
+ /// If [platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS], the
+ /// default values for [black] and [white] are [blackCupertino] and
+ /// [whiteCupertino] respectively. Otherwise they are [blackMountainView] and
+ /// [whiteMoutainView]. If [platform] is null then both [black] and [white]
+ /// must be specified.
///
/// The default values for [englishLike], [dense], and [tall] are
/// [englishLike2014], [dense2014], and [tall2014].
@@ -106,6 +107,7 @@
assert(platform != null || (black != null && white != null));
switch (platform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
black ??= blackCupertino;
white ??= whiteCupertino;
break;
diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart
index ad76598..d3afb1c 100644
--- a/packages/flutter/lib/src/rendering/editable.dart
+++ b/packages/flutter/lib/src/rendering/editable.dart
@@ -1719,6 +1719,7 @@
assert(defaultTargetPlatform != null);
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return Rect.fromLTWH(0.0, 0.0, cursorWidth, preferredLineHeight + 2);
case TargetPlatform.android:
case TargetPlatform.fuchsia:
@@ -1777,6 +1778,7 @@
if (caretHeight != null) {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
final double heightDiff = caretHeight - caretRect.height;
// Center the caret vertically along the text.
caretRect = Rect.fromLTWH(
diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart
index 2f301fa..686dff2 100644
--- a/packages/flutter/lib/src/rendering/view.dart
+++ b/packages/flutter/lib/src/rendering/view.dart
@@ -253,8 +253,9 @@
case TargetPlatform.android:
lowerOverlayStyle = layer.find<SystemUiOverlayStyle>(bottom);
break;
- case TargetPlatform.iOS:
case TargetPlatform.fuchsia:
+ case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
break;
}
// If there are no overlay styles in the UI don't bother updating.
diff --git a/packages/flutter/lib/src/widgets/modal_barrier.dart b/packages/flutter/lib/src/widgets/modal_barrier.dart
index 14de51e..5c0ad1c 100644
--- a/packages/flutter/lib/src/widgets/modal_barrier.dart
+++ b/packages/flutter/lib/src/widgets/modal_barrier.dart
@@ -82,6 +82,7 @@
platformSupportsDismissingBarrier = false;
break;
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
platformSupportsDismissingBarrier = true;
break;
}
diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart
index 63e8ff9..34f1ad3 100644
--- a/packages/flutter/lib/src/widgets/routes.dart
+++ b/packages/flutter/lib/src/widgets/routes.dart
@@ -1217,9 +1217,10 @@
/// True if one or more [WillPopCallback] callbacks exist.
///
- /// This method is used to disable the horizontal swipe pop gesture
- /// supported by [MaterialPageRoute] for [TargetPlatform.iOS].
- /// If a pop might be vetoed, then the back gesture is disabled.
+ /// This method is used to disable the horizontal swipe pop gesture supported
+ /// by [MaterialPageRoute] for [TargetPlatform.iOS] and
+ /// [TargetPlatform.macOS]. If a pop might be vetoed, then the back gesture is
+ /// disabled.
///
/// The [buildTransitions] method will not be called again if this changes,
/// since it can change during the build as descendants of the route add or
diff --git a/packages/flutter/lib/src/widgets/scroll_configuration.dart b/packages/flutter/lib/src/widgets/scroll_configuration.dart
index 4a67ffa..b1c16a2 100644
--- a/packages/flutter/lib/src/widgets/scroll_configuration.dart
+++ b/packages/flutter/lib/src/widgets/scroll_configuration.dart
@@ -35,6 +35,7 @@
// _MaterialScrollBehavior as well.
switch (getPlatform(context)) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return child;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
@@ -54,6 +55,7 @@
ScrollPhysics getScrollPhysics(BuildContext context) {
switch (getPlatform(context)) {
case TargetPlatform.iOS:
+ case TargetPlatform.macOS:
return const BouncingScrollPhysics();
case TargetPlatform.android:
case TargetPlatform.fuchsia:
diff --git a/packages/flutter/test/widgets/sliver_fill_remaining_test.dart b/packages/flutter/test/widgets/sliver_fill_remaining_test.dart
index 22b516d..a1a9c60 100644
--- a/packages/flutter/test/widgets/sliver_fill_remaining_test.dart
+++ b/packages/flutter/test/widgets/sliver_fill_remaining_test.dart
@@ -331,6 +331,7 @@
final Finder button = find.byType(RaisedButton);
expect(tester.getBottomLeft(button).dy, equals(550.0));
expect(tester.getCenter(button).dx, equals(400.0));
+ debugDefaultTargetPlatformOverride = null;
// Drag for overscroll
await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0));
diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart
index 4fd4377ae..645c625 100644
--- a/packages/flutter_tools/lib/src/commands/create.dart
+++ b/packages/flutter_tools/lib/src/commands/create.dart
@@ -656,7 +656,8 @@
// removed, and the new schema should always be used.
'useNewPluginSchema': macos,
// If a desktop platform is included, add a workaround for #31366.
- 'includeTargetPlatformWorkaround': macos,
+ // When Linux and Windows are added, we will need this workaround again.
+ 'includeTargetPlatformWorkaround': false,
};
}
diff --git a/packages/flutter_tools/templates/app/lib/main.dart.tmpl b/packages/flutter_tools/templates/app/lib/main.dart.tmpl
index fa01186..40c8db1 100644
--- a/packages/flutter_tools/templates/app/lib/main.dart.tmpl
+++ b/packages/flutter_tools/templates/app/lib/main.dart.tmpl
@@ -18,7 +18,7 @@
// Sets a platform override for desktop to avoid exceptions. See
// https://flutter.dev/desktop#target-platform-override for more info.
void _enablePlatformOverrideForDesktop() {
- if (!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
+ if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
}
}