Platform selector in gallery. (#6390)
This commit is contained in:
@@ -43,6 +43,8 @@ class GalleryAppState extends State<GalleryApp> {
|
||||
bool _useLightTheme = true;
|
||||
bool _showPerformanceOverlay = false;
|
||||
|
||||
TargetPlatform platform = defaultTargetPlatform;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget home = new GalleryHome(
|
||||
@@ -58,6 +60,11 @@ class GalleryAppState extends State<GalleryApp> {
|
||||
_showPerformanceOverlay = value;
|
||||
});
|
||||
} : null,
|
||||
onPlatformChanged: (TargetPlatform value) {
|
||||
setState(() {
|
||||
platform = value;
|
||||
});
|
||||
},
|
||||
timeDilation: timeDilation,
|
||||
onTimeDilationChanged: (double value) {
|
||||
setState(() {
|
||||
@@ -76,7 +83,7 @@ class GalleryAppState extends State<GalleryApp> {
|
||||
return new MaterialApp(
|
||||
title: 'Flutter Gallery',
|
||||
color: Colors.grey[500],
|
||||
theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme,
|
||||
theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: platform),
|
||||
showPerformanceOverlay: _showPerformanceOverlay,
|
||||
routes: _kRoutes,
|
||||
home: home,
|
||||
|
||||
@@ -92,7 +92,8 @@ class GalleryDrawer extends StatelessWidget {
|
||||
this.timeDilation,
|
||||
this.onTimeDilationChanged,
|
||||
this.showPerformanceOverlay,
|
||||
this.onShowPerformanceOverlayChanged
|
||||
this.onShowPerformanceOverlayChanged,
|
||||
this.onPlatformChanged,
|
||||
}) : super(key: key) {
|
||||
assert(onThemeChanged != null);
|
||||
assert(onTimeDilationChanged != null);
|
||||
@@ -107,6 +108,8 @@ class GalleryDrawer extends StatelessWidget {
|
||||
final bool showPerformanceOverlay;
|
||||
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
||||
|
||||
final ValueChanged<TargetPlatform> onPlatformChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext 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(
|
||||
icon: new Icon(Icons.hourglass_empty),
|
||||
selected: timeDilation != 1.0,
|
||||
@@ -216,14 +253,17 @@ class GalleryDrawer extends StatelessWidget {
|
||||
lightThemeItem,
|
||||
darkThemeItem,
|
||||
new Divider(),
|
||||
mountainViewItem,
|
||||
cupertinoItem,
|
||||
new Divider(),
|
||||
animateSlowlyItem,
|
||||
// index 5, optional: Performance Overlay
|
||||
// index 8, optional: Performance Overlay
|
||||
fileAnIssueItem,
|
||||
aboutItem
|
||||
];
|
||||
|
||||
if (onShowPerformanceOverlayChanged != null) {
|
||||
allDrawerItems.insert(5, new DrawerItem(
|
||||
allDrawerItems.insert(8, new DrawerItem(
|
||||
icon: new Icon(Icons.assessment),
|
||||
onPressed: () { onShowPerformanceOverlayChanged(!showPerformanceOverlay); },
|
||||
selected: showPerformanceOverlay,
|
||||
|
||||
@@ -76,7 +76,8 @@ class GalleryHome extends StatefulWidget {
|
||||
this.timeDilation,
|
||||
this.onTimeDilationChanged,
|
||||
this.showPerformanceOverlay,
|
||||
this.onShowPerformanceOverlayChanged
|
||||
this.onShowPerformanceOverlayChanged,
|
||||
this.onPlatformChanged,
|
||||
}) : super(key: key) {
|
||||
assert(onThemeChanged != null);
|
||||
assert(onTimeDilationChanged != null);
|
||||
@@ -91,6 +92,8 @@ class GalleryHome extends StatefulWidget {
|
||||
final bool showPerformanceOverlay;
|
||||
final ValueChanged<bool> onShowPerformanceOverlayChanged;
|
||||
|
||||
final ValueChanged<TargetPlatform> onPlatformChanged;
|
||||
|
||||
@override
|
||||
GalleryHomeState createState() => new GalleryHomeState();
|
||||
}
|
||||
@@ -153,7 +156,8 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
|
||||
timeDilation: config.timeDilation,
|
||||
onTimeDilationChanged: config.onTimeDilationChanged,
|
||||
showPerformanceOverlay: config.showPerformanceOverlay,
|
||||
onShowPerformanceOverlayChanged: config.onShowPerformanceOverlayChanged
|
||||
onShowPerformanceOverlayChanged: config.onShowPerformanceOverlayChanged,
|
||||
onPlatformChanged: config.onPlatformChanged,
|
||||
),
|
||||
appBar: new AppBar(
|
||||
expandedHeight: _kFlexibleSpaceMaxHeight,
|
||||
|
||||
Reference in New Issue
Block a user