Flutter vs React Native
全方位对比Google基于Dart的Flutter与Meta基于JavaScript/TypeScript的React Native。2025年哪个跨平台框架更胜一筹?
以最少代码实现编译期安全、快速演进的 provider 架构
强制事件/状态流转的成熟架构,社区规模庞大
没有"错误的选择"——两者都经过验证,且都采用 MIT 许可证。1-5 人的小团队、追求快速迭代时选 Riverpod:样板代码少,代码生成可选,版本发布节奏非常活跃(3.4.3,2026-09-03)。多团队协作、需要可审计事件流的企业级项目选 Bloc:事件/状态分离是强制的,有 BlocObserver,但 flutter_bloc 的最新版本停留在 2025-05-02——需要持续关注。问题不是"哪个更好",而是"你希望多少纪律由外部强制"。
| 分类 | Riverpod | Bloc |
|---|---|---|
| 性能 | 8/10 | 8/10 |
| 学习难易度 | 8/10 | 6/10 |
| 生态系统 | 7/10 | 9/10 |
| 社区 | 7/10 | 9/10 |
| 就业市场 | 7/10 | 7/10 |
| 面向未来 | 8/10 | 7/10 |
// Riverpod - 用户列表(使用代码生成)
// 来源:riverpod.dev 官方文档模式
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'user_list_provider.g.dart';
@riverpod
Future<List<User>> userList(Ref ref, {required int page}) async {
final repository = ref.watch(userRepositoryProvider);
return repository.fetchUsers(page: page);
}
class UserListScreen extends ConsumerWidget {
const UserListScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final usersAsync = ref.watch(userListProvider(page: 1));
return usersAsync.when(
data: (users) => ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) => ListTile(
title: Text(users[index].name),
subtitle: Text(users[index].email),
),
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('错误:$error')),
);
}
}
// 不使用代码生成的经典语法替代方案(官方文档,可选):
final userListClassicProvider =
FutureProvider.autoDispose.family<List<User>, int>((ref, page) async {
final repository = ref.watch(userRepositoryProvider);
return repository.fetchUsers(page: page);
});// Bloc - 用户列表(Event/State + Repository)
// 来源:bloclibrary.dev 官方 Core Concepts 模式
import 'package:flutter_bloc/flutter_bloc.dart';
sealed class UserListEvent {}
class FetchUsers extends UserListEvent {
FetchUsers({required this.page});
final int page;
}
sealed class UserListState {}
class UserListInitial extends UserListState {}
class UserListLoading extends UserListState {}
class UserListLoaded extends UserListState {
UserListLoaded({required this.users});
final List<User> users;
}
class UserListError extends UserListState {
UserListError({required this.message});
final String message;
}
class UserListBloc extends Bloc<UserListEvent, UserListState> {
UserListBloc({required this.repository}) : super(UserListInitial()) {
on<FetchUsers>(_onFetchUsers);
}
final UserRepository repository;
Future<void> _onFetchUsers(
FetchUsers event,
Emitter<UserListState> emit,
) async {
emit(UserListLoading());
try {
final users = await repository.fetchUsers(page: event.page);
emit(UserListLoaded(users: users));
} catch (error) {
emit(UserListError(message: error.toString()));
}
}
}没有"错误的选择"——两者都经过验证,且都采用 MIT 许可证。1-5 人的小团队、追求快速迭代时选 Riverpod:样板代码少,代码生成可选,版本发布节奏非常活跃(3.4.3,2026-09-03)。多团队协作、需要可审计事件流的企业级项目选 Bloc:事件/状态分离是强制的,有 BlocObserver,但 flutter_bloc 的最新版本停留在 2025-05-02——需要持续关注。问题不是"哪个更好",而是"你希望多少纪律由外部强制"。
获取免费咨询没有唯一正确答案。如果你的团队只有 1-5 人、追求快速迭代,并且架构决策可以靠团队内部沟通解决,Riverpod(样板代码少、代码生成可选、无需 BuildContext 即可测试)更合适。如果是多团队协作、需要可审计事件流和严格契约的企业级项目(例如金融科技、医疗等受监管行业),Bloc 通过强制事件/状态分离以及 BlocObserver 的集中式日志记录,提供了更安全的基础。