尝试在gridview.count小部件内添加图像时。图像未加载,并且在控制台中出现错误。
图像放置在本地-资产文件夹
body: center(
child:gridview.count(
crossaxiscount: 3,
childaspectratio: 1.0,
padding: const edgeinsets.all(4.0),
mainaxisspacing: 4.0,
crossaxisspacing: 4.0,
children: <string>[
'spinach_onion_salad.png',
'veggie.png',
].map<widget>((string url) {
return gridtile(
footer: gridtilebar(
title: text(url)
),
child: image.network(url, fit: boxfit.cover)
);
}).tolist(),
),
),
错误:
Error::
Reloaded 0 of 426 libraries in 937ms.
Reloaded 6 of 426 libraries in 1,338ms.
I/flutter (32327): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (32327): The following ArgumentError was thrown resolving an image codec:
I/flutter (32327): Invalid argument(s): No host specified in URI file:///%20eggie.png
I/flutter (32327):
I/flutter (32327): When the exception was thrown, this was the stack:
I/flutter (32327): #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2121:9)
I/flutter (32327): #1 _HttpClient.getUrl (dart:_http/http_impl.dart:2056:48)\
答案 0 :(得分:0)
return Container(
child: Center(
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
children: <String>[
'spinach_onion_salad.png',
'veggie.png',
]
.map<Widget>((String url) => GridTile(
footer: GridTileBar(title: Text(url)),
child: Image.asset(url)))
.toList(),
),
),
);