rx_interface.dart
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'dart:async';
import 'package:flutter/scheduler.dart';
import 'package:get/src/rx/rx_callbacks.dart';
abstract class RxInterface<T> {
  RxInterface([T initial]);
  /// add listener to stream
  addListener(Stream<T> rxGetx);
  bool get canUpdate;
  /// close stream
  close() {
    subject?.close();
  }
  StreamController<T> subject;
  /// Calls [callback] with current value, when the value changes.
  StreamSubscription<T> listen(ValueCallback<T> callback);
}
abstract class DisposableInterface {
  /// Called at the exact moment that the widget is allocated in memory.
  /// Do not overwrite this method.
  void onStart() {
    onInit();
    SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
  }
  /// Called Called immediately after the widget is allocated in memory.
  void onInit() async {}
  /// Called after rendering the screen. It is the perfect place to enter navigation events,
  /// be it snackbar, dialogs, or a new route.
  void onReady() async {}
  /// Called before the onDelete method. onClose is used to close events
  /// before the controller is destroyed, such as closing streams, for example.
  onClose() async {}
}