Ian Hickson d748186c51 Use callbacks for sending messages up the app
Using .of() to call mutating setters is not great practice since it ties

parts of the app together in ways that prevent reuse and composition.



Since people are now using the gallery app to copy from, let's use the

better practice of using callbacks.
2016-04-04 15:25:06 -07:00

81 lines
2.3 KiB
Dart

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class GalleryDrawer extends StatelessWidget {
GalleryDrawer({
Key key,
this.theme,
this.onThemeChanged,
this.timeDilation,
this.onTimeDilationChanged
}) : super(key: key) {
assert(onThemeChanged != null);
assert(onTimeDilationChanged != null);
}
final bool theme;
final ValueChanged<bool> onThemeChanged;
final double timeDilation;
final ValueChanged<double> onTimeDilationChanged;
@override
Widget build(BuildContext context) {
return new Drawer(
child: new Block(
children: <Widget>[
new DrawerHeader(child: new Text('Flutter Gallery')),
new DrawerItem(
icon: Icons.brightness_5,
onPressed: () { onThemeChanged(true); },
selected: theme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Light')),
new Radio<bool>(
value: true,
groupValue: theme,
onChanged: onThemeChanged
)
]
)
),
new DrawerItem(
icon: Icons.brightness_7,
onPressed: () { onThemeChanged(false); },
selected: theme,
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Dark')),
new Radio<bool>(
value: false,
groupValue: theme,
onChanged: onThemeChanged
)
]
)
),
new Divider(),
new DrawerItem(
icon: Icons.hourglass_empty,
selected: timeDilation != 1.0,
onPressed: () { onTimeDilationChanged(timeDilation != 1.0 ? 1.0 : 20.0); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Animate Slowly')),
new Checkbox(
value: timeDilation != 1.0,
onChanged: (bool value) { onTimeDilationChanged(value ? 20.0 : 1.0); }
)
]
)
)
]
)
);
}
}