dependencies:
pkg1:
path: ../../code/pkg1
依賴git包git
dependencies: pkg1: git: url: git://github.com/xxx/pkg1.git
flutter: assets: - assets/my_icon.png - assets/background.png
import 'dart:async' show Future;import 'package:flutter/services.dart' show rootBundle; Future<String> loadAsset() async { return await rootBundle.loadString('assets/config.json');}
Widget build(BuildContext context) { return new DecoratedBox( decoration: new BoxDecoration( image: new DecorationImage( image: new AssetImage('graphics/background.png'), ), ), );}
Widget build(BuildContext context){ return Image.asset('graphics/background.png') }
new AssetImage('icons/heart.png", package:'my_icons')
或github
new Image.asset('icons/heart.png', package: 'my_icons')
flutter:
assets:
- packages/fancy_backgrounds/backgrounds/background1.png
void collectLog(String line){ ... //收集日誌}void reportErrorAndLog(FlutterErrorDetails details){ ... //上報錯誤和日誌邏輯} FlutterErrorDetails makeDetails(Object obj, StackTrace stack){ ...// 構建錯誤信息} void main() { FlutterError.onError = (FlutterErrorDetails details) { reportErrorAndLog(details); }; runZoned( () => runApp(MyApp()), zoneSpecification: ZoneSpecification( print: (Zone self, ZoneDelegate parent, Zone zone, String line) { collectLog(line); // 收集日誌 }, ), onError: (Object obj, StackTrace stack) { var details = makeDetails(obj, stack); reportErrorAndLog(details); }, );}
flutter: fonts: - family: Raleway fonts: - asset: assets/fonts/Raleway-Regular.ttf - asset: assets/fonts/Raleway-Medium.ttf weight: 500 - asset: assets/fonts/Raleway-SemiBold.ttf weight: 600 - family: AbrilFatface fonts: - asset: assets/fonts/abrilfatface/AbrilFatface-Regular.ttf
使用字體json
// 聲明文本樣式const textStyle = const TextStyle( fontFamily: 'Raleway',); // 使用文本樣式var buttonText = const Text( "Use the font for this text", style: textStyle,);
const textStyle = const TextStyle( fontFamily: 'Raleway', package: 'my_package', //指定包名);
lib/fonts/Raleway-Medium.ttf
flutter: fonts: - family: Raleway fonts: - asset: assets/fonts/Raleway-Regular.ttf - asset: packages/my_package/fonts/Raleway-Medium.ttf weight: 500
const textStyle = const TextStyle( fontFamily: 'Raleway',);