Commit 972781f9 authored by Hans Muller's avatar Hans Muller

Merge pull request #1638 from HansMuller/gallery_drawer

Gallery support for light/dark theme switching, slow animation speed
parents cb9152ca 2d914526
name: material_gallery name: material_gallery
assets: assets:
- assets/ali_connors.png
- assets/flutter_logo.png - assets/flutter_logo.png
- assets/section_animation.png - assets/section_animation.png
- assets/section_style.png - assets/section_style.png
...@@ -8,6 +7,7 @@ assets: ...@@ -8,6 +7,7 @@ assets:
- assets/section_components.png - assets/section_components.png
- assets/section_patterns.png - assets/section_patterns.png
- assets/section_usability.png - assets/section_usability.png
- packages/flutter_gallery_assets/ali_connors.png
- packages/flutter_gallery_assets/sun.png - packages/flutter_gallery_assets/sun.png
- packages/flutter_gallery_assets/clouds-0.png - packages/flutter_gallery_assets/clouds-0.png
- packages/flutter_gallery_assets/clouds-1.png - packages/flutter_gallery_assets/clouds-1.png
...@@ -19,20 +19,12 @@ assets: ...@@ -19,20 +19,12 @@ assets:
- packages/flutter_gallery_assets/icon-rain.png - packages/flutter_gallery_assets/icon-rain.png
- packages/flutter_gallery_assets/icon-snow.png - packages/flutter_gallery_assets/icon-snow.png
material-design-icons: material-design-icons:
- name: navigation/arrow_drop_down
- name: navigation/arrow_forward
- name: navigation/arrow_back
- name: navigation/cancel
- name: navigation/expand_less
- name: navigation/expand_more
- name: navigation/menu
- name: navigation/more_horiz
- name: navigation/more_vert
- name: action/event
- name: action/home
- name: action/android
- name: action/alarm - name: action/alarm
- name: action/android
- name: action/event
- name: action/face - name: action/face
- name: action/home
- name: action/hourglass_empty
- name: action/language - name: action/language
- name: communication/call - name: communication/call
- name: communication/email - name: communication/email
...@@ -40,3 +32,14 @@ material-design-icons: ...@@ -40,3 +32,14 @@ material-design-icons:
- name: communication/message - name: communication/message
- name: content/add - name: content/add
- name: content/create - name: content/create
- name: image/brightness_5
- name: image/brightness_7
- name: navigation/arrow_back
- name: navigation/arrow_drop_down
- name: navigation/arrow_forward
- name: navigation/cancel
- name: navigation/expand_less
- name: navigation/expand_more
- name: navigation/menu
- name: navigation/more_horiz
- name: navigation/more_vert
...@@ -100,7 +100,7 @@ class FlexibleSpaceDemoState extends State<FlexibleSpaceDemo> { ...@@ -100,7 +100,7 @@ class FlexibleSpaceDemoState extends State<FlexibleSpaceDemo> {
return new FlexibleSpaceBar( return new FlexibleSpaceBar(
title : new Text('Ali Connors'), title : new Text('Ali Connors'),
image: new AssetImage( image: new AssetImage(
name: 'assets/ali_connors.png', name: 'packages/flutter_gallery_assets/ali_connors.png',
fit: ImageFit.cover, fit: ImageFit.cover,
height: appBarHeight height: appBarHeight
) )
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';// show timeDilation;
import 'demo/chip_demo.dart'; import 'demo/chip_demo.dart';
import 'demo/date_picker_demo.dart'; import 'demo/date_picker_demo.dart';
...@@ -48,7 +49,7 @@ class GallerySection extends StatelessComponent { ...@@ -48,7 +49,7 @@ class GallerySection extends StatelessComponent {
void showDemos(BuildContext context) { void showDemos(BuildContext context) {
final theme = new ThemeData( final theme = new ThemeData(
brightness: ThemeBrightness.light, brightness: Theme.of(context).brightness,
primarySwatch: colors primarySwatch: colors
); );
final appBarHeight = 200.0; final appBarHeight = 200.0;
...@@ -85,12 +86,13 @@ class GallerySection extends StatelessComponent { ...@@ -85,12 +86,13 @@ class GallerySection extends StatelessComponent {
Widget build (BuildContext context) { Widget build (BuildContext context) {
final theme = new ThemeData( final theme = new ThemeData(
brightness: ThemeBrightness.dark, brightness: Theme.of(context).brightness,
primarySwatch: colors primarySwatch: colors
); );
return new Theme( final titleTextStyle = theme.text.title.copyWith(
data: theme, color: theme.brightness == ThemeBrightness.dark ? Colors.black : Colors.white
child: new Flexible( );
return new Flexible(
child: new GestureDetector( child: new GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { showDemos(context); }, onTap: () { showDemos(context); },
...@@ -114,19 +116,31 @@ class GallerySection extends StatelessComponent { ...@@ -114,19 +116,31 @@ class GallerySection extends StatelessComponent {
padding: const EdgeDims.all(16.0), padding: const EdgeDims.all(16.0),
child: new Align( child: new Align(
alignment: const FractionalOffset(0.0, 1.0), alignment: const FractionalOffset(0.0, 1.0),
child: new Text(title, style: theme.text.title) child: new Text(title, style: titleTextStyle)
) )
) )
] ]
) )
) )
) )
)
); );
} }
} }
class GalleryHome extends StatelessComponent { class GalleryHome extends StatefulComponent {
GalleryHomeState createState() => new GalleryHomeState();
}
class GalleryHomeState extends State<GalleryHome> {
void _changeTheme(BuildContext context, bool value) {
GalleryApp.of(context).lightTheme = value;
}
void _toggleAnimationSpeed() {
setState((){
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
...@@ -143,6 +157,58 @@ class GalleryHome extends StatelessComponent { ...@@ -143,6 +157,58 @@ class GalleryHome extends StatelessComponent {
); );
} }
), ),
drawer: new Drawer(
child: new Block(
children: <Widget>[
new DrawerHeader(child: new Text('Flutter Gallery')),
new DrawerItem(
icon: 'image/brightness_5',
onPressed: () { _changeTheme(context, true); },
selected: GalleryApp.of(context).lightTheme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Light')),
new Radio<bool>(
value: true,
groupValue: GalleryApp.of(context).lightTheme,
onChanged: (bool value) { _changeTheme(context, value); }
)
]
)
),
new DrawerItem(
icon: 'image/brightness_7',
onPressed: () { _changeTheme(context, false); },
selected: !GalleryApp.of(context).lightTheme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Dark')),
new Radio<bool>(
value: false,
groupValue: GalleryApp.of(context).lightTheme,
onChanged: (bool value) { _changeTheme(context, value); }
)
]
)
),
new DrawerDivider(),
new DrawerItem(
icon: 'action/hourglass_empty',
selected: timeDilation != 1.0,
onPressed: () { _toggleAnimationSpeed(); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Animate Slowly')),
new Checkbox(
value: timeDilation != 1.0,
onChanged: (bool value) { _toggleAnimationSpeed(); }
)
]
)
)
]
)
),
body: new Padding( body: new Padding(
padding: const EdgeDims.all(4.0), padding: const EdgeDims.all(4.0),
child: new Block( child: new Block(
...@@ -217,11 +283,32 @@ class GalleryHome extends StatelessComponent { ...@@ -217,11 +283,32 @@ class GalleryHome extends StatelessComponent {
} }
} }
void main() { class GalleryApp extends StatefulComponent {
runApp(new MaterialApp( static GalleryAppState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher<GalleryAppState>());
title: 'Material Gallery',
GalleryAppState createState() => new GalleryAppState();
}
class GalleryAppState extends State<GalleryApp> {
bool _lightTheme = true;
bool get lightTheme => _lightTheme;
void set lightTheme(bool value) {
setState(() {
_lightTheme = value;
});
}
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Material Gallery',
theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(),
routes: { routes: {
'/': (RouteArguments args) => new GalleryHome() '/': (RouteArguments args) => new GalleryHome()
} }
)); );
}
}
void main() {
runApp(new GalleryApp());
} }
...@@ -6,4 +6,4 @@ dependencies: ...@@ -6,4 +6,4 @@ dependencies:
path: ../../packages/flutter path: ../../packages/flutter
flutter_sprites: flutter_sprites:
path: ../../packages/flutter_sprites path: ../../packages/flutter_sprites
flutter_gallery_assets: '0.0.2' flutter_gallery_assets: '0.0.3'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment