Jonatas

fix Rx variables out of GetXController memory leak

@@ -43,7 +43,5 @@ class MockClient extends HttpRequestBase { @@ -43,7 +43,5 @@ class MockClient extends HttpRequestBase {
43 } 43 }
44 44
45 @override 45 @override
46 - void close() {  
47 - // TODO: implement close  
48 - } 46 + void close() {}
49 } 47 }
@@ -31,7 +31,7 @@ extension ExtensionSnackbar on GetInterface { @@ -31,7 +31,7 @@ extension ExtensionSnackbar on GetInterface {
31 Color leftBarIndicatorColor, 31 Color leftBarIndicatorColor,
32 List<BoxShadow> boxShadows, 32 List<BoxShadow> boxShadows,
33 Gradient backgroundGradient, 33 Gradient backgroundGradient,
34 - FlatButton mainButton, 34 + Widget mainButton,
35 OnTap onTap, 35 OnTap onTap,
36 Duration duration = const Duration(seconds: 3), 36 Duration duration = const Duration(seconds: 3),
37 bool isDismissible = true, 37 bool isDismissible = true,
@@ -91,8 +91,8 @@ class GetBar<T extends Object> extends StatefulWidget { @@ -91,8 +91,8 @@ class GetBar<T extends Object> extends StatefulWidget {
91 /// An option to animate the icon (if present). Defaults to true. 91 /// An option to animate the icon (if present). Defaults to true.
92 final bool shouldIconPulse; 92 final bool shouldIconPulse;
93 93
94 - /// A [FlatButton] widget if you need an action from the user.  
95 - final FlatButton mainButton; 94 + /// A [TextButton] widget if you need an action from the user.
  95 + final Widget mainButton;
96 96
97 /// A callback that registers the user's click anywhere. 97 /// A callback that registers the user's click anywhere.
98 /// An alternative to [mainButton] 98 /// An alternative to [mainButton]
@@ -659,7 +659,7 @@ Set either a message or messageText"""); @@ -659,7 +659,7 @@ Set either a message or messageText""");
659 ); 659 );
660 } 660 }
661 661
662 - FlatButton _getMainActionButton() { 662 + Widget _getMainActionButton() {
663 return widget.mainButton; 663 return widget.mainButton;
664 } 664 }
665 } 665 }
@@ -116,7 +116,7 @@ mixin RxObjectMixin<T> on NotifyManager<T> { @@ -116,7 +116,7 @@ mixin RxObjectMixin<T> on NotifyManager<T> {
116 /// Closing the subscription will happen automatically when the observer 116 /// Closing the subscription will happen automatically when the observer
117 /// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree. 117 /// Widget ([GetX] or [Obx]) gets unmounted from the Widget tree.
118 void bindStream(Stream<T> stream) { 118 void bindStream(Stream<T> stream) {
119 - _subscriptions.add(stream.listen((va) => value = va)); 119 + _subscriptions[subject].add(stream.listen((va) => value = va));
120 } 120 }
121 } 121 }
122 122
@@ -124,21 +124,19 @@ class RxNotifier<T> = RxInterface<T> with NotifyManager<T>; @@ -124,21 +124,19 @@ class RxNotifier<T> = RxInterface<T> with NotifyManager<T>;
124 124
125 mixin NotifyManager<T> { 125 mixin NotifyManager<T> {
126 GetStream<T> subject = GetStream<T>(); 126 GetStream<T> subject = GetStream<T>();
127 - final _subscriptions = <StreamSubscription>[]; 127 + final _subscriptions = <GetStream, List<StreamSubscription>>{};
128 128
129 bool get canUpdate => _subscriptions.isNotEmpty; 129 bool get canUpdate => _subscriptions.isNotEmpty;
130 130
131 /// This is an internal method. 131 /// This is an internal method.
132 /// Subscribe to changes on the inner stream. 132 /// Subscribe to changes on the inner stream.
133 void addListener(GetStream<T> rxGetx) { 133 void addListener(GetStream<T> rxGetx) {
134 - if (_subscriptions.contains(rxGetx.listen)) {  
135 - return; 134 + if (!_subscriptions.containsKey(rxGetx)) {
  135 + final subs = rxGetx.listen(subject.add);
  136 + final listSubscriptions =
  137 + _subscriptions[rxGetx] ??= <StreamSubscription>[];
  138 + listSubscriptions.add(subs);
136 } 139 }
137 -  
138 - final subs = rxGetx.listen((data) {  
139 - subject.add(data);  
140 - });  
141 - _subscriptions.add(subs);  
142 } 140 }
143 141
144 StreamSubscription<T> listen( 142 StreamSubscription<T> listen(
@@ -152,9 +150,12 @@ mixin NotifyManager<T> { @@ -152,9 +150,12 @@ mixin NotifyManager<T> {
152 150
153 /// Closes the subscriptions for this Rx, releasing the resources. 151 /// Closes the subscriptions for this Rx, releasing the resources.
154 void close() { 152 void close() {
  153 + _subscriptions.forEach((getStream, _subscriptions) {
155 for (final subscription in _subscriptions) { 154 for (final subscription in _subscriptions) {
156 subscription?.cancel(); 155 subscription?.cancel();
157 } 156 }
  157 + });
  158 +
158 _subscriptions.clear(); 159 _subscriptions.clear();
159 subject.close(); 160 subject.close();
160 } 161 }