方式1:使用Container中的DecorationImage,代碼如下
return Scaffold( body: Center( child: Container( width: 300, height: 300, decoration: BoxDecoration( color: Colors.green, borderRadius: BorderRadius.circular(150), // 圓形圖片 image: DecorationImage( image: NetworkImage('https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1067487824,1623759373&fm=26&gp=0.jpg'), fit: BoxFit.cover ) ), ), ), );
方式2:使用ClipOval,代碼如下:
return Center( child: Container( // 圓形圖片 child: ClipOval( child: Image.asset('images/a.jpg', height: 100, width: 100, fit: BoxFit.cover, ), ), ) );
flutter中使用本地圖片:步驟
(1)新建文件夾,如圖所示:
需將圖片文件放到不同目錄下;
(2)在pubspec.yml中聲明:
效果如下: