如何将基于流的小部件更改为 GetX 小部件

时间:2021-04-02 05:52:12

标签: flutter dart stream provider getx

嗨,我正在尝试使用 GetX Package 实现秒表小部件。

我引用了 pub.dev 中的 stop_watch_timer 包。

以下是我的实现源码和stop_watch_timer包的源码。

我的实现:

var _elapsedTime = 0.obs;
  var _rawTimeController = 0.obs;
  var _secondTimeController = 0.obs;
  var _minuteTimeController = 0.obs;
  var _recordsController = <StopWatchRecord>[].obs;

  int get rawTime => _rawTimeController.value;
  int get secondTime => _secondTimeController.value;
  int get minuteTime => _minuteTimeController.value;
  List<StopWatchRecord> get records => _recordsController;

参考:

  final PublishSubject<int> _elapsedTime = PublishSubject<int>();

  final BehaviorSubject<int> _rawTimeController =
      BehaviorSubject<int>.seeded(0);
  ValueStream<int> get rawTime => _rawTimeController;

  final BehaviorSubject<int> _secondTimeController =
      BehaviorSubject<int>.seeded(0);
  ValueStream<int> get secondTime => _secondTimeController;

  final BehaviorSubject<int> _minuteTimeController =
      BehaviorSubject<int>.seeded(0);
  ValueStream<int> get minuteTime => _minuteTimeController;

  final BehaviorSubject<List<StopWatchRecord>> _recordsController =
      BehaviorSubject<List<StopWatchRecord>>.seeded([]);
  ValueStream<List<StopWatchRecord>> get records => _recordsController;

我不太确定我是否做得对。

任何帮助将不胜感激。谢谢!

0 个答案:

没有答案