【发布时间】:2026-02-17 01:50:01
【问题描述】:
被介绍给 BLoC,我创建了一个简单的类来改变 bool 变量的值:
class SignInBloc {
StreamController<bool> _isLoading = StreamController<bool>();
Stream<bool> get getIsLoading => _isLoading.stream;
set setIsLoading(bool isLoading) => _isLoading.sink.add(isLoading); // Here is my problem (set)
void dispose(){
_isLoading.close();
}
}
当我使用 set 关键字然后在我的 UI 屏幕中调用它时:bloc.setIsLoading(false);
我得到一个例外:
Try correcting the name to the name of an existing method, or defining a method named 'setIsLoading'.
但是当我在 SignInBloc 类中去掉 set 关键字时,它工作正常。我很困惑,使用这个关键字而不是直接声明我的setter不是最好吗?和,
为什么我取下来没有报错?
【问题讨论】: