flutter - ShowModalBottomSheet 在 Flutter 中仅显示一个项目图像
问题描述
我正在尝试showModalBottomSheet
通过使用flutter_bloc
库来获取 api。下面是飞镖代码和示例 api 数据,根据 api 数据,我得到两张图像,但showModalBottomSheet
其中只显示一张图像。它只显示一个的原因是什么。我还注意到,我无法更新文本颜色更改之类的内容showModalBottomSheet
。
主页.dart
TextButton(
onPressed: () {
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(24.0),
topLeft: Radius.circular(24.0))),
context: context,
builder: (_) => TableModalSheet(
id: id,
count: count,
),
);
},
),
TableModalSheet.dart
class TableModalSheet extends StatefulWidget {
final int id;
final int count;
const TableModalSheet({Key? key, required this.id, required this.count})
: super(key: key);
@override
_TableModalSheetState createState() => _TableModalSheetState(id, count)}
class _TableModalSheetState extends State<TableModalSheet> {
late final int id;
late final int count;
late TableBloc tableBloc;
_TableModalSheetState(this.id, this.count);
@override
void initState() {
super.initState();
tableBloc = BlocProvider.of<TableBloc>(context)
..add(LoadTableCapacityEvent(id, count));}
@override
Widget build(BuildContext context) {
return Container(
child: BlocBuilder<TableBloc, TableState>(builder: (context, state) {
if (state is TableLoading) {
return Center(child: PlatformCircularProgressIndicator());
} else if (state is TableLoaded) {
return buildModal(state.data);
} else if (state is TableError) {
return Center(child: Text(state.message));
}
return Container();}),);}
Widget buildModal(List<TablesTables> data) {
return Padding(
padding: const EdgeInsets.only(
left: 10.0, right: 10.0, bottom: 20.0, top: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(''),
Text(
'Select Table',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0),),
GestureDetector(
onTap: () {
Navigator.pop(context);},
child: Text(
'Done',
style: TextStyle(
color: TuxedoColor.redColor, fontWeight: FontWeight.bold),),),],),
Container(
height: MediaQuery.of(context).size.height * 0.175,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 100.0,
width: 100.0,
child: CachedNetworkImage(
imageUrl: data[index].tablePhotos![index]!.image!, //Here it is displaying only one image but i'm expecting to get two images
placeholder: (context, url) =>
Center(child: PlatformCircularProgressIndicator()),
errorWidget: (context, url, error) => Icon(Icons.error),
),);}),)],),);}}
API数据
{
"message": "Tables returend",
"tables": [
{
"table_photos": [
{
"id": "2",
"image": "https://cdn.fakercloud.com/avatars/calebogden_128.jpg",
"createdAt": "2021-09-09T13:45:31.089Z",
"updatedAt": "2021-09-09T13:45:31.089Z",
"tableId": "5"
},
{
"id": "7",
"image": "https://cdn.fakercloud.com/avatars/atanism_128.jpg",
"createdAt": "2021-09-09T13:45:31.089Z",
"updatedAt": "2021-09-09T13:45:31.089Z",
"tableId": "5"
}
}
]
}
解决方案
推荐阅读
- android - 初始屏幕上的微调器不旋转
- c# - C# 性能基准
- typo3 - TYPO3 EXT:powermail :- 提交后显示 Powermail 表单
- java - Firestore 实时更新会出现故障吗?
- hive - 写入 Hive 表时的多个 Parquet 文件(增量)
- spring - 如何使用 Spring 的 WebClient 发送带有自定义标头的删除请求?
- c# - 未知发布者+浏览器下载警告
- html - 两部分导航。一个居中,另一个右对齐
- windows-10 - llvm的windows installer exe代码在哪里
- node.js - 以读取模式输入 gzip 文件的 logstash 文件消耗非常高的内存