我正在尝试ChoiceChip
在 Cupertino 应用程序中使用小部件。
我在 GitHub 上找到了这个解决方案https://github.com/flutter/flutter/issues/21872#issuecomment-421508939
CupertinoApp(
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
title: 'Flutter Demo',
home: new MyHomePage(title: 'Flutter Demo Home Page'),
)
这是我的代码
return CupertinoApp(
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
],
home: CupertinoStoreHomePage(),
);
_buildChoiceList() {
List<Widget> choices = List();
widget.reportList.forEach((item) {
choices.add(Container(
child: ChoiceChip(
label: Text(item),
selected: selectedChoice == item,
onSelected: (selected) {
setState(() {
selectedChoice = item;
widget.onChoiceSelected(item);
});
},
),
));
});
return choices;
}
我得到这个错误
════════ 小部件库捕获的异常═════════════════════════════␕══以下断言在构建 ChoiceChip(dirty): No Material 小部件时被抛出。
ChoiceChip 小部件需要一个 Material 小部件祖先。