Flutter Assets: Watch
Flutter Assets: Stop Watch
Flutter Assets: Generate
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix:
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix: resource
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix: resource
ignore_comments: true
flutter_assets:
assets_path:
- assets/images/
- assets/msic/
output_path: lib/constants/
filename: assets.dart
field_prefix:
classname: R
class Assets {
Assets._();
/// Assets for loginLogo
/// assets/images/login/logo.png
static const String assetsImagesLoginLogo = "assets/images/login/logo.png";
/// Assets for tabHome
/// assets/images/tab/home.png
static const String assetsImagesTabHome = "assets/images/tab/home.png";
}
import 'constants/assets.dart';
/// example1:
Image.asset(Assets.assetsImagesLoginLogo, height: 30, width: 30),
/// example2:
Image(image: AssetImage(Assets.assetsImagesTabHome,), height: 30, width: 30),
flutter_assets:
assets_path: assets/
output_path: lib/constants/
filename: assets.dart
field_prefix:
classname: R
生成内容 (Generate content)
// ignore_for_file: prefer_single_quotes
class R {
R._();
/// Assets for loginLogo
/// assets/images/login/logo.png
static const String assetsImagesLoginLogo = "assets/images/login/logo.png";
/// Assets for tabHome
/// assets/images/tab/home.png
static const String assetsImagesTabHome = "assets/images/tab/home.png";
}
当通过 flutter create --template=package my_assets_package
来创建资源包时,可能会用到
flutter_assets:
assets_path:
- lib/assets/images/
- lib/assets/msic/
output_path: lib/
filename: assets.dart
field_prefix:
from: libAssets
to:
classname: MyAsset
package_name: my_assets_package
↓
// ignore_for_file: prefer_single_quotes
class MyAsset {
MyAsset._();
/// Assets for images96f775355c06519b
/// packages/my_assets_package/lib/assets/images/雷电将军.jpeg
static const String images96f775355c06519b = "packages/my_assets_package/lib/assets/images/雷电将军.jpeg";
/// Assets for imagesTap
/// packages/my_assets_package/lib/assets/images/tap.webp
static const String imagesTap = "packages/my_assets_package/lib/assets/images/tap.webp";
/// Assets for msicAdc
/// packages/my_assets_package/lib/assets/msic/adc.txt
static const String msicAdc = "packages/my_assets_package/lib/assets/msic/adc.txt";
}
此时引入时,不用每次都添加package字段
import 'package:my_assets_package/assets.dart';
// ....
Image.asset(MyAsset.images96f775355c06519b, height: 50, width: 50)