Ошибка указывает, что DropdownButton
виджет требует Material
предка виджета. Это можно исправить, обернув все дерево виджетов в виджет Scaffold
.
Я добавил пример, используя ваш код:
// wrap with a scafffold widget
return Scaffold( // new line
body: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 60,
),
Column(
children: <Widget>[
Container(
height: 5,
),
Container(
margin: EdgeInsets.only(top: 15.0),
child: Column(
children: <Widget>[
Text(
'Select Account',
),
],
)),
],
),
SizedBox(
width: 60,
height: 60,
),
]),
Expanded(
child: Center(
child: _isLoading
? SpinKitFadingCircle(
size: 50.0,
)
: KeyboardAvoider(
duration: Duration(milliseconds: 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(children: <Widget>[]),
Container(),
Column(
children: <Widget>[
Text(
'Select account\n',
),
Theme(
data: Theme.of(context).copyWith(
canvasColor: StateContainer.of(context)
.curTheme
.background,
),
child: DropdownButton(
// this is the drop down button causing error
value: (StateContainer.of(context)
?.bankAccounts
?.values
?.toList() ??
[])
.contains(_selectedAccount)
? _selectedAccount
: (StateContainer.of(context)
?.bankAccounts
?.length ??
0) >
0
? StateContainer.of(context)
?.bankAccounts
?.values
?.first
: null,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
underline: Container(
height: 2,
color: StateContainer.of(context)
.curTheme
.primary,
),
onChanged: (BankAccountDTO newValue) {
setState(() {
_selectedAccount = newValue;
});
},
items: StateContainer.of(context)
?.bankAccounts
?.values
?.map((BankAccountDTO bankAccountDTO) {
return DropdownMenuItem(
value: bankAccountDTO,
child: Text('${bankAccountDTO.type} ' +
'(...${bankAccountDTO.accountNumber.substring(bankAccountDTO.accountNumber.length - 4)}) ' +
'\$${bankAccountDTO.balance.toStringAsFixed(2)}'),
);
})?.toList(),
),
)
],
)
],
),
),
),
),
],
),
);