mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Platform selector in gallery. (#6390)
This commit is contained in:
parent
1f1d72853b
commit
cfddacbb81
@ -43,6 +43,8 @@ class GalleryAppState extends State<GalleryApp> {
|
|||||||
bool _useLightTheme = true;
|
bool _useLightTheme = true;
|
||||||
bool _showPerformanceOverlay = false;
|
bool _showPerformanceOverlay = false;
|
||||||
|
|
||||||
|
TargetPlatform platform = defaultTargetPlatform;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget home = new GalleryHome(
|
Widget home = new GalleryHome(
|
||||||
@ -58,6 +60,11 @@ class GalleryAppState extends State<GalleryApp> {
|
|||||||
_showPerformanceOverlay = value;
|
_showPerformanceOverlay = value;
|
||||||
});
|
});
|
||||||
} : null,
|
} : null,
|
||||||
|
onPlatformChanged: (TargetPlatform value) {
|
||||||
|
setState(() {
|
||||||
|
platform = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
timeDilation: timeDilation,
|
timeDilation: timeDilation,
|
||||||
onTimeDilationChanged: (double value) {
|
onTimeDilationChanged: (double value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -76,7 +83,7 @@ class GalleryAppState extends State<GalleryApp> {
|
|||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
title: 'Flutter Gallery',
|
title: 'Flutter Gallery',
|
||||||
color: Colors.grey[500],
|
color: Colors.grey[500],
|
||||||
theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme,
|
theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: platform),
|
||||||
showPerformanceOverlay: _showPerformanceOverlay,
|
showPerformanceOverlay: _showPerformanceOverlay,
|
||||||
routes: _kRoutes,
|
routes: _kRoutes,
|
||||||
home: home,
|
home: home,
|
||||||
|
@ -92,7 +92,8 @@ class GalleryDrawer extends StatelessWidget {
|
|||||||
this.timeDilation,
|
this.timeDilation,
|
||||||
this.onTimeDilationChanged,
|
this.onTimeDilationChanged,
|
||||||
this.showPerformanceOverlay,
|
this.showPerformanceOverlay,
|
||||||
this.onShowPerformanceOverlayChanged
|
this.onShowPerformanceOverlayChanged,
|
||||||
|
this.onPlatformChanged,
|
||||||
}) : super(key: key) {
|
}) : super(key: key) {
|
||||||
assert(onThemeChanged != null);
|
assert(onThemeChanged != null);
|
||||||
assert(onTimeDilationChanged != null);
|
assert(onTimeDilationChanged != null);
|
||||||
@ -107,6 +108,8 @@ class GalleryDrawer extends StatelessWidget {
|
|||||||
final bool showPerformanceOverlay;
|
final bool showPerformanceOverlay;
|
||||||
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
||||||
|
|
||||||
|
final ValueChanged<TargetPlatform> onPlatformChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final ThemeData themeData = Theme.of(context);
|
final ThemeData themeData = Theme.of(context);
|
||||||
@ -145,6 +148,40 @@ class GalleryDrawer extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final Widget mountainViewItem = new DrawerItem(
|
||||||
|
// on iOS, we don't want to show an Android phone icon
|
||||||
|
icon: new Icon(defaultTargetPlatform == TargetPlatform.iOS ? Icons.star : Icons.phone_android),
|
||||||
|
onPressed: () { onPlatformChanged(TargetPlatform.android); },
|
||||||
|
selected: Theme.of(context).platform == TargetPlatform.android,
|
||||||
|
child: new Row(
|
||||||
|
children: <Widget>[
|
||||||
|
new Flexible(child: new Text('Android')),
|
||||||
|
new Radio<TargetPlatform>(
|
||||||
|
value: TargetPlatform.android,
|
||||||
|
groupValue: Theme.of(context).platform,
|
||||||
|
onChanged: onPlatformChanged,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Widget cupertinoItem = new DrawerItem(
|
||||||
|
// on iOS, we don't want to show the iPhone icon
|
||||||
|
icon: new Icon(defaultTargetPlatform == TargetPlatform.iOS ? Icons.star_border : Icons.phone_iphone),
|
||||||
|
onPressed: () { onPlatformChanged(TargetPlatform.iOS); },
|
||||||
|
selected: Theme.of(context).platform == TargetPlatform.iOS,
|
||||||
|
child: new Row(
|
||||||
|
children: <Widget>[
|
||||||
|
new Flexible(child: new Text('iOS')),
|
||||||
|
new Radio<TargetPlatform>(
|
||||||
|
value: TargetPlatform.iOS,
|
||||||
|
groupValue: Theme.of(context).platform,
|
||||||
|
onChanged: onPlatformChanged,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
final Widget animateSlowlyItem = new DrawerItem(
|
final Widget animateSlowlyItem = new DrawerItem(
|
||||||
icon: new Icon(Icons.hourglass_empty),
|
icon: new Icon(Icons.hourglass_empty),
|
||||||
selected: timeDilation != 1.0,
|
selected: timeDilation != 1.0,
|
||||||
@ -216,14 +253,17 @@ class GalleryDrawer extends StatelessWidget {
|
|||||||
lightThemeItem,
|
lightThemeItem,
|
||||||
darkThemeItem,
|
darkThemeItem,
|
||||||
new Divider(),
|
new Divider(),
|
||||||
|
mountainViewItem,
|
||||||
|
cupertinoItem,
|
||||||
|
new Divider(),
|
||||||
animateSlowlyItem,
|
animateSlowlyItem,
|
||||||
// index 5, optional: Performance Overlay
|
// index 8, optional: Performance Overlay
|
||||||
fileAnIssueItem,
|
fileAnIssueItem,
|
||||||
aboutItem
|
aboutItem
|
||||||
];
|
];
|
||||||
|
|
||||||
if (onShowPerformanceOverlayChanged != null) {
|
if (onShowPerformanceOverlayChanged != null) {
|
||||||
allDrawerItems.insert(5, new DrawerItem(
|
allDrawerItems.insert(8, new DrawerItem(
|
||||||
icon: new Icon(Icons.assessment),
|
icon: new Icon(Icons.assessment),
|
||||||
onPressed: () { onShowPerformanceOverlayChanged(!showPerformanceOverlay); },
|
onPressed: () { onShowPerformanceOverlayChanged(!showPerformanceOverlay); },
|
||||||
selected: showPerformanceOverlay,
|
selected: showPerformanceOverlay,
|
||||||
|
@ -76,7 +76,8 @@ class GalleryHome extends StatefulWidget {
|
|||||||
this.timeDilation,
|
this.timeDilation,
|
||||||
this.onTimeDilationChanged,
|
this.onTimeDilationChanged,
|
||||||
this.showPerformanceOverlay,
|
this.showPerformanceOverlay,
|
||||||
this.onShowPerformanceOverlayChanged
|
this.onShowPerformanceOverlayChanged,
|
||||||
|
this.onPlatformChanged,
|
||||||
}) : super(key: key) {
|
}) : super(key: key) {
|
||||||
assert(onThemeChanged != null);
|
assert(onThemeChanged != null);
|
||||||
assert(onTimeDilationChanged != null);
|
assert(onTimeDilationChanged != null);
|
||||||
@ -91,6 +92,8 @@ class GalleryHome extends StatefulWidget {
|
|||||||
final bool showPerformanceOverlay;
|
final bool showPerformanceOverlay;
|
||||||
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
||||||
|
|
||||||
|
final ValueChanged<TargetPlatform> onPlatformChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
GalleryHomeState createState() => new GalleryHomeState();
|
GalleryHomeState createState() => new GalleryHomeState();
|
||||||
}
|
}
|
||||||
@ -153,7 +156,8 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
|
|||||||
timeDilation: config.timeDilation,
|
timeDilation: config.timeDilation,
|
||||||
onTimeDilationChanged: config.onTimeDilationChanged,
|
onTimeDilationChanged: config.onTimeDilationChanged,
|
||||||
showPerformanceOverlay: config.showPerformanceOverlay,
|
showPerformanceOverlay: config.showPerformanceOverlay,
|
||||||
onShowPerformanceOverlayChanged: config.onShowPerformanceOverlayChanged
|
onShowPerformanceOverlayChanged: config.onShowPerformanceOverlayChanged,
|
||||||
|
onPlatformChanged: config.onPlatformChanged,
|
||||||
),
|
),
|
||||||
appBar: new AppBar(
|
appBar: new AppBar(
|
||||||
expandedHeight: _kFlexibleSpaceMaxHeight,
|
expandedHeight: _kFlexibleSpaceMaxHeight,
|
||||||
|
@ -7,6 +7,8 @@ import 'dart:io' show Platform;
|
|||||||
import 'assertions.dart';
|
import 'assertions.dart';
|
||||||
|
|
||||||
/// The platform that user interaction should adapt to target.
|
/// The platform that user interaction should adapt to target.
|
||||||
|
///
|
||||||
|
/// The [defaultTargetPlatform] getter returns the current platform.
|
||||||
enum TargetPlatform {
|
enum TargetPlatform {
|
||||||
/// Android: <https://www.android.com/>
|
/// Android: <https://www.android.com/>
|
||||||
android,
|
android,
|
||||||
@ -25,7 +27,7 @@ enum TargetPlatform {
|
|||||||
/// regardless of the host platform. (Android was chosen because the tests were
|
/// regardless of the host platform. (Android was chosen because the tests were
|
||||||
/// originally written assuming Android-like behavior, and we added platform
|
/// originally written assuming Android-like behavior, and we added platform
|
||||||
/// adaptations for iOS later). Tests can check iOS behavior by using the
|
/// adaptations for iOS later). Tests can check iOS behavior by using the
|
||||||
/// platform override APIs (like in [ThemeData.platform] in the material
|
/// platform override APIs (such as [ThemeData.platform] in the material
|
||||||
/// library).
|
/// library).
|
||||||
TargetPlatform get defaultTargetPlatform {
|
TargetPlatform get defaultTargetPlatform {
|
||||||
TargetPlatform result;
|
TargetPlatform result;
|
||||||
|
@ -332,6 +332,66 @@ class ThemeData {
|
|||||||
/// Defaults to the current platform.
|
/// Defaults to the current platform.
|
||||||
final TargetPlatform platform;
|
final TargetPlatform platform;
|
||||||
|
|
||||||
|
/// Creates a copy of this theme but with the given fields replaced with the new values.
|
||||||
|
ThemeData copyWith({
|
||||||
|
Brightness brightness,
|
||||||
|
Map<int, Color> primarySwatch,
|
||||||
|
Color primaryColor,
|
||||||
|
Brightness primaryColorBrightness,
|
||||||
|
Color accentColor,
|
||||||
|
Brightness accentColorBrightness,
|
||||||
|
Color canvasColor,
|
||||||
|
Color cardColor,
|
||||||
|
Color dividerColor,
|
||||||
|
Color highlightColor,
|
||||||
|
Color splashColor,
|
||||||
|
Color selectedRowColor,
|
||||||
|
Color unselectedWidgetColor,
|
||||||
|
Color disabledColor,
|
||||||
|
Color buttonColor,
|
||||||
|
Color secondaryHeaderColor,
|
||||||
|
Color textSelectionColor,
|
||||||
|
Color textSelectionHandleColor,
|
||||||
|
Color backgroundColor,
|
||||||
|
Color indicatorColor,
|
||||||
|
Color hintColor,
|
||||||
|
Color errorColor,
|
||||||
|
TextTheme textTheme,
|
||||||
|
TextTheme primaryTextTheme,
|
||||||
|
IconThemeData iconTheme,
|
||||||
|
IconThemeData primaryIconTheme,
|
||||||
|
TargetPlatform platform,
|
||||||
|
}) {
|
||||||
|
return new ThemeData(
|
||||||
|
brightness: brightness ?? this.brightness,
|
||||||
|
primaryColor: primaryColor ?? this.primaryColor,
|
||||||
|
primaryColorBrightness: primaryColorBrightness ?? this.primaryColorBrightness,
|
||||||
|
accentColor: accentColor ?? this.accentColor,
|
||||||
|
accentColorBrightness: accentColorBrightness ?? this.accentColorBrightness,
|
||||||
|
canvasColor: canvasColor ?? this.canvasColor,
|
||||||
|
cardColor: cardColor ?? this.cardColor,
|
||||||
|
dividerColor: dividerColor ?? this.dividerColor,
|
||||||
|
highlightColor: highlightColor ?? this.highlightColor,
|
||||||
|
splashColor: splashColor ?? this.splashColor,
|
||||||
|
selectedRowColor: selectedRowColor ?? this.selectedRowColor,
|
||||||
|
unselectedWidgetColor: unselectedWidgetColor ?? this.unselectedWidgetColor,
|
||||||
|
disabledColor: disabledColor ?? this.disabledColor,
|
||||||
|
buttonColor: buttonColor ?? this.buttonColor,
|
||||||
|
secondaryHeaderColor: secondaryHeaderColor ?? this.secondaryHeaderColor,
|
||||||
|
textSelectionColor: textSelectionColor ?? this.textSelectionColor,
|
||||||
|
textSelectionHandleColor: textSelectionHandleColor ?? this.textSelectionHandleColor,
|
||||||
|
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||||
|
indicatorColor: indicatorColor ?? this.indicatorColor,
|
||||||
|
hintColor: hintColor ?? this.hintColor,
|
||||||
|
errorColor: errorColor ?? this.errorColor,
|
||||||
|
textTheme: textTheme ?? this.textTheme,
|
||||||
|
primaryTextTheme: primaryTextTheme ?? this.primaryTextTheme,
|
||||||
|
iconTheme: iconTheme ?? this.iconTheme,
|
||||||
|
primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
|
||||||
|
platform: platform ?? this.platform,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Linearly interpolate between two themes.
|
/// Linearly interpolate between two themes.
|
||||||
static ThemeData lerp(ThemeData begin, ThemeData end, double t) {
|
static ThemeData lerp(ThemeData begin, ThemeData end, double t) {
|
||||||
return new ThemeData.raw(
|
return new ThemeData.raw(
|
||||||
@ -393,7 +453,8 @@ class ThemeData {
|
|||||||
(otherData.textTheme == textTheme) &&
|
(otherData.textTheme == textTheme) &&
|
||||||
(otherData.primaryTextTheme == primaryTextTheme) &&
|
(otherData.primaryTextTheme == primaryTextTheme) &&
|
||||||
(otherData.iconTheme == iconTheme) &&
|
(otherData.iconTheme == iconTheme) &&
|
||||||
(otherData.primaryIconTheme == primaryIconTheme);
|
(otherData.primaryIconTheme == primaryIconTheme) &&
|
||||||
|
(otherData.platform == platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -417,14 +478,15 @@ class ThemeData {
|
|||||||
backgroundColor,
|
backgroundColor,
|
||||||
accentColor,
|
accentColor,
|
||||||
accentColorBrightness,
|
accentColorBrightness,
|
||||||
|
indicatorColor,
|
||||||
hashValues( // Too many values.
|
hashValues( // Too many values.
|
||||||
indicatorColor,
|
|
||||||
hintColor,
|
hintColor,
|
||||||
errorColor,
|
errorColor,
|
||||||
textTheme,
|
textTheme,
|
||||||
primaryTextTheme,
|
primaryTextTheme,
|
||||||
iconTheme,
|
iconTheme,
|
||||||
primaryIconTheme
|
primaryIconTheme,
|
||||||
|
platform,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user