Following the last answer here, i am getting error
错误:无法将元素类型"Future"分配给列表类型"Widget"。
Future<Widget> getImage(String path) async {
try {
await rootBundle.load(path);
return Image.asset(path);
} catch (_) {
return SizedBox.shrink();
}
}
我的代码如下所示:
child: Column(
children: <Widget>[
Text('Text 1'),
Text('Show below image if exist'),
getImage('fileName'),
],
如何使用"getImage"返回所需的Widget?
1条答案
按热度按时间eeq64g8w1#
试试Future Builder,即: