assets: - assets/images/1.jpgAssetImage会自动根据不通分辨率去找合适的图片。
ExactAssetImage可以对图片进行缩放,scale数值越小,放的越大,1为原图大小,下面是具体用法
除了AssetImage外,还可以用Image.asset来加载本地图片。下面是具体的代码:
class MyApp extends StatelessWidget { const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'AssetImage资源图片', home: Scaffold( appBar: AppBar( title: Text('AssetImage资源图片'), ), body: Column( children: [ SizedBox( width: 200.0, height: 200.0, child: CircleAvatar( backgroundImage: AssetImage('assets/images/1.jpg'), ), ), Container( child: Image( width: 200.0, height: 200.0, image: AssetImage('assets/images/1.jpg') ), ), Image( image: ExactAssetImage('assets/images/1.jpg', scale: .5), ), Image.asset('assets/images/1.jpg',fit: BoxFit.cover,) ], ), ), ); } }