From 8d84630d3c60ed853fe13bd97c54265a75238c96 Mon Sep 17 00:00:00 2001 From: Jonatas Date: Mon, 10 Aug 2020 06:06:36 -0300 Subject: [PATCH] update to 3.4.4 --- CHANGELOG.md | 3 + README.md | 19 +++-- benchmark/state_managers/pubspec.lock | 12 +-- example/lib/home/bindings/home_binding.dart | 14 ++-- .../lib/home/controllers/home_controller.dart | 6 +- example/lib/home/data/home_provider.dart | 35 ++++++++- example/lib/home/data/home_repository.dart | 8 +- example/pubspec.lock | 20 ++--- lib/route_manager.dart | 2 +- lib/src/{ => core}/get_interface.dart | 12 +-- lib/src/{ => core}/get_main.dart | 2 +- lib/src/instance/extension_instance.dart | 2 +- lib/src/instance/get_instance.dart | 74 +++++++++---------- lib/src/navigation/extension_navigation.dart | 2 +- lib/src/navigation/root/root_widget.dart | 8 +- lib/src/navigation/root/smart_management.dart | 1 - lib/src/navigation/route_manager.dart | 2 +- lib/src/navigation/routes/default_route.dart | 2 +- lib/src/state_manager/rx/rx_impl.dart | 40 +++++----- lib/src/state_manager/rx/rx_interface.dart | 7 +- pubspec.yaml | 2 +- 21 files changed, 153 insertions(+), 120 deletions(-) rename lib/src/{ => core}/get_interface.dart (80%) rename lib/src/{ => core}/get_main.dart (90%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 686006f7d..59bc11f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.4.4] +- Fix exception 'isInit called null' when tags are used in conjunction with dependencies. (@djade007) + ## [3.4.3] - Fix onInit fired only first time - Fix language callback(@lundin) diff --git a/README.md b/README.md index 88303a8d4..0a8a7d8c6 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,20 @@ # About Get - GetX is an extra-light and powerful solution for Flutter. It combines high performance state management, intelligent dependency injection, and route management in a quick and practical way. -- GetX is not for everyone, its focus is (performance) on the minimum consumption of resources ([look the benchmarks](https://github.com/jonataslaw/benchmarks)), (productivity) using an easy and pleasant syntax and (organization) allowing the total decoupling of the View from the business logic. -- GetX will save hours of development, and will extract the maximum performance that your application can deliver, being easy for beginners, and accurate for experts. -- Navigate without `context`, open `dialogs`, `snackbars` or `bottomsheets` from anywhere in your code, Manage states and inject dependencies in an easy and practical way. -- Get is secure, stable, up-to-date, and offers a huge range of APIs that are not present on default framework. -- GetX is not `bloated`. It has a multitude of features that allow you to start programming without worrying about anything, but each of these features are in separate containers, and are only started after use. If you only use State Management, only State Management will be compiled. If you only use routes, nothing from the state management will be compiled. You can compile the benchmark repository, and you will see that using only Get state management, the application compiled with Get has become smaller than all other applications that have only the state management of other packages, because nothing that is not used will be compiled into your code, and each GetX solution was designed to be extra lightweight. The merit here also comes from Flutter's AOT which is incredible, and manages to eliminate unused resources like no other framework does. -**GetX makes your development productive, but want to make it even more productive? Add the extension [GetX extension](https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets) to your VSCode**. Not available in other IDEs for now. + +- GetX has 3 basic principles, this means that this is the priority for all resources in the library +**PERFORMANCE:** GetX is focused on performance and minimum consumption of resources. Benchmarks are almost always not important in the real world, but if you want, there is a consumption indicator here([benchmarks](https://github.com/jonataslaw/benchmarks)), where GetX does better than other state management approaches, for example. The difference is not large, but it shows our concern not to waste its resources. +**PRODUCTIVITY:** GetX uses an easy and pleasant syntax. +**ORGANIZATION:** GetX allows total decoupling of the View from the business logic. + + +- GetX will save hours of development, and will extract the maximum performance that your application can deliver, being easy for beginners, and accurate for experts. Navigate without context, open dialogs, snackbars or bottomsheets from anywhere in your code, Manage states and inject dependencies in an easy and practical way. Get is secure, stable, up-to-date, and offers a huge range of APIs that are not present on default framework. + + +- GetX is not a bloated. It has a multitude of features that allow you to start programming without worrying about anything, but each of these features are in separate containers, and are only started after use. If you only use State Management, only State Management will be compiled. If you only use routes, nothing from the state management will be compiled. You can compile the benchmark repository, and you will see that using only Get state management, the application compiled with Get has become smaller than all other applications that have only the state management of other packages, because nothing that is not used will be compiled into your code, and each GetX solution was designed to be extra lightweight. The merit here also comes from Flutter's tree shaking which is incredible, and manages to eliminate unused resources like no other framework does. + +**GetX makes your development productive, but want to make it even more productive? Add the extension [GetX extension to VSCode](https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets) to your VSCode** # Installing diff --git a/benchmark/state_managers/pubspec.lock b/benchmark/state_managers/pubspec.lock index 1f4bdad1d..dacaae903 100644 --- a/benchmark/state_managers/pubspec.lock +++ b/benchmark/state_managers/pubspec.lock @@ -105,7 +105,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0-nullsafety" charcode: dependency: transitive description: @@ -140,7 +140,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0-nullsafety" convert: dependency: transitive description: @@ -311,7 +311,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety" mime: dependency: transitive description: @@ -512,7 +512,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0-nullsafety" uuid: dependency: "direct main" description: @@ -526,7 +526,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety" watcher: dependency: transitive description: @@ -549,5 +549,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.9.0-18.0 <2.9.0" flutter: ">=1.16.0" diff --git a/example/lib/home/bindings/home_binding.dart b/example/lib/home/bindings/home_binding.dart index a0a81b544..744b9de8c 100644 --- a/example/lib/home/bindings/home_binding.dart +++ b/example/lib/home/bindings/home_binding.dart @@ -1,15 +1,17 @@ +import 'package:dio/dio.dart'; import 'package:get/get.dart'; -import 'package:get_state/home/controllers/home_controller.dart'; -import 'package:get_state/home/data/home_provider.dart'; -import 'package:get_state/home/data/home_repository.dart'; +import '../controllers/home_controller.dart'; +import '../data/home_provider.dart'; +import '../data/home_repository.dart'; class HomeBinding extends Bindings { @override void dependencies() { Get.lazyPut(() { - final homeProvider = HomeProvider(); - final homeRepository = HomeRepository(homeProvider); - return HomeController(homeRepository); + Get.put(Dio()); + Get.put(HomeProvider(dio: Get.find())); + Get.put(HomeRepository(homeProvider: Get.find())); + return HomeController(homeRepository: Get.find()); }); } } diff --git a/example/lib/home/controllers/home_controller.dart b/example/lib/home/controllers/home_controller.dart index f69486266..ca40c9161 100644 --- a/example/lib/home/controllers/home_controller.dart +++ b/example/lib/home/controllers/home_controller.dart @@ -1,9 +1,9 @@ import 'package:get/get.dart'; -import 'package:get_state/home/data/home_model.dart'; -import 'package:get_state/home/data/home_repository.dart'; +import '../data/home_model.dart'; +import '../data/home_repository.dart'; class HomeController extends GetxController { - HomeController(this.homeRepository); + HomeController({this.homeRepository}); final HomeRepository homeRepository; Rx data = Rx(); diff --git a/example/lib/home/data/home_provider.dart b/example/lib/home/data/home_provider.dart index e19904da7..818aea8b1 100644 --- a/example/lib/home/data/home_provider.dart +++ b/example/lib/home/data/home_provider.dart @@ -1,14 +1,41 @@ import 'package:dio/dio.dart'; -import 'package:get_state/home/data/home_model.dart'; +import 'package:flutter/foundation.dart'; +import 'home_model.dart'; -class HomeProvider { - Future fetchData() async { +abstract class IHomeProvider { + Future get(); + Future post(Map data); + Future put(Map data); + Future delete(int id); +} + +class HomeProvider implements IHomeProvider { + final Dio dio; + + HomeProvider({@required this.dio}); + + Future get() async { try { - final response = await Dio().get("https://api.covid19api.com/summary"); + final response = await dio.get("https://api.covid19api.com/summary"); return ApiModel.fromJson(response.data); } catch (e) { print(e.toString()); return null; } } + + @override + Future post(Map data) { + throw UnimplementedError(); + } + + @override + Future put(Map data) { + throw UnimplementedError(); + } + + @override + Future delete(int id) { + throw UnimplementedError(); + } } diff --git a/example/lib/home/data/home_repository.dart b/example/lib/home/data/home_repository.dart index 939e7ccfb..4cdb16187 100644 --- a/example/lib/home/data/home_repository.dart +++ b/example/lib/home/data/home_repository.dart @@ -1,11 +1,11 @@ -import 'package:get_state/home/data/home_provider.dart'; -import 'package:get_state/home/data/home_model.dart'; +import 'home_model.dart'; +import 'home_provider.dart'; class HomeRepository { - HomeRepository(this.homeProvider); + HomeRepository({this.homeProvider}); final HomeProvider homeProvider; Future getData() async { - return homeProvider.fetchData(); + return homeProvider.get(); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index c8d0c8ab8..11968b9d6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.4.2" boolean_selector: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0-nullsafety" charcode: dependency: transitive description: @@ -42,14 +42,14 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0-nullsafety" dio: dependency: "direct main" description: name: dio url: "https://pub.dartlang.org" source: hosted - version: "3.0.9" + version: "3.0.10" fake_async: dependency: transitive description: @@ -73,7 +73,7 @@ packages: name: get url: "https://pub.dartlang.org" source: hosted - version: "3.2.2" + version: "3.4.3" http_parser: dependency: transitive description: @@ -94,7 +94,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety" path: dependency: transitive description: @@ -120,7 +120,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.9.5" stream_channel: dependency: transitive description: @@ -155,13 +155,13 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0-nullsafety" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.9.0-18.0 <2.9.0" diff --git a/lib/route_manager.dart b/lib/route_manager.dart index a4ea1ccd1..582dd4083 100644 --- a/lib/route_manager.dart +++ b/lib/route_manager.dart @@ -7,7 +7,7 @@ export 'src/navigation/root/root_widget.dart'; export 'src/navigation/snackbar/snack_route.dart'; export 'src/navigation/bottomsheet/bottomsheet.dart'; export 'src/navigation/snackbar/snack.dart'; -export 'src/get_main.dart'; +export 'src/core/get_main.dart'; export 'src/navigation/routes/default_route.dart'; export 'src/navigation/root/smart_management.dart'; export 'src/navigation/extension_navigation.dart'; diff --git a/lib/src/get_interface.dart b/lib/src/core/get_interface.dart similarity index 80% rename from lib/src/get_interface.dart rename to lib/src/core/get_interface.dart index ea83d872f..592a1d2d8 100644 --- a/lib/src/get_interface.dart +++ b/lib/src/core/get_interface.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -import 'navigation/root/parse_route.dart'; -import 'navigation/root/root_controller.dart'; -import 'navigation/routes/custom_transition.dart'; -import 'navigation/routes/observers/route_observer.dart'; -import 'navigation/routes/transitions_type.dart'; -import '../utils.dart'; +import '../navigation/root/parse_route.dart'; +import '../navigation/root/root_controller.dart'; +import '../navigation/routes/custom_transition.dart'; +import '../navigation/routes/observers/route_observer.dart'; +import '../navigation/routes/transitions_type.dart'; +import '../../utils.dart'; ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" diff --git a/lib/src/get_main.dart b/lib/src/core/get_main.dart similarity index 90% rename from lib/src/get_main.dart rename to lib/src/core/get_main.dart index c63afdca7..61eaee185 100644 --- a/lib/src/get_main.dart +++ b/lib/src/core/get_main.dart @@ -1,4 +1,4 @@ -import 'package:get/src/get_interface.dart'; +import 'package:get/src/core/get_interface.dart'; ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, ///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" diff --git a/lib/src/instance/extension_instance.dart b/lib/src/instance/extension_instance.dart index 1d70cda2b..16a517286 100644 --- a/lib/src/instance/extension_instance.dart +++ b/lib/src/instance/extension_instance.dart @@ -1,4 +1,4 @@ -import 'package:get/src/get_interface.dart'; +import 'package:get/src/core/get_interface.dart'; import 'get_instance.dart'; extension Inst on GetInterface { diff --git a/lib/src/instance/get_instance.dart b/lib/src/instance/get_instance.dart index f28b74e93..739c7ef5d 100644 --- a/lib/src/instance/get_instance.dart +++ b/lib/src/instance/get_instance.dart @@ -2,10 +2,6 @@ import 'package:get/src/navigation/root/smart_management.dart'; import 'package:get/src/state_manager/rx/rx_interface.dart'; class GetConfig { - //////////// INSTANCE MANAGER - static Map _singl = {}; - static Map _factory = {}; - static Map routesKey = {}; static SmartManagement smartManagement = SmartManagement.full; static bool isLogEnable = true; static String currentRoute; @@ -25,10 +21,14 @@ class GetInstance { const GetInstance._(); static GetInstance _getInstance; + static Map _singl = {}; + static Map _factory = {}; + static Map _routesKey = {}; + void lazyPut(FcBuilderFunc builder, {String tag, bool fenix = false}) { String key = _getKey(S, tag); - GetConfig._factory.putIfAbsent(key, () => Lazy(builder, fenix)); + _factory.putIfAbsent(key, () => Lazy(builder, fenix)); } Future putAsync(FcBuilderFuncAsync builder, @@ -75,14 +75,13 @@ class GetInstance { assert(builder != null); String key = _getKey(S, name); - GetConfig._singl.putIfAbsent( + _singl.putIfAbsent( key, () => FcBuilder(isSingleton, builder, permanent, false)); } Future removeDependencyByRoute(String routeName) async { List keysToRemove = []; - GetConfig.routesKey.forEach((key, value) { - // if (value == routeName && value != null) { + _routesKey.forEach((key, value) { if (value == routeName) { keysToRemove.add(key); } @@ -92,17 +91,17 @@ class GetInstance { await delete(key: element); }); keysToRemove.forEach((element) { - GetConfig.routesKey?.remove(element); + _routesKey?.remove(element); }); keysToRemove.clear(); } bool initDependencies({String name}) { String key = _getKey(S, name); - bool isInit = GetConfig._singl[key].isInit; + bool isInit = _singl[key].isInit; if (!isInit) { startController(tag: name); - GetConfig._singl[key].isInit = true; + _singl[key].isInit = true; if (GetConfig.smartManagement != SmartManagement.onlyBuilder) { registerRouteInstance(tag: name); } @@ -111,18 +110,17 @@ class GetInstance { } void registerRouteInstance({String tag}) { - GetConfig.routesKey - .putIfAbsent(_getKey(S, tag), () => GetConfig.currentRoute); + _routesKey.putIfAbsent(_getKey(S, tag), () => GetConfig.currentRoute); } S findByType(Type type, {String tag}) { String key = _getKey(type, tag); - return GetConfig._singl[key].getDependency() as S; + return _singl[key].getDependency() as S; } void startController({String tag}) { String key = _getKey(S, tag); - final i = GetConfig._singl[key].getDependency(); + final i = _singl[key].getDependency(); if (i is DisposableInterface) { i.onStart(); @@ -133,15 +131,15 @@ class GetInstance { // S putOrFind(S Function() dep, {String tag}) { // final key = _getKey(S, tag); - // if (GetConfig._singl.containsKey(key)) { - // return GetConfig._singl[key].getDependency() as S; + // if (_singl.containsKey(key)) { + // return _singl[key].getDependency() as S; // } else { - // if (GetConfig._factory.containsKey(key)) { - // S _value = put((GetConfig._factory[key].builder() as S), tag: tag); + // if (_factory.containsKey(key)) { + // S _value = put((_factory[key].builder() as S), tag: tag); // if (GetConfig.smartManagement != SmartManagement.keepFactory) { - // if (!GetConfig._factory[key].fenix) { - // GetConfig._factory.remove(key); + // if (!_factory[key].fenix) { + // _factory.remove(key); // } // } // return _value; @@ -156,7 +154,7 @@ class GetInstance { String key = _getKey(S, tag); if (isRegistered(tag: tag)) { - FcBuilder builder = GetConfig._singl[key] as FcBuilder; + FcBuilder builder = _singl[key] as FcBuilder; if (builder == null) { if (tag == null) { throw "class ${S.toString()} is not register"; @@ -166,20 +164,20 @@ class GetInstance { } initDependencies(name: tag); - return GetConfig._singl[key].getDependency() as S; + return _singl[key].getDependency() as S; } else { - if (!GetConfig._factory.containsKey(key)) + if (!_factory.containsKey(key)) throw " $S not found. You need call put<$S>($S()) before"; if (GetConfig.isLogEnable) print('[GETX] $S instance was created at that time'); - S _value = put(GetConfig._factory[key].builder() as S); + S _value = put(_factory[key].builder() as S); initDependencies(name: tag); if (GetConfig.smartManagement != SmartManagement.keepFactory && - !GetConfig._factory[key].fenix) { - GetConfig._factory.remove(key); + !_factory[key].fenix) { + _factory.remove(key); } return _value; @@ -191,9 +189,9 @@ class GetInstance { } bool reset({bool clearFactory = true, bool clearRouteBindings = true}) { - if (clearFactory) GetConfig._factory.clear(); - if (clearRouteBindings) GetConfig.routesKey.clear(); - GetConfig._singl.clear(); + if (clearFactory) _factory.clear(); + if (clearRouteBindings) _routesKey.clear(); + _singl.clear(); return true; } @@ -206,12 +204,12 @@ class GetInstance { newKey = key; } - if (!GetConfig._singl.containsKey(newKey)) { + if (!_singl.containsKey(newKey)) { print('Instance $newKey not found'); return false; } - FcBuilder builder = GetConfig._singl[newKey] as FcBuilder; + FcBuilder builder = _singl[newKey] as FcBuilder; if (builder.permanent && !force) { print( '[GETX] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.'); @@ -227,23 +225,21 @@ class GetInstance { if (GetConfig.isLogEnable) print('[GETX] onClose of $newKey called'); } - GetConfig._singl.removeWhere((oldKey, value) => (oldKey == newKey)); - if (GetConfig._singl.containsKey(newKey)) { + _singl.removeWhere((oldKey, value) => (oldKey == newKey)); + if (_singl.containsKey(newKey)) { print('[GETX] error on remove object $newKey'); } else { if (GetConfig.isLogEnable) print('[GETX] $newKey deleted from memory'); } - // GetConfig.routesKey?.remove(key); + // _routesKey?.remove(key); return true; } /// check if instance is registered - bool isRegistered({String tag}) => - GetConfig._singl.containsKey(_getKey(S, tag)); + bool isRegistered({String tag}) => _singl.containsKey(_getKey(S, tag)); /// check if instance is prepared - bool isPrepared({String tag}) => - GetConfig._factory.containsKey(_getKey(S, tag)); + bool isPrepared({String tag}) => _factory.containsKey(_getKey(S, tag)); } typedef FcBuilderFunc = S Function(); diff --git a/lib/src/navigation/extension_navigation.dart b/lib/src/navigation/extension_navigation.dart index af414e283..ce44c8aa3 100644 --- a/lib/src/navigation/extension_navigation.dart +++ b/lib/src/navigation/extension_navigation.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:get/src/get_interface.dart'; +import 'package:get/src/core/get_interface.dart'; import 'package:get/instance_manager.dart'; import 'package:get/route_manager.dart'; import 'root/parse_route.dart'; diff --git a/lib/src/navigation/root/root_widget.dart b/lib/src/navigation/root/root_widget.dart index 9d590fa38..52aba1bd3 100644 --- a/lib/src/navigation/root/root_widget.dart +++ b/lib/src/navigation/root/root_widget.dart @@ -184,13 +184,9 @@ class GetMaterialApp extends StatelessWidget { initState: (i) { print( '[GETX] INITIALIZED: If you need help, join our community support channels: https://tinyurl.com/y3cp88l3'); - if (locale != null) { - Get.locale = locale; - } + if (locale != null) Get.locale = locale; - if (fallbackLocale != null) { - Get.fallbackLocale = fallbackLocale; - } + if (fallbackLocale != null) Get.fallbackLocale = fallbackLocale; if (translations != null) { Get.translations = translations.keys; diff --git a/lib/src/navigation/root/smart_management.dart b/lib/src/navigation/root/smart_management.dart index 933553437..58be064e6 100644 --- a/lib/src/navigation/root/smart_management.dart +++ b/lib/src/navigation/root/smart_management.dart @@ -2,5 +2,4 @@ enum SmartManagement { full, onlyBuilder, keepFactory, - // none, } diff --git a/lib/src/navigation/route_manager.dart b/lib/src/navigation/route_manager.dart index b22968436..fd0e6bcdd 100644 --- a/lib/src/navigation/route_manager.dart +++ b/lib/src/navigation/route_manager.dart @@ -7,7 +7,7 @@ export 'root/root_widget.dart'; export 'snackbar/snack_route.dart'; export 'bottomsheet/bottomsheet.dart'; export 'snackbar/snack.dart'; -export '../get_main.dart'; +export '../core/get_main.dart'; export 'routes/default_route.dart'; export 'root/smart_management.dart'; export 'extension_navigation.dart'; diff --git a/lib/src/navigation/routes/default_route.dart b/lib/src/navigation/routes/default_route.dart index 2ecc0b400..e7bb764d1 100644 --- a/lib/src/navigation/routes/default_route.dart +++ b/lib/src/navigation/routes/default_route.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:get/route_manager.dart'; -import 'package:get/src/get_main.dart'; +import 'package:get/src/core/get_main.dart'; import 'package:get/src/instance/get_instance.dart'; import 'package:get/utils.dart'; import 'bindings_interface.dart'; diff --git a/lib/src/state_manager/rx/rx_impl.dart b/lib/src/state_manager/rx/rx_impl.dart index 1cb49e3c6..0a24a0b4c 100644 --- a/lib/src/state_manager/rx/rx_impl.dart +++ b/lib/src/state_manager/rx/rx_impl.dart @@ -70,13 +70,13 @@ class _RxImpl implements RxInterface { Stream map(R mapper(T data)) => stream.map(mapper); } -class RxMap extends RxInterface implements Map { +class RxMap extends RxInterface> implements Map { RxMap([Map initial]) { _value = initial; } @override - StreamController subject = StreamController>.broadcast(); + StreamController> subject = StreamController>.broadcast(); final Map>, StreamSubscription> _subscriptions = {}; Map _value; @@ -248,7 +248,7 @@ class RxMap extends RxInterface implements Map { } /// Create a list similar to `List` -class RxList extends Iterable implements RxInterface { +class RxList extends Iterable implements RxInterface> { RxList([List initial]) { _list = initial; } @@ -266,8 +266,8 @@ class RxList extends Iterable implements RxInterface { @override bool get isNotEmpty => value.isNotEmpty; - StreamController subject = StreamController.broadcast(); - Map, StreamSubscription> _subscriptions = Map(); + StreamController> subject = StreamController>.broadcast(); + Map>, StreamSubscription> _subscriptions = Map(); /// Adds [item] only if [condition] resolves to true. void addIf(condition, E item) { @@ -283,7 +283,7 @@ class RxList extends Iterable implements RxInterface { operator []=(int index, E val) { _list[index] = val; - subject.add(val); + subject.add(_list); } E operator [](int index) { @@ -292,12 +292,12 @@ class RxList extends Iterable implements RxInterface { void add(E item) { _list.add(item); - subject.add(item); + subject.add(_list); } void addAll(Iterable item) { _list.addAll(item); - subject.add(null); + subject.add(_list); } /// Adds only if [item] is not null. @@ -312,12 +312,12 @@ class RxList extends Iterable implements RxInterface { void insert(int index, E item) { _list.insert(index, item); - subject.add(item); + subject.add(_list); } void insertAll(int index, Iterable iterable) { _list.insertAll(index, iterable); - subject.add(iterable.last); + subject.add(_list); } int get length => value.length; @@ -337,34 +337,34 @@ class RxList extends Iterable implements RxInterface { E removeAt(int index) { E item = _list.removeAt(index); - subject.add(item); + subject.add(_list); return item; } E removeLast() { E item = _list.removeLast(); - subject.add(item); + subject.add(_list); return item; } void removeRange(int start, int end) { _list.removeRange(start, end); - subject.add(null); + subject.add(_list); } void removeWhere(bool Function(E) test) { _list.removeWhere(test); - subject.add(null); + subject.add(_list); } void clear() { _list.clear(); - subject.add(null); + subject.add(_list); } void sort([int compare(E a, E b)]) { _list.sort(); - subject.add(null); + subject.add(_list); } close() { @@ -401,7 +401,7 @@ class RxList extends Iterable implements RxInterface { String get string => value.toString(); - addListener(Stream rxGetx) { + addListener(Stream> rxGetx) { if (_subscriptions.containsKey(rxGetx)) { return; } @@ -413,12 +413,12 @@ class RxList extends Iterable implements RxInterface { set value(Iterable val) { if (_list == val) return; _list = val; - subject.add(null); + subject.add(_list); } - Stream get stream => subject.stream; + Stream> get stream => subject.stream; - StreamSubscription listen(void Function(E) onData, + StreamSubscription> listen(void Function(List) onData, {Function onError, void Function() onDone, bool cancelOnError}) => stream.listen(onData, onError: onError, onDone: onDone); diff --git a/lib/src/state_manager/rx/rx_interface.dart b/lib/src/state_manager/rx/rx_interface.dart index 3ef6e3a27..49bc94f34 100644 --- a/lib/src/state_manager/rx/rx_interface.dart +++ b/lib/src/state_manager/rx/rx_interface.dart @@ -6,12 +6,12 @@ abstract class RxInterface { RxInterface([T initial]); /// add listener to stream - addListener(Stream rxGetx); + void addListener(Stream rxGetx); bool get canUpdate; /// close stream - close() { + void close() { subject?.close(); } @@ -21,6 +21,9 @@ abstract class RxInterface { StreamSubscription listen(ValueCallback callback); } +/// Unlike GetxController, which serves to control events on each of its pages, +/// GetxService is not automatically disposed. It is ideal for situations where, +/// once started, that service will remain in memory, such as Auth control for example. abstract class GetxService extends DisposableInterface {} abstract class DisposableInterface { diff --git a/pubspec.yaml b/pubspec.yaml index 25d6917fb..629a66d51 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: get description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. -version: 3.4.3 +version: 3.4.4 homepage: https://github.com/jonataslaw/get environment: