Unverified Commit 17ddfb1b authored by MH Johnson's avatar MH Johnson Committed by GitHub

make RawChip.selected non-nullable (#37556)

parent aa83b284
......@@ -1285,8 +1285,8 @@ class RawChip extends StatefulWidget
/// The [onPressed] and [onSelected] callbacks must not both be specified at
/// the same time.
///
/// The [label], [isEnabled], and [clipBehavior] arguments must not be null.
/// The [pressElevation] and [elevation] must be null or non-negative.
/// The [label], [isEnabled], [selected], and [clipBehavior] arguments must
/// not be null. The [pressElevation] and [elevation] must be null or non-negative.
/// Typically, [pressElevation] is greater than [elevation].
const RawChip({
Key key,
......@@ -1303,7 +1303,7 @@ class RawChip extends StatefulWidget
this.onSelected,
this.pressElevation,
this.tapEnabled = true,
this.selected,
this.selected = false,
this.showCheckmark = true,
this.isEnabled = true,
this.disabledColor,
......@@ -1319,6 +1319,7 @@ class RawChip extends StatefulWidget
this.avatarBorder = const CircleBorder(),
}) : assert(label != null),
assert(isEnabled != null),
assert(selected != null),
assert(clipBehavior != null),
assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0),
......@@ -1430,7 +1431,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
assert(widget.onSelected == null || widget.onPressed == null);
super.initState();
_updateState(MaterialState.disabled, !widget.isEnabled);
_updateState(MaterialState.selected, widget.selected ?? false);
_updateState(MaterialState.selected, widget.selected);
selectController = AnimationController(
duration: _kSelectDuration,
value: widget.selected == true ? 1.0 : 0.0,
......@@ -1588,7 +1589,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
}
if (oldWidget.selected != widget.selected) {
setState(() {
_updateState(MaterialState.selected, widget.selected ?? false);
_updateState(MaterialState.selected, widget.selected);
if (widget.selected == true) {
selectController.forward();
} else {
......@@ -1655,7 +1656,6 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
final double pressElevation = widget.pressElevation ?? chipTheme.pressElevation ?? _defaultPressElevation;
final Color shadowColor = widget.shadowColor ?? chipTheme.shadowColor ?? _defaultShadowColor;
final Color selectedShadowColor = widget.selectedShadowColor ?? chipTheme.selectedShadowColor ?? _defaultShadowColor;
final bool selected = widget.selected ?? false;
final TextStyle effectiveLabelStyle = widget.labelStyle ?? chipTheme.labelStyle;
final Color resolvedLabelColor = MaterialStateProperty.resolveAs<Color>(effectiveLabelStyle?.color, _states);
......@@ -1665,7 +1665,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
onFocusChange: _handleFocus,
child: Material(
elevation: isTapping ? pressElevation : elevation,
shadowColor: selected ? selectedShadowColor : shadowColor,
shadowColor: widget.selected ? selectedShadowColor : shadowColor,
animationDuration: pressedAnimationDuration,
shape: shape,
clipBehavior: widget.clipBehavior,
......
......@@ -1168,7 +1168,7 @@ void main() {
deleteIcon: deleteIcon,
isEnabled: isSelectable || isPressable,
shape: chipTheme.shape,
selected: isSelectable ? value : null,
selected: isSelectable && value,
label: Text('$value'),
onSelected: isSelectable
? (bool newValue) {
......@@ -1738,6 +1738,20 @@ void main() {
expect(find.byType(InkWell), findsOneWidget);
});
testWidgets('RawChip.selected can not be null', (WidgetTester tester) async {
expect(() async {
MaterialApp(
home: Material(
child: RawChip(
onPressed: () { },
selected: null,
label: const Text('Chip'),
),
),
);
}, throwsAssertionError);
});
testWidgets('Chip uses stateful color for text color in different states', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
......
......@@ -71,7 +71,6 @@ void main() {
backgroundColor: Colors.blue,
);
final ChipThemeData chipTheme = theme.chipTheme;
bool value;
Widget buildChip(ChipThemeData data) {
return MaterialApp(
......@@ -91,8 +90,8 @@ void main() {
avatar: const Placeholder(),
deleteIcon: const Placeholder(),
isEnabled: true,
selected: value,
label: Text('$value'),
selected: false,
label: const Text('Chip'),
onSelected: (bool newValue) { },
onPressed: null,
),
......
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