mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Anywhere that accepted IconData now accepts either an Icon or an ImageIcon. Places that used to take an IconData in an `icon` argument, notably IconButton and DrawerItem, now take a Widget in that slot. You can wrap the value that used to be passed in in an Icon constructor to get the same result. Icon itself now takes the icon as a positional argument, for brevity. ThemeData now has an iconTheme as well as a primaryIconTheme, the same way it has had a textTheme and primaryTextTheme for a while. IconTheme.of() always returns a value now (though that value itself may have nulls in it). It defaults to the ThemeData.iconTheme. IconThemeData.fallback() is a new method that returns an icon theme data structure with all fields filled in. IconTheme.merge() is a new constructor that takes a context and creates a widget that mixes in the new values with the inherited values. Most places that introduced an IconTheme widget now use IconTheme.merge. IconThemeData.merge and IconThemeData.copyWith act in a way analogous to the similarly-named members of TextStyle. ImageIcon is introduced. It acts like Icon but takes an ImageProvider instead of an IconData. Also: Fix the analyzer to actually check the stocks app.
247 lines
7.8 KiB
Dart
247 lines
7.8 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:intl/intl.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
// This demo is based on
|
|
// https://www.google.com/design/spec/components/dialogs.html#dialogs-full-screen-dialogs
|
|
|
|
enum DismissDialogAction {
|
|
cancel,
|
|
discard,
|
|
save,
|
|
}
|
|
|
|
class DateTimeItem extends StatelessWidget {
|
|
DateTimeItem({ Key key, DateTime dateTime, this.onChanged })
|
|
: date = new DateTime(dateTime.year, dateTime.month, dateTime.day),
|
|
time = new TimeOfDay(hour: dateTime.hour, minute: dateTime.minute),
|
|
super(key: key) {
|
|
assert(onChanged != null);
|
|
}
|
|
|
|
final DateTime date;
|
|
final TimeOfDay time;
|
|
final ValueChanged<DateTime> onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final ThemeData theme = Theme.of(context);
|
|
|
|
return new DefaultTextStyle(
|
|
style: theme.textTheme.subhead,
|
|
child: new Row(
|
|
children: <Widget>[
|
|
new Flexible(
|
|
child: new Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
decoration: new BoxDecoration(
|
|
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
|
),
|
|
child: new InkWell(
|
|
onTap: () {
|
|
showDatePicker(
|
|
context: context,
|
|
initialDate: date,
|
|
firstDate: date.subtract(const Duration(days: 30)),
|
|
lastDate: date.add(const Duration(days: 30))
|
|
)
|
|
.then((DateTime value) {
|
|
onChanged(new DateTime(value.year, value.month, value.day, time.hour, time.minute));
|
|
});
|
|
},
|
|
child: new Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
new Text(new DateFormat('EEE, MMM d yyyy').format(date)),
|
|
new Icon(Icons.arrow_drop_down, color: Colors.black54),
|
|
]
|
|
)
|
|
)
|
|
)
|
|
),
|
|
new Container(
|
|
margin: const EdgeInsets.only(left: 8.0),
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
decoration: new BoxDecoration(
|
|
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
|
),
|
|
child: new InkWell(
|
|
onTap: () {
|
|
showTimePicker(
|
|
context: context,
|
|
initialTime: time
|
|
)
|
|
.then((TimeOfDay value) {
|
|
onChanged(new DateTime(date.year, date.month, date.day, value.hour, value.minute));
|
|
});
|
|
},
|
|
child: new Row(
|
|
children: <Widget>[
|
|
new Text('$time'),
|
|
new Icon(Icons.arrow_drop_down, color: Colors.black54),
|
|
]
|
|
)
|
|
)
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
class FullScreenDialogDemo extends StatefulWidget {
|
|
@override
|
|
FullScreenDialogDemoState createState() => new FullScreenDialogDemoState();
|
|
}
|
|
|
|
class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
|
|
DateTime _fromDateTime = new DateTime.now();
|
|
DateTime _toDateTime = new DateTime.now();
|
|
bool _allDayValue = false;
|
|
bool _saveNeeded = false;
|
|
|
|
void handleDismissButton(BuildContext context) {
|
|
if (!_saveNeeded) {
|
|
Navigator.pop(context, null);
|
|
return;
|
|
}
|
|
|
|
final ThemeData theme = Theme.of(context);
|
|
final TextStyle dialogTextStyle = theme.textTheme.subhead.copyWith(color: theme.textTheme.caption.color);
|
|
|
|
showDialog(
|
|
context: context,
|
|
child: new Dialog(
|
|
content: new Text(
|
|
'Discard new event?',
|
|
style: dialogTextStyle
|
|
),
|
|
actions: <Widget>[
|
|
new FlatButton(
|
|
child: new Text('CANCEL'),
|
|
onPressed: () { Navigator.pop(context, DismissDialogAction.cancel); }
|
|
),
|
|
new FlatButton(
|
|
child: new Text('DISCARD'),
|
|
onPressed: () {
|
|
Navigator.openTransaction(context, (NavigatorTransaction transaction) {
|
|
transaction.pop(DismissDialogAction.discard); // pop the cancel/discard dialog
|
|
transaction.pop(null); // pop this route
|
|
});
|
|
}
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final ThemeData theme = Theme.of(context);
|
|
|
|
return new Scaffold(
|
|
appBar: new AppBar(
|
|
leading: new IconButton(
|
|
icon: new Icon(Icons.clear),
|
|
onPressed: () { handleDismissButton(context); }
|
|
),
|
|
title: new Text('New event'),
|
|
actions: <Widget> [
|
|
new FlatButton(
|
|
child: new Text('SAVE', style: theme.textTheme.body1.copyWith(color: Colors.white)),
|
|
onPressed: () {
|
|
Navigator.pop(context, DismissDialogAction.save);
|
|
}
|
|
)
|
|
]
|
|
),
|
|
body: new Block(
|
|
padding: const EdgeInsets.all(16.0),
|
|
children: <Widget>[
|
|
new Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
decoration: new BoxDecoration(
|
|
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
|
),
|
|
child: new Align(
|
|
alignment: FractionalOffset.bottomLeft,
|
|
child: new Text('Event name', style: theme.textTheme.display2)
|
|
)
|
|
),
|
|
new Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
decoration: new BoxDecoration(
|
|
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
|
),
|
|
child: new Align(
|
|
alignment: FractionalOffset.bottomLeft,
|
|
child: new Text('Location', style: theme.textTheme.title.copyWith(color: Colors.black54))
|
|
)
|
|
),
|
|
new Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
new Text('From', style: theme.textTheme.caption),
|
|
new DateTimeItem(
|
|
dateTime: _fromDateTime,
|
|
onChanged: (DateTime value) {
|
|
setState(() {
|
|
_fromDateTime = value;
|
|
_saveNeeded = true;
|
|
});
|
|
}
|
|
)
|
|
]
|
|
),
|
|
new Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
new Text('To', style: theme.textTheme.caption),
|
|
new DateTimeItem(
|
|
dateTime: _toDateTime,
|
|
onChanged: (DateTime value) {
|
|
setState(() {
|
|
_toDateTime = value;
|
|
_saveNeeded = true;
|
|
});
|
|
}
|
|
)
|
|
]
|
|
),
|
|
new Container(
|
|
decoration: new BoxDecoration(
|
|
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
|
),
|
|
child: new Row(
|
|
children: <Widget> [
|
|
new Checkbox(
|
|
value: _allDayValue,
|
|
onChanged: (bool value) {
|
|
setState(() {
|
|
_allDayValue = value;
|
|
_saveNeeded = true;
|
|
});
|
|
}
|
|
),
|
|
new Text('All-day')
|
|
]
|
|
)
|
|
)
|
|
]
|
|
.map((Widget child) {
|
|
return new Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
height: 96.0,
|
|
child: child
|
|
);
|
|
})
|
|
.toList()
|
|
)
|
|
);
|
|
}
|
|
}
|