如何在颤动中使用带有 Bloc 的冷冻包?
Posted
技术标签:
【中文标题】如何在颤动中使用带有 Bloc 的冷冻包?【英文标题】:How to use Freezed package with Bloc in flutter? 【发布时间】:2021-04-08 07:46:29 【问题描述】:我想用冷冻包创建一个简单的块。这是我的集团:
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:presentation/presentation_index.dart';
part 'auth_bloc_event.dart';
part 'auth_bloc_state.dart';
class AuthBlocBloc extends Bloc<AuthEvent, AuthState>
final SignUpBuyerUseCase signUpBuyerUseCase;
AuthBlocBloc(this.signUpBuyerUseCase) : super(AuthState.initial());
@override
Stream<AuthState> mapEventToState(
AuthEvent event,
) async*
yield* event.map();
还有我的活动课:
part of 'auth_bloc.dart';
@freezed
abstract class AuthEvent with _$AuthEvent
const factory AuthEvent.login(String username, String password) = Login;
const factory AuthEvent.signUpBuyer(BuyerEntity entity) = SignUpBuyer;
和状态类:
part of 'auth_bloc.dart';
@freezed
abstract class AuthState with _$AuthState
const factory AuthState.initial() = InitialAuthState;
const factory AuthState.signUpBuyerFail(String error) = SignUpBuyerFail;
const factory AuthState.signUpBuyerSuccess() = SignUpBuyerSuccess;
const factory AuthState.signUpBuyerLoading() = SignUpBuyerLoading;
问题是当我尝试运行时
flutter pub run build_runner watch --deleteonflicting-outputs
什么都没有发生,也没有生成类
【问题讨论】:
【参考方案1】:在 bloc 中,您应该尝试包含冻结的文件。
part 'auth_bloc_event.dart';
part 'auth_bloc_state.dart';
part 'auth_bloc.freezed.dart';
【讨论】:
以上是关于如何在颤动中使用带有 Bloc 的冷冻包?的主要内容,如果未能解决你的问题,请参考以下文章