Merge pull request #2216 from HansMuller/stocks_demo
Add CheckedPopupMenuitem, update the Stocks demo
This commit is contained in:
@@ -11,7 +11,7 @@ import 'theme.dart';
|
||||
/// Icons are defined with the [left] and [right] parameters. The first line of text
|
||||
/// is not optional and is specified with [primary]. The value of [secondary] will
|
||||
/// occupy the space allocated for an aditional line of text, or two lines if
|
||||
/// isThreeLine: true is specified. If isDense: true is specified then the overall
|
||||
/// isThreeLine: true is specified. If dense: true is specified then the overall
|
||||
/// height of this list item and the size of the DefaultTextStyles that wrap
|
||||
/// the [primary] and [secondary] widget are reduced.
|
||||
class ListItem extends StatelessComponent {
|
||||
@@ -22,7 +22,8 @@ class ListItem extends StatelessComponent {
|
||||
this.secondary,
|
||||
this.right,
|
||||
this.isThreeLine: false,
|
||||
this.isDense: false,
|
||||
this.dense: false,
|
||||
this.enabled: true,
|
||||
this.onTap,
|
||||
this.onLongPress
|
||||
}) : super(key: key) {
|
||||
@@ -35,20 +36,26 @@ class ListItem extends StatelessComponent {
|
||||
final Widget secondary;
|
||||
final Widget right;
|
||||
final bool isThreeLine;
|
||||
final bool isDense;
|
||||
final bool dense;
|
||||
final bool enabled;
|
||||
final GestureTapCallback onTap;
|
||||
final GestureLongPressCallback onLongPress;
|
||||
|
||||
TextStyle primaryTextStyle(BuildContext context) {
|
||||
final TextStyle style = Theme.of(context).text.subhead;
|
||||
return isDense ? style.copyWith(fontSize: 13.0) : style;
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final TextStyle style = theme.text.subhead;
|
||||
if (!enabled) {
|
||||
final Color color = theme.disabledColor;
|
||||
return dense ? style.copyWith(fontSize: 13.0, color: color) : style.copyWith(color: color);
|
||||
}
|
||||
return dense ? style.copyWith(fontSize: 13.0) : style;
|
||||
}
|
||||
|
||||
TextStyle secondaryTextStyle(BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final Color color = theme.text.caption.color;
|
||||
final TextStyle style = theme.text.body1;
|
||||
return isDense ? style.copyWith(color: color, fontSize: 12.0) : style.copyWith(color: color);
|
||||
return dense ? style.copyWith(color: color, fontSize: 12.0) : style.copyWith(color: color);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -56,15 +63,15 @@ class ListItem extends StatelessComponent {
|
||||
final bool isOneLine = !isThreeLine && !isTwoLine;
|
||||
double itemHeight;
|
||||
if (isOneLine)
|
||||
itemHeight = isDense ? 48.0 : 56.0;
|
||||
itemHeight = dense ? 48.0 : 56.0;
|
||||
else if (isTwoLine)
|
||||
itemHeight = isDense ? 60.0 : 72.0;
|
||||
itemHeight = dense ? 60.0 : 72.0;
|
||||
else
|
||||
itemHeight = isDense ? 76.0 : 88.0;
|
||||
itemHeight = dense ? 76.0 : 88.0;
|
||||
|
||||
double iconMarginTop = 0.0;
|
||||
if (isThreeLine)
|
||||
iconMarginTop = isDense ? 8.0 : 16.0;
|
||||
iconMarginTop = dense ? 8.0 : 16.0;
|
||||
|
||||
// Overall, the list item is a Row() with these children.
|
||||
final List<Widget> children = <Widget>[];
|
||||
@@ -113,8 +120,8 @@ class ListItem extends StatelessComponent {
|
||||
}
|
||||
|
||||
return new InkWell(
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
onTap: enabled ? onTap : null,
|
||||
onLongPress: enabled ? onLongPress : null,
|
||||
child: new Container(
|
||||
height: itemHeight,
|
||||
padding: const EdgeDims.symmetric(horizontal: 16.0),
|
||||
|
||||
@@ -6,8 +6,12 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'icon.dart';
|
||||
import 'icon_button.dart';
|
||||
import 'icon_theme.dart';
|
||||
import 'icon_theme_data.dart';
|
||||
import 'ink_well.dart';
|
||||
import 'list_item.dart';
|
||||
import 'material.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
@@ -26,22 +30,37 @@ class PopupMenuItem<T> extends StatelessComponent {
|
||||
PopupMenuItem({
|
||||
Key key,
|
||||
this.value,
|
||||
this.disabled: false,
|
||||
this.enabled: true,
|
||||
this.hasDivider: false,
|
||||
this.child
|
||||
}) : super(key: key);
|
||||
|
||||
final T value;
|
||||
final bool disabled;
|
||||
final bool enabled;
|
||||
final bool hasDivider;
|
||||
final Widget child;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
TextStyle style = theme.text.subhead;
|
||||
if (disabled)
|
||||
if (!enabled)
|
||||
style = style.copyWith(color: theme.disabledColor);
|
||||
|
||||
Widget item = new DefaultTextStyle(
|
||||
style: style,
|
||||
child: new Baseline(
|
||||
baseline: _kMenuItemHeight - _kBaselineOffsetFromBottom,
|
||||
child: child
|
||||
)
|
||||
);
|
||||
if (!enabled) {
|
||||
final bool isDark = theme.brightness == ThemeBrightness.dark;
|
||||
item = new IconTheme(
|
||||
data: new IconThemeData(opacity: isDark ? 0.5 : 0.38),
|
||||
child: item
|
||||
);
|
||||
}
|
||||
|
||||
return new MergeSemantics(
|
||||
child: new Container(
|
||||
height: _kMenuItemHeight,
|
||||
@@ -49,18 +68,31 @@ class PopupMenuItem<T> extends StatelessComponent {
|
||||
decoration: !hasDivider ? null : new BoxDecoration(
|
||||
border: new Border(bottom: new BorderSide(color: theme.dividerColor))
|
||||
),
|
||||
child: new DefaultTextStyle(
|
||||
style: style,
|
||||
child: new Baseline(
|
||||
baseline: _kMenuItemHeight - _kBaselineOffsetFromBottom,
|
||||
child: child
|
||||
)
|
||||
)
|
||||
child: item
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
|
||||
CheckedPopupMenuItem({
|
||||
Key key,
|
||||
T value,
|
||||
checked: false,
|
||||
bool enabled: true,
|
||||
Widget child
|
||||
}) : super(
|
||||
key: key,
|
||||
value: value,
|
||||
enabled: enabled,
|
||||
child: new ListItem(
|
||||
enabled: enabled,
|
||||
left: new Icon(icon: checked ? 'action/done' : null),
|
||||
primary: child
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
class _PopupMenu<T> extends StatelessComponent {
|
||||
_PopupMenu({
|
||||
Key key,
|
||||
@@ -80,7 +112,7 @@ class _PopupMenu<T> extends StatelessComponent {
|
||||
parent: route.animation,
|
||||
curve: new Interval(start, end)
|
||||
);
|
||||
final bool disabled = route.items[i].disabled;
|
||||
final bool enabled = route.items[i].enabled;
|
||||
Widget item = route.items[i];
|
||||
if (route.initialValue != null && route.initialValue == route.items[i].value) {
|
||||
item = new Container(
|
||||
@@ -91,7 +123,7 @@ class _PopupMenu<T> extends StatelessComponent {
|
||||
children.add(new FadeTransition(
|
||||
opacity: opacity,
|
||||
child: new InkWell(
|
||||
onTap: disabled ? null : () { Navigator.pop(context, route.items[i].value); },
|
||||
onTap: enabled ? () { Navigator.pop(context, route.items[i].value); } : null,
|
||||
child: item
|
||||
)
|
||||
));
|
||||
@@ -298,7 +330,7 @@ class _PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||
)
|
||||
)
|
||||
.then((T value) {
|
||||
if (config.onSelected != null)
|
||||
if (value != null && config.onSelected != null)
|
||||
config.onSelected(value);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user