Line data Source code
1 : import 'dart:async'; 2 : import 'package:flutter/scheduler.dart'; 3 : import 'package:get_core/src/rx/rx_callbacks.dart'; 4 : 5 : abstract class RxInterface<T> { 6 3 : RxInterface([T initial]); 7 : 8 : /// add listener to stream 9 : addListener(Stream<T> rxGetx); 10 : 11 : /// close stream 12 0 : close() { 13 0 : subject?.close(); 14 : } 15 : 16 : StreamController<T> subject; 17 : 18 : /// Convert value on string 19 : // String get string; 20 : 21 : /// Calls [callback] with current value, when the value changes. 22 : StreamSubscription<T> listen(ValueCallback<T> callback); 23 : 24 : /// Maps the changes into a [Stream] of [S] 25 : // Stream<S> map<S>(S mapper(T data)); 26 : } 27 : 28 : class RxController extends DisposableInterface { 29 : @override 30 2 : void onInit() async {} 31 : 32 : @override 33 1 : void onReady() async {} 34 : 35 : @override 36 1 : void onClose() async {} 37 : } 38 : 39 : abstract class DisposableInterface { 40 : /// Called at the exact moment that the widget is allocated in memory. 41 : /// Do not overwrite this method. 42 7 : void onStart() { 43 7 : onInit(); 44 25 : SchedulerBinding.instance?.addPostFrameCallback((_) => onReady()); 45 : } 46 : 47 : /// Called Called immediately after the widget is allocated in memory. 48 0 : void onInit() async {} 49 : 50 : /// Called after rendering the screen. It is the perfect place to enter navigation events, 51 : /// be it snackbar, dialogs, or a new route. 52 0 : void onReady() async {} 53 : 54 : /// Called before the onDelete method. onClose is used to close events 55 : /// before the controller is destroyed, such as closing streams, for example. 56 0 : onClose() async {} 57 : }