Flutter开发进阶之使用工具效率开发
软件开发团队使用Flutter开发的原因通常是因为Flutter开发性能高、效率高、兼容性好、可拓展性高,作为软件PM来说主要考虑的是范围管理、进度管理、成本管理、资源管理、质量管理、风险管理和沟通管理等,可以看到Flutter开发与项目管理完美契合。
在Flutter开发的不断发展中有一条主线就是更完善、更简单,这也是为什么现在状态管理库Getx异军突起的原因,在开发中使用工具去提升开发效率是很重要的,有些人认为使用更简单的工具去提升开发效率会影响自身技术的提升,作为项目管理来说肯定不是这样的,技术的提升是主动性的,而不是被动的去理解。
接下来介绍几种Flutter开发中常用的工具。
一、JsonToDart
JsonToDart
二、intl
dependencies:
flutter:
sdk: flutter
intl: ^0.18.1
flutter_localizations:
sdk: flutter
此时lib中会生成对应文件
还可以添加指定语言
添加对应语言
导入头文件
import 'package:sky_flutter_lib/generated/l10n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
配置代理并使用
Widget build(BuildContext context) {S.load(const Locale("en", "en_US"));return MaterialApp(localizationsDelegates: const [S.delegate,GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate,GlobalCupertinoLocalizations.delegate,],supportedLocales: S.delegate.supportedLocales,home: Scaffold(appBar: AppBar(title: Text(S.current.ok),),body: Center(child: Text('Running on: $_platformVersion\n'),),),);}
三、flutter_gen
配置环境
brew install FlutterGen/tap/fluttergen
dart pub global activate flutter_gen
pubspec.yaml中导入对应库
dependencies:flutter:sdk: flutterflutter_gen: ^5.4.0
dev_dependencies:flutter_test:sdk: flutterflutter_lints: ^2.0.0build_runner: ^2.4.8flutter_gen_runner: ^5.4.0
启动runner
dart run build_runner build
配置文件路径
<?xml version="1.0" encoding="utf-8" ?>
<resources><color name="color_primary">#20212A</color>
</resources>
dev_dependencies:integration_test:sdk: flutterflutter_test:sdk: flutterflutter_gen:colors:inputs:- assets/color/colors.xmloutput: lib/gen/line_length: 80integrations:flutter_svg: trueflare_flutter: truerive: truelottie: trueflutter:uses-material-design: trueassets:- assets/images/fonts:- family: xxxxfonts:- asset: assets/fonts/xxxx-Bold.otfweight: 700- asset: assets/fonts/xxxx-BoldItalic.otfstyle: italicweight: 700- asset: assets/fonts/xxxx-Light.otfweight: 300- asset: assets/fonts/xxxx-LightItalic.otfstyle: italicweight: 300- asset: assets/fonts/xxxx-Regular.otfweight: 400- asset: assets/fonts/xxxx-RegularItalic.otfstyle: italicweight: 400
执行命令生成资源文件
fluttergen -hfluttergen -c {project name}/pubspec.yaml
Assets.images.appIcon.image();
FontFamily.sKSans;
ColorName.colorPrimary;