I have following code.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SimpleScreen());
}
}
class SimpleScreen extends StatefulWidget {
@override
_SimpleScreenState createState() => _SimpleScreenState();
}
class _SimpleScreenState extends State<SimpleScreen> {
ItemCls currentValue = ItemCls(name: 'one', price: 1);
List<DropdownMenuItem> _menuItems = <DropdownMenuItem>[
DropdownMenuItem(
child: new Container(
child: new Text("Item#1"),
width: 200.0,
),
value: ItemCls(name: 'one', price: 1)),
DropdownMenuItem(
child: new Container(
child: new Text("Item#2"),
width: 200.0,
),
value: ItemCls(name: 'two', price: 2))
];
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Center(
child: DropdownButton(
value: currentValue,
items: _menuItems,
onChanged: onChanged,
style: Theme.of(context).textTheme.title,
),
));
}
void onChanged(value) {
setState(() {
currentValue = value;
});
// print(value);
}
}
class ItemCls {
final String name;
final double price;
const ItemCls({
@required this.name,
@required this.price,
}) : assert(name != null),
assert(price != null);
}
That fails with
The following assertion was thrown building SimpleScreen(dirty, dependencies: [_LocalizationsScope-[GlobalKey#b1ff3], _InheritedTheme], state: _SimpleScreenState#d473f): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 620 pos 15: 'items == null || items.isEmpty || value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1': is not true.