首页 > 大数据 > 数据分析 > 对于 Flutter 快速开发框架的思考
要打造一个 Flutter的快速开发框架,首先要思考的事情是一个快速开发框架需要照顾到哪些功能点,经过2天的思考,我大致整理了一下需要的能力:
那么,基于上面的分析,我就开始做了一些选型,这里基本上就是按照官方Flutter Favorites ,里面推荐的来选了。因为这些建议的库都是目前Flutter社区中比较流行和受欢迎的,能够提供稳定和高效的开发体验。

@riverpod
Future<String> boredSuggestion(BoredSuggestionRef ref) async {
final response = await http.get(
Uri.https('https://boredapi.com/api/activity'),
);
final json = jsonDecode(response.body);
return json['activity']! as String;}class Home extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final boredSuggestion = ref.watch(boredSuggestionProvider);
// Perform a switch-case on the result to handle loading/error states
return boredSuggestion.when(
loading: () => Text('loading'),
error: (error, stackTrace) => Text('error: $error'),
data: (data) => Text(data),
);
}}
final rs = await dio.get( url, options: Options(responseType: ResponseType.stream), // Set the response type to `stream`.);print(rs.data.stream); // Response stream.
'/protected-route': (route) =>
canUserAccessPage()
? MaterialPage(child: ProtectedPage())
: Redirect('/no-access'),

var box = Hive.box('myBox');box.put('name', 'David');var name = box.get('name');print('Name: $name');
final getIt = GetIt.instance;void setup() {
getIt.registerSingleton<AppModel>(AppModel());// Alternatively you could write it if you don't like global variables
GetIt.I.registerSingleton<AppModel>(AppModel());}MaterialButton(
child: Text("Update"),
onPressed: getIt<AppModel>().update // given that your AppModel has a method update),
CI/CD集成通常涉及外部服务,如 GitHub Actions、Codemagic等,而非Flutter库。
前面已经做完了选型,下来我们可以确立一下我们快速开发框架的目录结构,我们给框架取名为fdflutter,顾名思义,就是fast development flutter,如下:
fdflutter/├── lib/│ ├── core/│ │ ├── api/│ │ │ └── api_service.dart │ │ ├── di/│ │ │ └── injection_container.dart │ │ ├── localization/│ │ │ └── localization_service.dart │ │ ├── routing/│ │ │ └── router.dart │ │ └── utils/│ │ └── logger.dart │ ├── data/│ │ ├── datasources/│ │ │ ├── local_datasource.dart │ │ │ └── remote_datasource.dart │ │ └── repositories/│ │ └── example_repository.dart │ ├── domain/│ │ ├── entities/│ │ │ └── example_entity.dart │ │ └── usecases/│ │ └── get_example_data.dart │ ├── presentation/│ │ ├── pages/│ │ │ └── example_page.dart │ │ └── providers/│ │ └── example_provider.dart │ └── main.dart ├── test/│ ├── data/│ ├── domain/│ └── presentation/├── pubspec.yaml └── README.md
在这个结构中,我保持了核心功能、数据层、领域层和表示层的划分:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70030722/viewspace-3008067/ ,如需转载,请注明出处,否则将追究法律责任。