我想使用资产中的图像作为图标,然后构建列表,但是当尝试将Image.asset
作为类添加到图标作为IconData
数据类型的变量而不是使用图标作为图标时,会发生一些错误班级。
有办法解决这个问题吗?
谢谢。
class Menu {
const Menu({this.icon, this.title});
final IconData icon;
final String title;
}
const List<Menu> menus = const <Menu>[
const Menu(title: 'menu_icon_1', icon: Image.asset('assets/menu/1-1.png')),
],
Run Code Online (Sandbox Code Playgroud)
error: The argument type 'Image' can't be assigned to the parameter type 'IconData'. (argument_type_not_assignable at [sinergi] lib\home.dart:12)
Run Code Online (Sandbox Code Playgroud) 当我在 ConstrainedBox 中放置 ListTile 的前导时,我遇到了图像大小问题,图像太小并且无法填充到更大的尺寸,有什么想法可以使该图像大小可以遵循 Card 的高度吗?
谢谢。
ListTile(
leading: ConstrainedBox(
constraints:
BoxConstraints(minWidth: 100, minHeight: 100),
child: Image.network(
'http://www.malmalioboro.co.id/$gambar',
width: 100,
height: 100,
)),
title: Text(
nama,
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold),
),
subtitle: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(
'Barcode : ',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
deskripsi,
style: TextStyle(fontSize: 15.0),
),
],
),
Row(
children: <Widget>[
Text(
'Harga : ',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20),
),
Text(
harga,
style: TextStyle(fontSize: 20),
)
],
),
], …
Run Code Online (Sandbox Code Playgroud) 我有一个清单:
List user = [
{"name": "Alex", "id": "001"},
{"name": "Brandon", "id": "002"},
{"name": "Charlie", "id": "003"},
{"name": "Danny", "id": "004"},
];
Run Code Online (Sandbox Code Playgroud)
我有一个有价值的变量
String a = "002";
int index;
Run Code Online (Sandbox Code Playgroud)
user
我的问题是,当我通过传递值进行搜索时,如何从列表中获取索引值a
?
所以我会有一个index = 1
谢谢 :)
我在 main.dart 文件上使用最新的 Flutter v 1.17.1 和 Dart 2.8.2 版本时收到此错误消息,
'onError' 已弃用,不应使用。请改用 runZonedGuarded。尝试使用替换来替换已弃用成员的使用。
这是代码,
runZoned<Future<Null>>(() async {
runApp(MyApp());
}, onError: (error, stackTrace) async {
await FlutterCrashlytics().reportCrash(error, stackTrace, forceCrash: false);
});
}
Run Code Online (Sandbox Code Playgroud)
有什么解决方案可以消除此错误消息?