Commit a87351ad authored by Hixie's avatar Hixie

Aggressively try to catch misuse of DropDownButton

Fixes https://github.com/flutter/flutter/issues/948.
I hope.
parent fce3a244
...@@ -209,7 +209,9 @@ class DropDownButton<T> extends StatefulComponent { ...@@ -209,7 +209,9 @@ class DropDownButton<T> extends StatefulComponent {
this.value, this.value,
this.onChanged, this.onChanged,
this.elevation: 8 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 List<DropDownMenuItem<T>> items;
final T value; final T value;
...@@ -225,6 +227,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> { ...@@ -225,6 +227,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
void initState() { void initState() {
super.initState(); super.initState();
_updateSelectedIndex(); _updateSelectedIndex();
assert(_selectedIndex != null);
} }
void didUpdateConfig(DropDownButton<T> oldConfig) { void didUpdateConfig(DropDownButton<T> oldConfig) {
......
...@@ -433,7 +433,8 @@ class RenderStack extends RenderStackBase { ...@@ -433,7 +433,8 @@ class RenderStack extends RenderStackBase {
/// Implements the same layout algorithm as RenderStack but only paints the child /// Implements the same layout algorithm as RenderStack but only paints the child
/// specified by index. /// 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. /// still O(N), like an ordinary stack.
class RenderIndexedStack extends RenderStackBase { class RenderIndexedStack extends RenderStackBase {
RenderIndexedStack({ RenderIndexedStack({
...@@ -443,11 +444,14 @@ class RenderIndexedStack extends RenderStackBase { ...@@ -443,11 +444,14 @@ class RenderIndexedStack extends RenderStackBase {
}) : _index = index, super( }) : _index = index, super(
children: children, children: children,
alignment: alignment alignment: alignment
); ) {
assert(index != null);
}
int get index => _index; int get index => _index;
int _index; int _index;
void set index (int value) { void set index (int value) {
assert(value != null);
if (_index != value) { if (_index != value) {
_index = value; _index = value;
markNeedsLayout(); markNeedsLayout();
......
...@@ -962,7 +962,9 @@ class IndexedStack extends MultiChildRenderObjectWidget { ...@@ -962,7 +962,9 @@ class IndexedStack extends MultiChildRenderObjectWidget {
Key key, Key key,
this.alignment: const FractionalOffset(0.0, 0.0), this.alignment: const FractionalOffset(0.0, 0.0),
this.index: 0 this.index: 0
}) : super(key: key, children: children); }) : super(key: key, children: children) {
assert(index != null);
}
/// The index of the child to show. /// The index of the child to show.
final int index; final int index;
......
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