date_picker.dart 1.55 KB
Newer Older
1 2 3 4 5
// 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 'package:sky/widgets.dart';
6
import 'package:sky/material.dart';
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

void main() => runApp(new DatePickerDemo());

class DatePickerDemo extends App {

  DateTime _dateTime;

  void initState() {
    DateTime now = new DateTime.now();
    _dateTime = new DateTime(now.year, now.month, now.day);
  }

  void _handleDateChanged(DateTime dateTime) {
    setState(() {
      _dateTime = dateTime;
    });
  }

  Widget build() {
    return new Theme(
      data: new ThemeData(
        brightness: ThemeBrightness.light,
29
        primarySwatch: Colors.teal
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      ),
      child: new Stack([
        new Scaffold(
          toolbar: new ToolBar(center: new Text("Date Picker")),
          body: new Material(
            child: new Row(
              [new Text(_dateTime.toString())],
              alignItems: FlexAlignItems.end,
              justifyContent: FlexJustifyContent.center
            )
          )
        ),
        new Dialog(
          content: new DatePicker(
            selectedDate: _dateTime,
            firstDate: new DateTime(2015, 8),
            lastDate: new DateTime(2101),
            onChanged: _handleDateChanged
          ),
          contentPadding: EdgeDims.zero,
          actions: [
            new FlatButton(
              child: new Text('CANCEL')
            ),
            new FlatButton(
              child: new Text('OK')
            ),
          ]
        )
      ])
    );
  }
}