在树中创建同一块/cubits的多个实例是不是一种坏做法?我创建了一个cubit的实例,并在树中的几个位置使用它,如下所示。 BlocBuilder<BlocA, BlocAState>(
cubit: blocA, // provide the local cubit instance
builder: (context, state) {
// return widget here based on BlocA's state
}
) ..。但是使用此方法,区块的作用域仅限于单个小部件。我在小部件树中使用了3次这种技术(将我的小部件分成不同的类)。
我见过BlocProvider自动处理flutter_bloc包中的块。在将bloc/cubit作用域指定到单个小部件时也是如此吗? BlocBuilder<BlocA, BlocAState>(
cubit: blocA, // provide the local cubit instance
builder: (context, state) {
// return widget here based on BlocA's state
}
) (我似乎在创建我的cubit的多个实例)
我正在尝试从fire store检索数据集合列表,如下所示:
这是我的下面的State类:
abstract class AppStates {}
class AppInitialState extends AppStates {}
class AppGetCategoriesLoadingState extends AppStates {}
class AppGetCategoriesSuccessState extends AppStates {}
class AppGetCategoriesErrorState extends AppStates {
final S
为了在dropdownbutton中显示categoryList,我使用的是Cubit,它工作正常。我的问题:可以使用Cubit来显示selectedCategory吗?而不使用setState?现在,当选择类别时,它不会显示selectedCategory。库比特:
class CategoriesCubit extends Cubit<CategoriesState> {
final DataBase dataBase;
final Category category;
CategoriesCubit(this.dataBase, this.category)
我试图在屏幕上显示当前的蓝牙状态(打开、关闭、加载)。当我初次亮相的时候,一切似乎都是真的。如果我想执行的话,代码就会执行。在UI中仍然没有显示任何内容。使用的flutter_blue软件包。
bluetooth_cubit_dart.
part 'bluetooth_state.dart';
class BluetoothCubit extends Cubit<BluetoothCubitState> {
final FlutterBlue flutterBlue;
late final StreamSubscription bluetoothStrea
我正在尝试使用Cubit进行状态管理,并且我有一个带有@freezed注释的state类。我以前用过肘,以前没有见过这样的问题。在cubit构造函数中,我发出带有超级构造函数的初始状态,BLocBuilder捕获该初始状态。然后,每当我发出一个新的状态,我的肘实际上没有发射。下面是我的代码的样子:
promotion_state.dart
part of 'promotion_cubit.dart';
@freezed
abstract class PromotionState with _$PromotionState {
const factory Promotion
尝试在我的应用程序中创建BlocBuilder时遇到错误:"'ImagePickerCubit‘不符合类型参数'B’的绑定'BlocBase‘。请尝试使用是’BlocBase‘的子类的类型。“ 我正在根据文档实现它,所以我不知道是什么导致了这个错误。 以下是cubit、state和widgets的代码: ImagePickerCubit: part 'image_picker_state.dart';
class ImagePickerCubit extends Cubit {
final ImagePickerRepository _i