Commit a555ee47 authored by Hans Muller's avatar Hans Muller Committed by GitHub

TimePicker layout tweaks (#5047)

parent 3b577c53
...@@ -64,6 +64,15 @@ class DialogDemo extends StatefulWidget { ...@@ -64,6 +64,15 @@ class DialogDemo extends StatefulWidget {
class DialogDemoState extends State<DialogDemo> { class DialogDemoState extends State<DialogDemo> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
TimeOfDay _selectedTime;
@override
void initState() {
super.initState();
final DateTime now = new DateTime.now();
_selectedTime = new TimeOfDay(hour: now.hour, minute: now.minute);
}
void showDemoDialog/*<T>*/({ BuildContext context, Dialog dialog }) { void showDemoDialog/*<T>*/({ BuildContext context, Dialog dialog }) {
showDialog/*<T>*/( showDialog/*<T>*/(
context: context, context: context,
...@@ -177,10 +186,11 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -177,10 +186,11 @@ class DialogDemoState extends State<DialogDemo> {
onPressed: () { onPressed: () {
showTimePicker( showTimePicker(
context: context, context: context,
initialTime: const TimeOfDay(hour: 15, minute: 30) initialTime: _selectedTime
) )
.then((TimeOfDay value) { // The value passed to Navigator.pop() or null. .then((TimeOfDay value) {
if (value != null) { if (value != _selectedTime) {
_selectedTime = value;
_scaffoldKey.currentState.showSnackBar(new SnackBar( _scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text('You selected: $value') content: new Text('You selected: $value')
)); ));
......
...@@ -99,8 +99,8 @@ class TimeOfDay { ...@@ -99,8 +99,8 @@ class TimeOfDay {
} }
enum _TimePickerMode { hour, minute } enum _TimePickerMode { hour, minute }
const double _kHeaderFontSize = 65.0; const double _kHeaderFontSize = 60.0;
const double _kPreferredDialExtent = 300.0; const double _kPreferredDialExtent = 296.0;
/// A material design time picker. /// A material design time picker.
/// ///
...@@ -250,8 +250,7 @@ class _TimePickerHeader extends StatelessWidget { ...@@ -250,8 +250,7 @@ class _TimePickerHeader extends StatelessWidget {
); );
return new Container( return new Container(
height: 100.0, height: 96.0,
padding: const EdgeInsets.symmetric(horizontal: 24.0),
decoration: new BoxDecoration(backgroundColor: backgroundColor), decoration: new BoxDecoration(backgroundColor: backgroundColor),
child: new Row( child: new Row(
children: <Widget>[ children: <Widget>[
...@@ -274,7 +273,7 @@ class _TimePickerHeader extends StatelessWidget { ...@@ -274,7 +273,7 @@ class _TimePickerHeader extends StatelessWidget {
onTap: () => _handleChangeMode(_TimePickerMode.minute), onTap: () => _handleChangeMode(_TimePickerMode.minute),
child: new Text(selectedTime.minuteLabel, style: minuteStyle) child: new Text(selectedTime.minuteLabel, style: minuteStyle)
), ),
new Container(width: 16.0, height: 0.0), // Horizontal spacer new Container(width: 8.0, height: 0.0), // Horizontal spacer
new GestureDetector( new GestureDetector(
onTap: _handleChangeDayPeriod, onTap: _handleChangeDayPeriod,
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
......
...@@ -71,7 +71,16 @@ class _TimePickerDialogState extends State<_TimePickerDialog> { ...@@ -71,7 +71,16 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// ///
/// The returned Future resolves to the time selected by the user when the user /// The returned Future resolves to the time selected by the user when the user
/// closes the dialog. If the user cancels the dialog, the Future resolves to /// closes the dialog. If the user cancels the dialog, the Future resolves to
/// the initialTime. /// the [initialTime].
///
/// To show a dialog with [initialTime] equal to the current time:
/// ```dart
/// final DateTime now = new DateTime.now();
/// showTimePicker(
/// initialTime: new TimeOfDay(hour: now.hour, minute: now.minute),
/// context: context
/// );
/// ```
/// ///
/// See also: /// See also:
/// ///
......
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