Flutter Bloc模式中两个活动之间的实时数据更改

时间:2018-11-18 14:00:57

标签: dart flutter

我有两个活动。

活动1 ------>文字

活动2 ------>增量按钮

当用户单击活动2 按钮时,在活动1 中,文本字段将像计数器一样递增。

我当前的Bloc类:

class IncrementBloc implements BlocBase {

int _counter;
StreamController<int> _counterController = StreamController<int>();
Sink<int> get _inAdd => _counterController.sink;
Stream<int> get outCounter => _counterController.stream;


StreamController _actionController = StreamController();
Sink get incrementCounter => _actionController.sink;


IncrementBloc(){
  _counter = 0;
  _actionController.stream.listen(_handleLogic);
}




@override
void dispose() {
  _actionController.close();
  _counterController.close();
}

void _handleLogic(data){
  print("hello");
  _counter = _counter + 1;
  _inAdd.add(_counter);
}

}

如何使用此bloc类实现我的功能?

0 个答案:

没有答案