【发布时间】:2019-10-29 10:14:18
【问题描述】:
我有以下填充 DropdownButton 的代码,但我在编辑时无法过滤内容。
我需要帮助,因为我无法理解错误以及如何纠正问题以制作过滤器。
我尝试了几个过滤器都没有成功。下面应用的过滤器有以下错误:
断言失败:第 609 行 pos 15: 'items == null || items.isEmpty ||
值 == 空 || items.where ((DropdownMenuItem item) =>
item.value == value) .length == 1 ': 不正确。
这个错误来自下面的过滤器:
if (widget.filialID != 0) {
_select = FilialModel(key: widget.filialID);
}
我找不到问题的解决方案。请帮忙。谢谢。
import 'package:flutter/material.dart';
import 'package:onex_qa/data/database.dart';
import 'package:onex_qa/models/filial_model.dart';
class DropFilialDb extends StatefulWidget {
int filialID;
DropFilialDb({Key key, this.filialID}) : super(key: key);
@override
_DropFilialDbState createState() => _DropFilialDbState();
}
class _DropFilialDbState extends State<DropFilialDb> {
final String _tipo = 'Filial';
FilialModel _select;
final _listDb = DatabaseDb().getAllFilialList();
@override
void initState() {
super.initState();
if (widget.filialID != 0) {
_select = FilialModel(key: widget.filialID);
}
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(4, 0, 2, 0),
child: Theme(
data: Theme.of(context).copyWith(
canvasColor: Theme.of(context).dialogBackgroundColor,
),
child: FutureBuilder<List<FilialModel>>(
future: _listDb,
builder: (BuildContext context,
AsyncSnapshot<List<FilialModel>> snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return DropdownButton<FilialModel>(
items: snapshot.data.map((FilialModel value) {
return new DropdownMenuItem<FilialModel>(
value: value,
child: new Text(value.filial),
);
}).toList(),
style: TextStyle(color: Theme.of(context).primaryColorDark),
elevation: 3,
isExpanded: true,
hint: Text("Selecione ${_tipo}",
style: TextStyle(
color: Theme.of(context).primaryColorDark, fontSize: 17)),
value: _select == null ? null : _select,
onChanged: (FilialModel value) {
if (value == null) {
_select = null;
} else {
setState(() {
_select = value;
widget.filialID = _select.key;
});
}
},
);
},
),
),
);
}
}
【问题讨论】:
-
请告诉我们
FilialModel的实现,因为错误来自那里;否则我们将无法为您提供帮助。
标签: flutter