Jonatas

improve GetWidget cache

@@ -39,17 +39,21 @@ abstract class GetView<T> extends StatelessWidget { @@ -39,17 +39,21 @@ abstract class GetView<T> extends StatelessWidget {
39 Widget build(BuildContext context); 39 Widget build(BuildContext context);
40 } 40 }
41 41
  42 +class _Wrapper<T> {
  43 + T data;
  44 +}
  45 +
42 abstract class GetWidget<T extends DisposableInterface> 46 abstract class GetWidget<T extends DisposableInterface>
43 extends StatelessWidget { 47 extends StatelessWidget {
44 GetWidget({Key key}) : super(key: key); 48 GetWidget({Key key}) : super(key: key);
45 49
46 - final Set<T> _value = <T>{}; 50 + final _value = _Wrapper<T>();
47 51
48 final String tag = null; 52 final String tag = null;
49 53
50 T get controller { 54 T get controller {
51 - if (_value.isEmpty) _value.add(GetInstance().find<T>(tag: tag));  
52 - return _value.first; 55 + _value.data ??= GetInstance().find<T>(tag: tag);
  56 + return _value.data;
53 } 57 }
54 58
55 @override 59 @override