Integrate Date Picker into material_gallery

This commit is contained in:
Adam Barth
2015-11-23 15:20:23 -08:00
parent 1a351a6598
commit b17fe3afb2
11 changed files with 192 additions and 124 deletions

View File

@@ -15,6 +15,7 @@ export 'src/material/circle_avatar.dart';
export 'src/material/colors.dart';
export 'src/material/constants.dart';
export 'src/material/date_picker.dart';
export 'src/material/date_picker_dialog.dart';
export 'src/material/dialog.dart';
export 'src/material/drawer.dart';
export 'src/material/drawer_divider.dart';

View File

@@ -0,0 +1,88 @@
// Copyright 2015 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 'dart:async';
import 'package:flutter/widgets.dart';
import 'dialog.dart';
import 'date_picker.dart';
import 'flat_button.dart';
class _DatePickerDialog extends StatefulComponent {
_DatePickerDialog({
Key key,
this.initialDate,
this.firstDate,
this.lastDate
}) : super(key: key);
final DateTime initialDate;
final DateTime firstDate;
final DateTime lastDate;
_DatePickerDialogState createState() => new _DatePickerDialogState();
}
class _DatePickerDialogState extends State<_DatePickerDialog> {
void initState() {
super.initState();
_selectedDate = config.initialDate;
}
DateTime _selectedDate;
void _handleDateChanged(DateTime value) {
setState(() {
_selectedDate = value;
});
}
void _handleCancel() {
Navigator.of(context).pop();
}
void _handleOk() {
Navigator.of(context).pop(_selectedDate);
}
Widget build(BuildContext context) {
return new Dialog(
content: new DatePicker(
selectedDate: _selectedDate,
firstDate: config.firstDate,
lastDate: config.lastDate,
onChanged: _handleDateChanged
),
contentPadding: EdgeDims.zero,
actions: <Widget>[
new FlatButton(
child: new Text('CANCEL'),
onPressed: _handleCancel
),
new FlatButton(
child: new Text('OK'),
onPressed: _handleOk
),
]
);
}
}
Future<DateTime> showDatePicker({
BuildContext context,
DateTime initialDate,
DateTime firstDate,
DateTime lastDate
}) async {
DateTime picked = await showDialog(
context: context,
child: new _DatePickerDialog(
initialDate: initialDate,
firstDate: firstDate,
lastDate: lastDate
)
);
return picked ?? initialDate;
}