I tried to get flutter pub get, tried several ways to add the image
My pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/images/
Especific code in main.dart
decoration: new BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/thermo.png'),
fit: BoxFit.fill,
),
color: Color.fromRGBO(78, 144, 30, 1),
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(30.0),
topRight: const Radius.circular(30.0),
bottomLeft: const Radius.circular(30.0),
bottomRight: const Radius.circular(30.0),
)
),
Debug Console
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/thermo.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:225
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:668
#2 AssetBundleImageProvider.load
package:flutter/…/painting/image_provider.dart:651
The hierarchy of folders:
Indentations(spaces) are highly important in pubspec.yaml file. Your issue is related to this. You can fix it like this:
flutter:
uses-material-design: true
assets:
- assets/images/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.