Commit 1d39db69 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #950 from Hixie/dropdown-asserts

Aggressively try to catch misuse of DropDownButton
parents b378d967 a87351ad
......@@ -227,7 +227,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;
......@@ -243,6 +245,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;
......
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