Aggressively try to catch misuse of DropDownButton
Fixes https://github.com/flutter/flutter/issues/948. I hope.
This commit is contained in:
parent
fce3a244d3
commit
a87351ad88
@ -209,7 +209,9 @@ class DropDownButton<T> extends StatefulComponent {
|
||||
this.value,
|
||||
this.onChanged,
|
||||
this.elevation: 8
|
||||
}) : super(key: key);
|
||||
}) : super(key: key) {
|
||||
assert(items.where((DropDownMenuItem<T> item) => item.value == value).length == 1);
|
||||
}
|
||||
|
||||
final List<DropDownMenuItem<T>> items;
|
||||
final T value;
|
||||
@ -225,6 +227,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateSelectedIndex();
|
||||
assert(_selectedIndex != null);
|
||||
}
|
||||
|
||||
void didUpdateConfig(DropDownButton<T> oldConfig) {
|
||||
|
@ -433,7 +433,8 @@ class RenderStack extends RenderStackBase {
|
||||
|
||||
/// Implements the same layout algorithm as RenderStack but only paints the child
|
||||
/// specified by index.
|
||||
/// Note: although only one child is displayed, the cost of the layout algorithm is
|
||||
///
|
||||
/// Although only one child is displayed, the cost of the layout algorithm is
|
||||
/// still O(N), like an ordinary stack.
|
||||
class RenderIndexedStack extends RenderStackBase {
|
||||
RenderIndexedStack({
|
||||
@ -443,11 +444,14 @@ class RenderIndexedStack extends RenderStackBase {
|
||||
}) : _index = index, super(
|
||||
children: children,
|
||||
alignment: alignment
|
||||
);
|
||||
) {
|
||||
assert(index != null);
|
||||
}
|
||||
|
||||
int get index => _index;
|
||||
int _index;
|
||||
void set index (int value) {
|
||||
assert(value != null);
|
||||
if (_index != value) {
|
||||
_index = value;
|
||||
markNeedsLayout();
|
||||
|
@ -962,7 +962,9 @@ class IndexedStack extends MultiChildRenderObjectWidget {
|
||||
Key key,
|
||||
this.alignment: const FractionalOffset(0.0, 0.0),
|
||||
this.index: 0
|
||||
}) : super(key: key, children: children);
|
||||
}) : super(key: key, children: children) {
|
||||
assert(index != null);
|
||||
}
|
||||
|
||||
/// The index of the child to show.
|
||||
final int index;
|
||||
|
Loading…
x
Reference in New Issue
Block a user