1.创建文件夹

2.配置pubspec.yaml文件

也可以这样写:
assets: - lib/images/woman.png - lib/images/2.0x/woman.png - lib/images/3.0x/woman.png区别可能是这样更具体,如果
images文件夹中有不必要的图片就不会被配置...
其中2.0x和3.0x是为了适配不同屏幕分别率,其下的图片是外层同名图片的变体(asset variants),根据不同屏幕分别率加载合适的图片,具体参考Flutter文档resolution-aware的详细说明。
遗憾的是asset variants机制只应用于resolution-aware,而没有所谓的theme-aware来支持深色模式切换。官方文档只说以后可能会有其他方面的支持:
Flutter uses asset variants when choosing resolution-appropriate images. In the future, this mechanism might be extended to include variants for different locales or regions, reading directions, and so on.
3.使用
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Center(
child: Image(image: AssetImage('lib/images/woman.png')),
);
}
}