Showing
71 changed files
with
1327 additions
and
1404 deletions
1 | # Include option is buggy: | 1 | # Include option is buggy: |
2 | -# https://github.com/flutter/flutter/issues/62591 | 2 | +include: package:lints/recommended.yaml |
3 | # In case the include issue gets fixed, lines below INCLUDE_FIX | 3 | # In case the include issue gets fixed, lines below INCLUDE_FIX |
4 | # can be removed | 4 | # can be removed |
5 | - | ||
6 | -# include: package:effective_dart/analysis_options.1.2.0.yaml | ||
7 | -analyzer: | ||
8 | - strong-mode: | ||
9 | - implicit-casts: false | ||
10 | -linter: | ||
11 | - rules: | ||
12 | - await_only_futures: true | ||
13 | - # This one is desirable, but that's a lot of work for now | ||
14 | - public_member_api_docs: false | ||
15 | - # Desirable, but would be breaking changes: | ||
16 | - avoid_positional_boolean_parameters: false | ||
17 | - constant_identifier_names: false | ||
18 | - include_file_not_found: false | ||
19 | - | ||
20 | - # INCLUDE_FIX (copy of effective dart 1.2.0) | ||
21 | - # STYLE | ||
22 | - camel_case_types: true | ||
23 | - close_sinks: true | ||
24 | - unnecessary_statements: true | ||
25 | - camel_case_extensions: true | ||
26 | - library_names: true | ||
27 | - file_names: true | ||
28 | - library_prefixes: true | ||
29 | - non_constant_identifier_names: true | ||
30 | - directives_ordering: true | ||
31 | - lines_longer_than_80_chars: true # avoid | ||
32 | - curly_braces_in_flow_control_structures: true | ||
33 | - | ||
34 | - # DOCUMENTATION | ||
35 | - slash_for_doc_comments: true | ||
36 | - package_api_docs: true # prefer | ||
37 | - #- comment_references # Unused because https://github.com/dart-lang/sdk/issues/36974 | ||
38 | - | ||
39 | - # USAGE | ||
40 | - implementation_imports: true | ||
41 | - avoid_relative_lib_imports: true # prefer | ||
42 | - prefer_relative_imports: true # prefer | ||
43 | - prefer_adjacent_string_concatenation: true | ||
44 | - prefer_interpolation_to_compose_strings: true # prefer | ||
45 | - unnecessary_brace_in_string_interps: true # avoid | ||
46 | - prefer_collection_literals: true | ||
47 | - avoid_function_literals_in_foreach_calls: true # avoid | ||
48 | - prefer_iterable_whereType: true | ||
49 | - prefer_function_declarations_over_variables: true | ||
50 | - unnecessary_lambdas: true | ||
51 | - prefer_equal_for_default_values: true | ||
52 | - avoid_init_to_null: true | ||
53 | - unnecessary_getters_setters: true | ||
54 | - annotate_overrides: true | ||
55 | - #- unnecessary_getters # prefer # Disabled pending fix: https://github.com/dart-lang/linter/issues/23 | ||
56 | - #- prefer_expression_function_bodies # consider | ||
57 | - unnecessary_this: true | ||
58 | - prefer_initializing_formals: true | ||
59 | - type_init_formals: true | ||
60 | - empty_constructor_bodies: true | ||
61 | - unnecessary_new: true | ||
62 | - unnecessary_const: true | ||
63 | - avoid_catches_without_on_clauses: true # avoid | ||
64 | - avoid_catching_errors: true | ||
65 | - use_rethrow_when_possible: true | ||
66 | - unrelated_type_equality_checks: true | ||
67 | - | ||
68 | - # DESIGN | ||
69 | - use_to_and_as_if_applicable: true # prefer | ||
70 | - one_member_abstracts: true # avoid | ||
71 | - avoid_classes_with_only_static_members: true # avoid | ||
72 | - prefer_mixin: true | ||
73 | - prefer_final_fields: true # prefer | ||
74 | - use_setters_to_change_properties: true | ||
75 | - avoid_setters_without_getters: true | ||
76 | - avoid_returning_null: true # avoid | ||
77 | - avoid_returning_this: true # avoid | ||
78 | - type_annotate_public_apis: true # prefer | ||
79 | - #- prefer_typing_uninitialized_variables # consider | ||
80 | - omit_local_variable_types: true # avoid | ||
81 | - avoid_types_on_closure_parameters: true # avoid | ||
82 | - avoid_return_types_on_setters: true # avoid | ||
83 | - prefer_generic_function_type_aliases: true | ||
84 | - avoid_private_typedef_functions: true # prefer | ||
85 | - #- use_function_type_syntax_for_parameters # consider | ||
86 | - hash_and_equals: true | ||
87 | - avoid_equals_and_hash_code_on_mutable_classes: true # avoid | ||
88 | - avoid_null_checks_in_equality_operators: true | ||
89 | - |
@@ -15,7 +15,7 @@ class AppPages { | @@ -15,7 +15,7 @@ class AppPages { | ||
15 | GetPage( | 15 | GetPage( |
16 | name: Routes.HOME, | 16 | name: Routes.HOME, |
17 | page: () => HomeView(), | 17 | page: () => HomeView(), |
18 | - bindings: [HomeBinding()], | 18 | + binding: HomeBinding(), |
19 | children: [ | 19 | children: [ |
20 | GetPage( | 20 | GetPage( |
21 | name: Routes.COUNTRY, | 21 | name: Routes.COUNTRY, |
@@ -37,15 +37,22 @@ class MockRepositoryFailure implements IHomeRepository { | @@ -37,15 +37,22 @@ class MockRepositoryFailure implements IHomeRepository { | ||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | +class MockBinding extends Binding { | ||
41 | + @override | ||
42 | + List<Bind> dependencies() { | ||
43 | + return [ | ||
44 | + Bind.lazyPut<IHomeRepository>(() => MockRepositorySuccess()), | ||
45 | + Bind.lazyPut<HomeController>( | ||
46 | + () => HomeController(homeRepository: Get.find()), | ||
47 | + ) | ||
48 | + ]; | ||
49 | + } | ||
50 | +} | ||
51 | + | ||
40 | void main() { | 52 | void main() { |
41 | WidgetsFlutterBinding.ensureInitialized(); | 53 | WidgetsFlutterBinding.ensureInitialized(); |
42 | setUpAll(() => HttpOverrides.global = null); | 54 | setUpAll(() => HttpOverrides.global = null); |
43 | - final binding = BindingsBuilder(() { | ||
44 | - Get.lazyPut<IHomeRepository>(() => MockRepositorySuccess()); | ||
45 | - Get.lazyPut<HomeController>( | ||
46 | - () => HomeController(homeRepository: Get.find()), | ||
47 | - ); | ||
48 | - }); | 55 | + final binding = MockBinding(); |
49 | 56 | ||
50 | test('Test Controller', () async { | 57 | test('Test Controller', () async { |
51 | /// Controller can't be on memory | 58 | /// Controller can't be on memory |
@@ -53,7 +60,7 @@ void main() { | @@ -53,7 +60,7 @@ void main() { | ||
53 | throwsA(m.TypeMatcher<String>())); | 60 | throwsA(m.TypeMatcher<String>())); |
54 | 61 | ||
55 | /// binding will put the controller on memory | 62 | /// binding will put the controller on memory |
56 | - binding.builder(); | 63 | + binding.dependencies(); |
57 | 64 | ||
58 | /// recover your controller | 65 | /// recover your controller |
59 | final controller = Get.find<HomeController>(); | 66 | final controller = Get.find<HomeController>(); |
@@ -9,22 +9,22 @@ class HomeView extends GetView<HomeController> { | @@ -9,22 +9,22 @@ class HomeView extends GetView<HomeController> { | ||
9 | @override | 9 | @override |
10 | Widget build(BuildContext context) { | 10 | Widget build(BuildContext context) { |
11 | return GetRouterOutlet.builder( | 11 | return GetRouterOutlet.builder( |
12 | - routerDelegate: Get.nestedKey(Routes.HOME), | 12 | + routerDelegate: Get.nestedKey(Routes.home), |
13 | builder: (context) { | 13 | builder: (context) { |
14 | final delegate = context.navigation; | 14 | final delegate = context.navigation; |
15 | //This router outlet handles the appbar and the bottom navigation bar | 15 | //This router outlet handles the appbar and the bottom navigation bar |
16 | final currentLocation = context.location; | 16 | final currentLocation = context.location; |
17 | var currentIndex = 0; | 17 | var currentIndex = 0; |
18 | - if (currentLocation.startsWith(Routes.PRODUCTS) == true) { | 18 | + if (currentLocation.startsWith(Routes.products) == true) { |
19 | currentIndex = 2; | 19 | currentIndex = 2; |
20 | } | 20 | } |
21 | - if (currentLocation.startsWith(Routes.PROFILE) == true) { | 21 | + if (currentLocation.startsWith(Routes.profile) == true) { |
22 | currentIndex = 1; | 22 | currentIndex = 1; |
23 | } | 23 | } |
24 | return Scaffold( | 24 | return Scaffold( |
25 | body: GetRouterOutlet( | 25 | body: GetRouterOutlet( |
26 | - initialRoute: Routes.DASHBOARD, | ||
27 | - anchorRoute: Routes.HOME, | 26 | + initialRoute: Routes.dashboard, |
27 | + anchorRoute: Routes.home, | ||
28 | 28 | ||
29 | //delegate: Get.nestedKey(Routes.HOME), | 29 | //delegate: Get.nestedKey(Routes.HOME), |
30 | // key: Get.nestedKey(Routes.HOME), | 30 | // key: Get.nestedKey(Routes.HOME), |
@@ -34,13 +34,13 @@ class HomeView extends GetView<HomeController> { | @@ -34,13 +34,13 @@ class HomeView extends GetView<HomeController> { | ||
34 | onTap: (value) { | 34 | onTap: (value) { |
35 | switch (value) { | 35 | switch (value) { |
36 | case 0: | 36 | case 0: |
37 | - delegate.toNamed(Routes.HOME); | 37 | + delegate.toNamed(Routes.home); |
38 | break; | 38 | break; |
39 | case 1: | 39 | case 1: |
40 | - delegate.toNamed(Routes.PROFILE); | 40 | + delegate.toNamed(Routes.profile); |
41 | break; | 41 | break; |
42 | case 2: | 42 | case 2: |
43 | - delegate.toNamed(Routes.PRODUCTS); | 43 | + delegate.toNamed(Routes.products); |
44 | break; | 44 | break; |
45 | default: | 45 | default: |
46 | } | 46 | } |
@@ -32,7 +32,7 @@ class LoginView extends GetView<LoginController> { | @@ -32,7 +32,7 @@ class LoginView extends GetView<LoginController> { | ||
32 | onPressed: () { | 32 | onPressed: () { |
33 | AuthService.to.login(); | 33 | AuthService.to.login(); |
34 | final thenTo = context.params['then']; | 34 | final thenTo = context.params['then']; |
35 | - Get.offNamed(thenTo ?? Routes.HOME); | 35 | + Get.offNamed(thenTo ?? Routes.home); |
36 | }, | 36 | }, |
37 | ), | 37 | ), |
38 | ], | 38 | ], |
@@ -39,7 +39,7 @@ class ProfileView extends GetView<ProfileController> { | @@ -39,7 +39,7 @@ class ProfileView extends GetView<ProfileController> { | ||
39 | Get.defaultDialog( | 39 | Get.defaultDialog( |
40 | title: 'Test Dialog In Home Outlet !!', | 40 | title: 'Test Dialog In Home Outlet !!', |
41 | barrierDismissible: true, | 41 | barrierDismissible: true, |
42 | - id: Routes.HOME, | 42 | + id: Routes.home, |
43 | // navigatorKey: Get.nestedKey(Routes.HOME), | 43 | // navigatorKey: Get.nestedKey(Routes.HOME), |
44 | ); | 44 | ); |
45 | }, | 45 | }, |
1 | import 'package:get/get.dart'; | 1 | import 'package:get/get.dart'; |
2 | 2 | ||
3 | class RootController extends GetxController { | 3 | class RootController extends GetxController { |
4 | - //TODO: Implement RootController | ||
5 | - | ||
6 | final count = 0.obs; | 4 | final count = 0.obs; |
7 | - @override | ||
8 | - void onInit() { | ||
9 | - super.onInit(); | ||
10 | - } | ||
11 | - | ||
12 | - @override | ||
13 | - void onReady() { | ||
14 | - super.onReady(); | ||
15 | - } | ||
16 | 5 | ||
17 | @override | 6 | @override |
18 | void onClose() {} | 7 | void onClose() {} |
@@ -21,7 +21,7 @@ class DrawerWidget extends StatelessWidget { | @@ -21,7 +21,7 @@ class DrawerWidget extends StatelessWidget { | ||
21 | ListTile( | 21 | ListTile( |
22 | title: Text('Home'), | 22 | title: Text('Home'), |
23 | onTap: () { | 23 | onTap: () { |
24 | - Get.toNamed(Routes.HOME); | 24 | + Get.toNamed(Routes.home); |
25 | //to close the drawer | 25 | //to close the drawer |
26 | 26 | ||
27 | Navigator.of(context).pop(); | 27 | Navigator.of(context).pop(); |
@@ -30,7 +30,7 @@ class DrawerWidget extends StatelessWidget { | @@ -30,7 +30,7 @@ class DrawerWidget extends StatelessWidget { | ||
30 | ListTile( | 30 | ListTile( |
31 | title: Text('Settings'), | 31 | title: Text('Settings'), |
32 | onTap: () { | 32 | onTap: () { |
33 | - Get.toNamed(Routes.SETTINGS); | 33 | + Get.toNamed(Routes.settings); |
34 | //to close the drawer | 34 | //to close the drawer |
35 | 35 | ||
36 | Navigator.of(context).pop(); | 36 | Navigator.of(context).pop(); |
@@ -46,7 +46,7 @@ class DrawerWidget extends StatelessWidget { | @@ -46,7 +46,7 @@ class DrawerWidget extends StatelessWidget { | ||
46 | ), | 46 | ), |
47 | onTap: () { | 47 | onTap: () { |
48 | AuthService.to.logout(); | 48 | AuthService.to.logout(); |
49 | - Get.toNamed(Routes.LOGIN); | 49 | + Get.toNamed(Routes.login); |
50 | //to close the drawer | 50 | //to close the drawer |
51 | 51 | ||
52 | Navigator.of(context).pop(); | 52 | Navigator.of(context).pop(); |
@@ -61,7 +61,7 @@ class DrawerWidget extends StatelessWidget { | @@ -61,7 +61,7 @@ class DrawerWidget extends StatelessWidget { | ||
61 | ), | 61 | ), |
62 | ), | 62 | ), |
63 | onTap: () { | 63 | onTap: () { |
64 | - Get.toNamed(Routes.LOGIN); | 64 | + Get.toNamed(Routes.login); |
65 | //to close the drawer | 65 | //to close the drawer |
66 | 66 | ||
67 | Navigator.of(context).pop(); | 67 | Navigator.of(context).pop(); |
@@ -21,7 +21,7 @@ class RootView extends GetView<RootController> { | @@ -21,7 +21,7 @@ class RootView extends GetView<RootController> { | ||
21 | //body: HomeView(), | 21 | //body: HomeView(), |
22 | 22 | ||
23 | body: GetRouterOutlet( | 23 | body: GetRouterOutlet( |
24 | - initialRoute: Routes.HOME, | 24 | + initialRoute: Routes.home, |
25 | delegate: Get.nestedKey(null), | 25 | delegate: Get.nestedKey(null), |
26 | anchorRoute: '/', | 26 | anchorRoute: '/', |
27 | filterPages: (afterAnchor) { | 27 | filterPages: (afterAnchor) { |
1 | import 'package:get/get.dart'; | 1 | import 'package:get/get.dart'; |
2 | 2 | ||
3 | class SettingsController extends GetxController { | 3 | class SettingsController extends GetxController { |
4 | - //TODO: Implement SettingsController | ||
5 | - | ||
6 | final count = 0.obs; | 4 | final count = 0.obs; |
7 | - @override | ||
8 | - void onInit() { | ||
9 | - super.onInit(); | ||
10 | - } | ||
11 | - | ||
12 | - @override | ||
13 | - void onReady() { | ||
14 | - super.onReady(); | ||
15 | - } | ||
16 | 5 | ||
17 | @override | 6 | @override |
18 | void onClose() {} | 7 | void onClose() {} |
@@ -23,7 +23,7 @@ part 'app_routes.dart'; | @@ -23,7 +23,7 @@ part 'app_routes.dart'; | ||
23 | class AppPages { | 23 | class AppPages { |
24 | AppPages._(); | 24 | AppPages._(); |
25 | 25 | ||
26 | - static const INITIAL = Routes.HOME; | 26 | + static const initial = Routes.home; |
27 | 27 | ||
28 | static final routes = [ | 28 | static final routes = [ |
29 | GetPage( | 29 | GetPage( |
@@ -38,13 +38,13 @@ class AppPages { | @@ -38,13 +38,13 @@ class AppPages { | ||
38 | //only enter this route when not authed | 38 | //only enter this route when not authed |
39 | EnsureNotAuthedMiddleware(), | 39 | EnsureNotAuthedMiddleware(), |
40 | ], | 40 | ], |
41 | - name: _Paths.LOGIN, | 41 | + name: _Paths.login, |
42 | page: () => LoginView(), | 42 | page: () => LoginView(), |
43 | bindings: [LoginBinding()], | 43 | bindings: [LoginBinding()], |
44 | ), | 44 | ), |
45 | GetPage( | 45 | GetPage( |
46 | preventDuplicates: true, | 46 | preventDuplicates: true, |
47 | - name: _Paths.HOME, | 47 | + name: _Paths.home, |
48 | page: () => const HomeView(), | 48 | page: () => const HomeView(), |
49 | bindings: [ | 49 | bindings: [ |
50 | HomeBinding(), | 50 | HomeBinding(), |
@@ -52,7 +52,7 @@ class AppPages { | @@ -52,7 +52,7 @@ class AppPages { | ||
52 | title: null, | 52 | title: null, |
53 | children: [ | 53 | children: [ |
54 | GetPage( | 54 | GetPage( |
55 | - name: _Paths.DASHBOARD, | 55 | + name: _Paths.dashboard, |
56 | page: () => DashboardView(), | 56 | page: () => DashboardView(), |
57 | bindings: [ | 57 | bindings: [ |
58 | DashboardBinding(), | 58 | DashboardBinding(), |
@@ -63,14 +63,14 @@ class AppPages { | @@ -63,14 +63,14 @@ class AppPages { | ||
63 | //only enter this route when authed | 63 | //only enter this route when authed |
64 | EnsureAuthMiddleware(), | 64 | EnsureAuthMiddleware(), |
65 | ], | 65 | ], |
66 | - name: _Paths.PROFILE, | 66 | + name: _Paths.profile, |
67 | page: () => ProfileView(), | 67 | page: () => ProfileView(), |
68 | title: 'Profile', | 68 | title: 'Profile', |
69 | transition: Transition.size, | 69 | transition: Transition.size, |
70 | bindings: [ProfileBinding()], | 70 | bindings: [ProfileBinding()], |
71 | ), | 71 | ), |
72 | GetPage( | 72 | GetPage( |
73 | - name: _Paths.PRODUCTS, | 73 | + name: _Paths.products, |
74 | page: () => const ProductsView(), | 74 | page: () => const ProductsView(), |
75 | title: 'Products', | 75 | title: 'Products', |
76 | transition: Transition.zoom, | 76 | transition: Transition.zoom, |
@@ -78,7 +78,7 @@ class AppPages { | @@ -78,7 +78,7 @@ class AppPages { | ||
78 | bindings: [ProductsBinding()], | 78 | bindings: [ProductsBinding()], |
79 | children: [ | 79 | children: [ |
80 | GetPage( | 80 | GetPage( |
81 | - name: _Paths.PRODUCT_DETAILS, | 81 | + name: _Paths.productDetails, |
82 | page: () => ProductDetailsView(), | 82 | page: () => ProductDetailsView(), |
83 | bindings: [ProductDetailsBinding()], | 83 | bindings: [ProductDetailsBinding()], |
84 | middlewares: [ | 84 | middlewares: [ |
@@ -91,7 +91,7 @@ class AppPages { | @@ -91,7 +91,7 @@ class AppPages { | ||
91 | ], | 91 | ], |
92 | ), | 92 | ), |
93 | GetPage( | 93 | GetPage( |
94 | - name: _Paths.SETTINGS, | 94 | + name: _Paths.settings, |
95 | page: () => SettingsView(), | 95 | page: () => SettingsView(), |
96 | bindings: [ | 96 | bindings: [ |
97 | SettingsBinding(), | 97 | SettingsBinding(), |
@@ -4,27 +4,27 @@ part of 'app_pages.dart'; | @@ -4,27 +4,27 @@ part of 'app_pages.dart'; | ||
4 | // DO NOT EDIT. This is code generated via package:get_cli/get_cli.dart | 4 | // DO NOT EDIT. This is code generated via package:get_cli/get_cli.dart |
5 | 5 | ||
6 | abstract class Routes { | 6 | abstract class Routes { |
7 | - static const HOME = _Paths.HOME; | 7 | + static const home = _Paths.home; |
8 | 8 | ||
9 | - static const PROFILE = _Paths.HOME + _Paths.PROFILE; | ||
10 | - static const SETTINGS = _Paths.SETTINGS; | 9 | + static const profile = _Paths.home + _Paths.profile; |
10 | + static const settings = _Paths.settings; | ||
11 | 11 | ||
12 | - static const PRODUCTS = _Paths.HOME + _Paths.PRODUCTS; | 12 | + static const products = _Paths.home + _Paths.products; |
13 | 13 | ||
14 | - static const LOGIN = _Paths.LOGIN; | ||
15 | - static const DASHBOARD = _Paths.HOME + _Paths.DASHBOARD; | 14 | + static const login = _Paths.login; |
15 | + static const dashboard = _Paths.home + _Paths.dashboard; | ||
16 | Routes._(); | 16 | Routes._(); |
17 | static String LOGIN_THEN(String afterSuccessfulLogin) => | 17 | static String LOGIN_THEN(String afterSuccessfulLogin) => |
18 | - '$LOGIN?then=${Uri.encodeQueryComponent(afterSuccessfulLogin)}'; | ||
19 | - static String PRODUCT_DETAILS(String productId) => '$PRODUCTS/$productId'; | 18 | + '$login?then=${Uri.encodeQueryComponent(afterSuccessfulLogin)}'; |
19 | + static String PRODUCT_DETAILS(String productId) => '$products/$productId'; | ||
20 | } | 20 | } |
21 | 21 | ||
22 | abstract class _Paths { | 22 | abstract class _Paths { |
23 | - static const HOME = '/home'; | ||
24 | - static const PRODUCTS = '/products'; | ||
25 | - static const PROFILE = '/profile'; | ||
26 | - static const SETTINGS = '/settings'; | ||
27 | - static const PRODUCT_DETAILS = '/:productId'; | ||
28 | - static const LOGIN = '/login'; | ||
29 | - static const DASHBOARD = '/dashboard'; | 23 | + static const home = '/home'; |
24 | + static const products = '/products'; | ||
25 | + static const profile = '/profile'; | ||
26 | + static const settings = '/settings'; | ||
27 | + static const productDetails = '/:productId'; | ||
28 | + static const login = '/login'; | ||
29 | + static const dashboard = '/dashboard'; | ||
30 | } | 30 | } |
@@ -9,14 +9,12 @@ void main() { | @@ -9,14 +9,12 @@ void main() { | ||
9 | runApp( | 9 | runApp( |
10 | GetMaterialApp( | 10 | GetMaterialApp( |
11 | title: "Application", | 11 | title: "Application", |
12 | - initialBinding: BindingsBuilder( | ||
13 | - () { | ||
14 | - Get.put(SplashService()); | ||
15 | - Get.put(AuthService()); | ||
16 | - }, | ||
17 | - ), | 12 | + binds: [ |
13 | + Bind.put(SplashService()), | ||
14 | + Bind.put(AuthService()), | ||
15 | + ], | ||
18 | getPages: AppPages.routes, | 16 | getPages: AppPages.routes, |
19 | - initialRoute: AppPages.INITIAL, | 17 | + initialRoute: AppPages.initial, |
20 | // builder: (context, child) { | 18 | // builder: (context, child) { |
21 | // return FutureBuilder<void>( | 19 | // return FutureBuilder<void>( |
22 | // key: ValueKey('initFuture'), | 20 | // key: ValueKey('initFuture'), |
1 | import '../get.dart'; | 1 | import '../get.dart'; |
2 | 2 | ||
3 | extension GetResetExt on GetInterface { | 3 | extension GetResetExt on GetInterface { |
4 | - void reset( | ||
5 | - {@deprecated bool clearFactory = true, bool clearRouteBindings = true}) { | ||
6 | - GetInstance().resetInstance(clearRouteBindings: clearRouteBindings); | ||
7 | - Get.clearRouteTree(); | 4 | + void reset({bool clearRouteBindings = true}) { |
5 | + Get.resetInstance(clearRouteBindings: clearRouteBindings); | ||
6 | + // Get.clearRouteTree(); | ||
8 | Get.clearTranslations(); | 7 | Get.clearTranslations(); |
9 | - Get.resetRootNavigator(); | 8 | + // Get.resetRootNavigator(); |
10 | } | 9 | } |
11 | } | 10 | } |
@@ -8,9 +8,7 @@ import '../src/request/request.dart'; | @@ -8,9 +8,7 @@ import '../src/request/request.dart'; | ||
8 | import '../src/response/response.dart'; | 8 | import '../src/response/response.dart'; |
9 | import '../src/status/http_status.dart'; | 9 | import '../src/status/http_status.dart'; |
10 | import 'http/interface/request_base.dart'; | 10 | import 'http/interface/request_base.dart'; |
11 | -import 'http/stub/http_request_stub.dart' | ||
12 | - if (dart.library.html) 'http/html/http_request_html.dart' | ||
13 | - if (dart.library.io) 'http/io/http_request_io.dart'; | 11 | +import 'http/request/http_request.dart'; |
14 | import 'interceptors/get_modifiers.dart'; | 12 | import 'interceptors/get_modifiers.dart'; |
15 | 13 | ||
16 | typedef Decoder<T> = T Function(dynamic data); | 14 | typedef Decoder<T> = T Function(dynamic data); |
@@ -55,7 +53,7 @@ class GetHttpClient { | @@ -55,7 +53,7 @@ class GetHttpClient { | ||
55 | List<TrustedCertificate>? trustedCertificates, | 53 | List<TrustedCertificate>? trustedCertificates, |
56 | bool withCredentials = false, | 54 | bool withCredentials = false, |
57 | String Function(Uri url)? findProxy, | 55 | String Function(Uri url)? findProxy, |
58 | - }) : _httpClient = HttpRequestImpl( | 56 | + }) : _httpClient = createHttp( |
59 | allowAutoSignedCert: allowAutoSignedCert, | 57 | allowAutoSignedCert: allowAutoSignedCert, |
60 | trustedCertificates: trustedCertificates, | 58 | trustedCertificates: trustedCertificates, |
61 | withCredentials: withCredentials, | 59 | withCredentials: withCredentials, |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | -import 'dart:html' as html; | 2 | +import 'dart:html'; |
3 | 3 | ||
4 | import '../../certificates/certificates.dart'; | 4 | import '../../certificates/certificates.dart'; |
5 | import '../../exceptions/exceptions.dart'; | 5 | import '../../exceptions/exceptions.dart'; |
@@ -18,7 +18,7 @@ class HttpRequestImpl implements HttpRequestBase { | @@ -18,7 +18,7 @@ class HttpRequestImpl implements HttpRequestBase { | ||
18 | }); | 18 | }); |
19 | 19 | ||
20 | /// The currently active XHRs. | 20 | /// The currently active XHRs. |
21 | - final _xhrs = <html.HttpRequest>{}; | 21 | + final _xhrs = <HttpRequest>{}; |
22 | 22 | ||
23 | ///This option requires that you submit credentials for requests | 23 | ///This option requires that you submit credentials for requests |
24 | ///on different sites. The default is false | 24 | ///on different sites. The default is false |
@@ -31,9 +31,9 @@ class HttpRequestImpl implements HttpRequestBase { | @@ -31,9 +31,9 @@ class HttpRequestImpl implements HttpRequestBase { | ||
31 | @override | 31 | @override |
32 | Future<Response<T>> send<T>(Request<T> request) async { | 32 | Future<Response<T>> send<T>(Request<T> request) async { |
33 | var bytes = await request.bodyBytes.toBytes(); | 33 | var bytes = await request.bodyBytes.toBytes(); |
34 | - html.HttpRequest xhr; | 34 | + HttpRequest xhr; |
35 | 35 | ||
36 | - xhr = html.HttpRequest() | 36 | + xhr = HttpRequest() |
37 | ..timeout = timeout?.inMilliseconds | 37 | ..timeout = timeout?.inMilliseconds |
38 | ..open(request.method, '${request.url}', async: true); // check this | 38 | ..open(request.method, '${request.url}', async: true); // check this |
39 | 39 | ||
@@ -46,8 +46,8 @@ class HttpRequestImpl implements HttpRequestBase { | @@ -46,8 +46,8 @@ class HttpRequestImpl implements HttpRequestBase { | ||
46 | 46 | ||
47 | var completer = Completer<Response<T>>(); | 47 | var completer = Completer<Response<T>>(); |
48 | xhr.onLoad.first.then((_) { | 48 | xhr.onLoad.first.then((_) { |
49 | - var blob = xhr.response as html.Blob? ?? html.Blob([]); | ||
50 | - var reader = html.FileReader(); | 49 | + var blob = xhr.response as Blob? ?? Blob([]); |
50 | + var reader = FileReader(); | ||
51 | 51 | ||
52 | reader.onLoad.first.then((_) async { | 52 | reader.onLoad.first.then((_) async { |
53 | var bodyBytes = BodyBytesStream.fromBytes(reader.result as List<int>); | 53 | var bodyBytes = BodyBytesStream.fromBytes(reader.result as List<int>); |
1 | +import '../../certificates/certificates.dart'; | ||
2 | +import '../stub/http_request_stub.dart' | ||
3 | + if (dart.library.html) '../html/http_request_html.dart' | ||
4 | + if (dart.library.io) '../io/http_request_io.dart'; | ||
5 | + | ||
6 | +HttpRequestImpl createHttp({ | ||
7 | + bool allowAutoSignedCert = true, | ||
8 | + List<TrustedCertificate>? trustedCertificates, | ||
9 | + bool withCredentials = false, | ||
10 | + String Function(Uri url)? findProxy, | ||
11 | +}) { | ||
12 | + return HttpRequestImpl( | ||
13 | + allowAutoSignedCert: allowAutoSignedCert, | ||
14 | + trustedCertificates: trustedCertificates, | ||
15 | + withCredentials: withCredentials, | ||
16 | + findProxy: findProxy, | ||
17 | + ); | ||
18 | +} |
1 | import 'dart:convert'; | 1 | import 'dart:convert'; |
2 | 2 | ||
3 | import '../../../../../get_core/get_core.dart'; | 3 | import '../../../../../get_core/get_core.dart'; |
4 | - | ||
5 | import '../../request/request.dart'; | 4 | import '../../request/request.dart'; |
6 | 5 | ||
7 | T? bodyDecoded<T>(Request<T> request, String stringBody, String? mimeType) { | 6 | T? bodyDecoded<T>(Request<T> request, String stringBody, String? mimeType) { |
8 | T? body; | 7 | T? body; |
9 | - var bodyToDecode; | 8 | + dynamic bodyToDecode; |
10 | 9 | ||
11 | if (mimeType != null && mimeType.contains('application/json')) { | 10 | if (mimeType != null && mimeType.contains('application/json')) { |
12 | try { | 11 | try { |
@@ -10,7 +10,7 @@ typedef ResponseModifier<T> = FutureOr Function( | @@ -10,7 +10,7 @@ typedef ResponseModifier<T> = FutureOr Function( | ||
10 | 10 | ||
11 | typedef HandlerExecute<T> = Future<Request<T>> Function(); | 11 | typedef HandlerExecute<T> = Future<Request<T>> Function(); |
12 | 12 | ||
13 | -class GetModifier<T> { | 13 | +class GetModifier<S> { |
14 | final _requestModifiers = <RequestModifier>[]; | 14 | final _requestModifiers = <RequestModifier>[]; |
15 | final _responseModifiers = <ResponseModifier>[]; | 15 | final _responseModifiers = <ResponseModifier>[]; |
16 | RequestModifier? authenticator; | 16 | RequestModifier? authenticator; |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | import 'dart:convert'; | 2 | import 'dart:convert'; |
3 | import 'dart:math'; | 3 | import 'dart:math'; |
4 | + | ||
4 | import '../request/request.dart'; | 5 | import '../request/request.dart'; |
5 | import '../utils/utils.dart'; | 6 | import '../utils/utils.dart'; |
6 | import 'multipart_file.dart'; | 7 | import 'multipart_file.dart'; |
@@ -8,7 +9,7 @@ import 'multipart_file.dart'; | @@ -8,7 +9,7 @@ import 'multipart_file.dart'; | ||
8 | class FormData { | 9 | class FormData { |
9 | FormData(Map<String, dynamic> map) : boundary = _getBoundary() { | 10 | FormData(Map<String, dynamic> map) : boundary = _getBoundary() { |
10 | map.forEach((key, value) { | 11 | map.forEach((key, value) { |
11 | - if (value == null) return null; | 12 | + if (value == null) return; |
12 | if (value is MultipartFile) { | 13 | if (value is MultipartFile) { |
13 | files.add(MapEntry(key, value)); | 14 | files.add(MapEntry(key, value)); |
14 | } else if (value is List<MultipartFile>) { | 15 | } else if (value is List<MultipartFile>) { |
1 | import 'dart:collection'; | 1 | import 'dart:collection'; |
2 | import 'dart:convert'; | 2 | import 'dart:convert'; |
3 | + | ||
3 | import '../exceptions/exceptions.dart'; | 4 | import '../exceptions/exceptions.dart'; |
4 | import '../request/request.dart'; | 5 | import '../request/request.dart'; |
5 | import '../status/http_status.dart'; | 6 | import '../status/http_status.dart'; |
@@ -206,7 +207,7 @@ class HeaderValue { | @@ -206,7 +207,7 @@ class HeaderValue { | ||
206 | } | 207 | } |
207 | 208 | ||
208 | String? parseParameterValue() { | 209 | String? parseParameterValue() { |
209 | - if (!done() && value[index] == '\"') { | 210 | + if (!done() && value[index] == '"') { |
210 | var stringBuffer = StringBuffer(); | 211 | var stringBuffer = StringBuffer(); |
211 | index++; | 212 | index++; |
212 | while (!done()) { | 213 | while (!done()) { |
@@ -214,11 +215,11 @@ class HeaderValue { | @@ -214,11 +215,11 @@ class HeaderValue { | ||
214 | if (index + 1 == value.length) { | 215 | if (index + 1 == value.length) { |
215 | throw StateError('Failed to parse header value'); | 216 | throw StateError('Failed to parse header value'); |
216 | } | 217 | } |
217 | - if (preserveBackslash && value[index + 1] != '\"') { | 218 | + if (preserveBackslash && value[index + 1] != '"') { |
218 | stringBuffer.write(value[index]); | 219 | stringBuffer.write(value[index]); |
219 | } | 220 | } |
220 | index++; | 221 | index++; |
221 | - } else if (value[index] == '\"') { | 222 | + } else if (value[index] == '"') { |
222 | index++; | 223 | index++; |
223 | break; | 224 | break; |
224 | } | 225 | } |
1 | import 'package:flutter/foundation.dart'; | 1 | import 'package:flutter/foundation.dart'; |
2 | -import 'package:flutter/widgets.dart'; | ||
3 | 2 | ||
4 | import 'log.dart'; | 3 | import 'log.dart'; |
5 | import 'smart_management.dart'; | 4 | import 'smart_management.dart'; |
@@ -8,8 +7,6 @@ import 'smart_management.dart'; | @@ -8,8 +7,6 @@ import 'smart_management.dart'; | ||
8 | /// class through extensions | 7 | /// class through extensions |
9 | abstract class GetInterface { | 8 | abstract class GetInterface { |
10 | SmartManagement smartManagement = SmartManagement.full; | 9 | SmartManagement smartManagement = SmartManagement.full; |
11 | - RouterDelegate? routerDelegate; | ||
12 | - RouteInformationParser? routeInformationParser; | ||
13 | bool isLogEnable = kDebugMode; | 10 | bool isLogEnable = kDebugMode; |
14 | LogWriterCallback log = defaultLogWriterCallback; | 11 | LogWriterCallback log = defaultLogWriterCallback; |
15 | } | 12 | } |
1 | // ignore: one_member_abstracts | 1 | // ignore: one_member_abstracts |
2 | -import 'get_instance.dart'; | ||
3 | 2 | ||
4 | // ignore: one_member_abstracts | 3 | // ignore: one_member_abstracts |
5 | abstract class BindingsInterface<T> { | 4 | abstract class BindingsInterface<T> { |
@@ -18,52 +17,52 @@ abstract class Bindings extends BindingsInterface<void> { | @@ -18,52 +17,52 @@ abstract class Bindings extends BindingsInterface<void> { | ||
18 | void dependencies(); | 17 | void dependencies(); |
19 | } | 18 | } |
20 | 19 | ||
21 | -/// Simplifies Bindings generation from a single callback. | ||
22 | -/// To avoid the creation of a custom Binding instance per route. | ||
23 | -/// | ||
24 | -/// Example: | ||
25 | -/// ``` | ||
26 | -/// GetPage( | ||
27 | -/// name: '/', | ||
28 | -/// page: () => Home(), | ||
29 | -/// // This might cause you an error. | ||
30 | -/// // binding: BindingsBuilder(() => Get.put(HomeController())), | ||
31 | -/// binding: BindingsBuilder(() { Get.put(HomeController(); })), | ||
32 | -/// // Using .lazyPut() works fine. | ||
33 | -/// // binding: BindingsBuilder(() => Get.lazyPut(() => HomeController())), | ||
34 | -/// ), | ||
35 | -/// ``` | ||
36 | -class BindingsBuilder<T> extends Bindings { | ||
37 | - /// Register your dependencies in the [builder] callback. | ||
38 | - final BindingBuilderCallback builder; | 20 | +// /// Simplifies Bindings generation from a single callback. |
21 | +// /// To avoid the creation of a custom Binding instance per route. | ||
22 | +// /// | ||
23 | +// /// Example: | ||
24 | +// /// ``` | ||
25 | +// /// GetPage( | ||
26 | +// /// name: '/', | ||
27 | +// /// page: () => Home(), | ||
28 | +// /// // This might cause you an error. | ||
29 | +// /// // binding: BindingsBuilder(() => Get.put(HomeController())), | ||
30 | +// /// binding: BindingsBuilder(() { Get.put(HomeController(); })), | ||
31 | +// /// // Using .lazyPut() works fine. | ||
32 | +// /// // binding: BindingsBuilder(() => Get.lazyPut(() => HomeController())), | ||
33 | +// /// ), | ||
34 | +// /// ``` | ||
35 | +// class BindingsBuilder<T> extends Bindings { | ||
36 | +// /// Register your dependencies in the [builder] callback. | ||
37 | +// final BindingBuilderCallback builder; | ||
39 | 38 | ||
40 | - /// Shortcut to register 1 Controller with Get.put(), | ||
41 | - /// Prevents the issue of the fat arrow function with the constructor. | ||
42 | - /// BindingsBuilder(() => Get.put(HomeController())), | ||
43 | - /// | ||
44 | - /// Sample: | ||
45 | - /// ``` | ||
46 | - /// GetPage( | ||
47 | - /// name: '/', | ||
48 | - /// page: () => Home(), | ||
49 | - /// binding: BindingsBuilder.put(() => HomeController()), | ||
50 | - /// ), | ||
51 | - /// ``` | ||
52 | - factory BindingsBuilder.put(InstanceBuilderCallback<T> builder, | ||
53 | - {String? tag, bool permanent = false}) { | ||
54 | - return BindingsBuilder( | ||
55 | - () => GetInstance().put<T>(builder(), tag: tag, permanent: permanent)); | ||
56 | - } | 39 | +// /// Shortcut to register 1 Controller with Get.put(), |
40 | +// /// Prevents the issue of the fat arrow function with the constructor. | ||
41 | +// /// BindingsBuilder(() => Get.put(HomeController())), | ||
42 | +// /// | ||
43 | +// /// Sample: | ||
44 | +// /// ``` | ||
45 | +// /// GetPage( | ||
46 | +// /// name: '/', | ||
47 | +// /// page: () => Home(), | ||
48 | +// /// binding: BindingsBuilder.put(() => HomeController()), | ||
49 | +// /// ), | ||
50 | +// /// ``` | ||
51 | +// factory BindingsBuilder.put(InstanceBuilderCallback<T> builder, | ||
52 | +// {String? tag, bool permanent = false}) { | ||
53 | +// return BindingsBuilder( | ||
54 | +// () => Get.put<T>(builder(), tag: tag, permanent: permanent)); | ||
55 | +// } | ||
57 | 56 | ||
58 | - /// WARNING: don't use `()=> Get.put(Controller())`, | ||
59 | - /// if only passing 1 callback use `BindingsBuilder.put(Controller())` | ||
60 | - /// or `BindingsBuilder(()=> Get.lazyPut(Controller()))` | ||
61 | - BindingsBuilder(this.builder); | 57 | +// /// WARNING: don't use `()=> Get.put(Controller())`, |
58 | +// /// if only passing 1 callback use `BindingsBuilder.put(Controller())` | ||
59 | +// /// or `BindingsBuilder(()=> Get.lazyPut(Controller()))` | ||
60 | +// BindingsBuilder(this.builder); | ||
62 | 61 | ||
63 | - @override | ||
64 | - void dependencies() { | ||
65 | - builder(); | ||
66 | - } | ||
67 | -} | 62 | +// @override |
63 | +// void dependencies() { | ||
64 | +// builder(); | ||
65 | +// } | ||
66 | +// } | ||
68 | 67 | ||
69 | typedef BindingBuilderCallback = void Function(); | 68 | typedef BindingBuilderCallback = void Function(); |
1 | -import '../../route_manager.dart'; | ||
2 | -import 'get_instance.dart'; | 1 | +import 'dart:async'; |
2 | + | ||
3 | +import '../../get_core/get_core.dart'; | ||
4 | +import '../../get_navigation/src/router_report.dart'; | ||
5 | +import 'lifecycle.dart'; | ||
6 | + | ||
7 | +class InstanceInfo { | ||
8 | + final bool? isPermanent; | ||
9 | + final bool? isSingleton; | ||
10 | + bool get isCreate => !isSingleton!; | ||
11 | + final bool isRegistered; | ||
12 | + final bool isPrepared; | ||
13 | + final bool? isInit; | ||
14 | + const InstanceInfo({ | ||
15 | + required this.isPermanent, | ||
16 | + required this.isSingleton, | ||
17 | + required this.isRegistered, | ||
18 | + required this.isPrepared, | ||
19 | + required this.isInit, | ||
20 | + }); | ||
21 | +} | ||
3 | 22 | ||
4 | extension Inst on GetInterface { | 23 | extension Inst on GetInterface { |
24 | + T call<T>() => find<T>(); | ||
25 | + | ||
26 | + /// Holds references to every registered Instance when using | ||
27 | + /// `Get.put()` | ||
28 | + static final Map<String, _InstanceBuilderFactory> _singl = {}; | ||
29 | + | ||
30 | + /// Holds a reference to every registered callback when using | ||
31 | + /// `Get.lazyPut()` | ||
32 | + // static final Map<String, _Lazy> _factory = {}; | ||
33 | + | ||
34 | + // void injector<S>( | ||
35 | + // InjectorBuilderCallback<S> fn, { | ||
36 | + // String? tag, | ||
37 | + // bool fenix = false, | ||
38 | + // // bool permanent = false, | ||
39 | + // }) { | ||
40 | + // lazyPut( | ||
41 | + // () => fn(this), | ||
42 | + // tag: tag, | ||
43 | + // fenix: fenix, | ||
44 | + // // permanent: permanent, | ||
45 | + // ); | ||
46 | + // } | ||
47 | + | ||
48 | + /// async version of `Get.put()`. | ||
49 | + /// Awaits for the resolution of the Future from `builder()` parameter and | ||
50 | + /// stores the Instance returned. | ||
51 | + Future<S> putAsync<S>( | ||
52 | + AsyncInstanceBuilderCallback<S> builder, { | ||
53 | + String? tag, | ||
54 | + bool permanent = false, | ||
55 | + }) async { | ||
56 | + return put<S>(await builder(), tag: tag, permanent: permanent); | ||
57 | + } | ||
58 | + | ||
59 | + /// Injects an instance `<S>` in memory to be globally accessible. | ||
60 | + /// | ||
61 | + /// No need to define the generic type `<S>` as it's inferred from | ||
62 | + /// the [dependency] | ||
63 | + /// | ||
64 | + /// - [dependency] The Instance to be injected. | ||
65 | + /// - [tag] optionally, use a [tag] as an "id" to create multiple records of | ||
66 | + /// the same Type<[S]> | ||
67 | + /// - [permanent] keeps the Instance in memory, not following | ||
68 | + /// `Get.smartManagement` rules. | ||
69 | + S put<S>( | ||
70 | + S dependency, { | ||
71 | + String? tag, | ||
72 | + bool permanent = false, | ||
73 | + }) { | ||
74 | + _insert( | ||
75 | + isSingleton: true, | ||
76 | + name: tag, | ||
77 | + permanent: permanent, | ||
78 | + builder: (() => dependency)); | ||
79 | + return find<S>(tag: tag); | ||
80 | + } | ||
81 | + | ||
5 | /// Creates a new Instance<S> lazily from the `<S>builder()` callback. | 82 | /// Creates a new Instance<S> lazily from the `<S>builder()` callback. |
6 | /// | 83 | /// |
7 | /// The first time you call `Get.find()`, the `builder()` callback will create | 84 | /// The first time you call `Get.find()`, the `builder()` callback will create |
8 | - /// the Instance and persisted as a Singleton (like you would use | ||
9 | - /// `Get.put()`). | 85 | + /// the Instance and persisted as a Singleton (like you would |
86 | + /// use `Get.put()`). | ||
10 | /// | 87 | /// |
11 | /// Using `Get.smartManagement` as [SmartManagement.keepFactory] has | 88 | /// Using `Get.smartManagement` as [SmartManagement.keepFactory] has |
12 | - /// the same outcome | ||
13 | - /// as using `fenix:true` : | 89 | + /// the same outcome as using `fenix:true` : |
14 | /// The internal register of `builder()` will remain in memory to recreate | 90 | /// The internal register of `builder()` will remain in memory to recreate |
15 | /// the Instance if the Instance has been removed with `Get.delete()`. | 91 | /// the Instance if the Instance has been removed with `Get.delete()`. |
16 | /// Therefore, future calls to `Get.find()` will return the same Instance. | 92 | /// Therefore, future calls to `Get.find()` will return the same Instance. |
17 | /// | 93 | /// |
18 | /// If you need to make use of GetxController's life-cycle | 94 | /// If you need to make use of GetxController's life-cycle |
19 | - /// (`onInit(), onStart(), onClose()`) | ||
20 | - /// [fenix] is a great choice to mix with `GetBuilder` and `GetX` widgets, | ||
21 | - /// and/or [GetMaterialApp] Navigation. | 95 | + /// (`onInit(), onStart(), onClose()`) [fenix] is a great choice to mix with |
96 | + /// `GetBuilder()` and `GetX()` widgets, and/or `GetMaterialApp` Navigation. | ||
22 | /// | 97 | /// |
23 | - /// You could use `Get.lazyPut(fenix:true)` in your app's `main()` instead of | ||
24 | - /// `Bindings` for each [GetPage]. | 98 | + /// You could use `Get.lazyPut(fenix:true)` in your app's `main()` instead |
99 | + /// of `Bindings()` for each `GetPage`. | ||
25 | /// And the memory management will be similar. | 100 | /// And the memory management will be similar. |
26 | /// | 101 | /// |
27 | - /// Subsequent calls to `Get.lazyPut` with the same parameters | ||
28 | - /// (`<S>` and optionally [tag] will **not** override the original). | ||
29 | - void lazyPut<S>(InstanceBuilderCallback<S> builder, | ||
30 | - {String? tag, bool fenix = false}) { | ||
31 | - GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); | 102 | + /// Subsequent calls to `Get.lazyPut()` with the same parameters |
103 | + /// (<[S]> and optionally [tag] will **not** override the original). | ||
104 | + void lazyPut<S>( | ||
105 | + InstanceBuilderCallback<S> builder, { | ||
106 | + String? tag, | ||
107 | + bool? fenix, | ||
108 | + bool permanent = false, | ||
109 | + }) { | ||
110 | + _insert( | ||
111 | + isSingleton: true, | ||
112 | + name: tag, | ||
113 | + permanent: permanent, | ||
114 | + builder: builder, | ||
115 | + fenix: fenix ?? Get.smartManagement == SmartManagement.keepFactory, | ||
116 | + ); | ||
32 | } | 117 | } |
33 | 118 | ||
34 | - // void printInstanceStack() { | ||
35 | - // GetInstance().printInstanceStack(); | ||
36 | - // } | ||
37 | - | ||
38 | - /// async version of `Get.put()`. | ||
39 | - /// Awaits for the resolution of the Future from `builder()`parameter and | ||
40 | - /// stores the Instance returned. | ||
41 | - Future<S> putAsync<S>(AsyncInstanceBuilderCallback<S> builder, | ||
42 | - {String? tag, bool permanent = false}) async => | ||
43 | - GetInstance().putAsync<S>(builder, tag: tag, permanent: permanent); | ||
44 | - | ||
45 | /// Creates a new Class Instance [S] from the builder callback[S]. | 119 | /// Creates a new Class Instance [S] from the builder callback[S]. |
46 | - /// Every time `find<S>()` is used, it calls the builder method to generate | 120 | + /// Every time [find]<[S]>() is used, it calls the builder method to generate |
47 | /// a new Instance [S]. | 121 | /// a new Instance [S]. |
48 | /// It also registers each `instance.onClose()` with the current | 122 | /// It also registers each `instance.onClose()` with the current |
49 | - /// Route `GetConfig.currentRoute` to keep the lifecycle active. | 123 | + /// Route `Get.reference` to keep the lifecycle active. |
50 | /// Is important to know that the instances created are only stored per Route. | 124 | /// Is important to know that the instances created are only stored per Route. |
51 | /// So, if you call `Get.delete<T>()` the "instance factory" used in this | 125 | /// So, if you call `Get.delete<T>()` the "instance factory" used in this |
52 | /// method (`Get.create<T>()`) will be removed, but NOT the instances | 126 | /// method (`Get.create<T>()`) will be removed, but NOT the instances |
53 | /// already created by it. | 127 | /// already created by it. |
54 | - /// Uses `tag` as the other methods. | ||
55 | /// | 128 | /// |
56 | /// Example: | 129 | /// Example: |
57 | /// | 130 | /// |
@@ -59,85 +132,169 @@ extension Inst on GetInterface { | @@ -59,85 +132,169 @@ extension Inst on GetInterface { | ||
59 | /// Repl a = find(); | 132 | /// Repl a = find(); |
60 | /// Repl b = find(); | 133 | /// Repl b = find(); |
61 | /// print(a==b); (false)``` | 134 | /// print(a==b); (false)``` |
62 | - void create<S>(InstanceBuilderCallback<S> builder, | ||
63 | - {String? tag, bool permanent = true}) => | ||
64 | - GetInstance().create<S>(builder, tag: tag, permanent: permanent); | 135 | + void create<S>( |
136 | + InstanceBuilderCallback<S> builder, { | ||
137 | + String? tag, | ||
138 | + bool permanent = true, | ||
139 | + }) { | ||
140 | + _insert( | ||
141 | + isSingleton: false, | ||
142 | + name: tag, | ||
143 | + builder: builder, | ||
144 | + permanent: permanent, | ||
145 | + ); | ||
146 | + } | ||
65 | 147 | ||
66 | - /// Finds a Instance of the required Class `<S>`(or [tag]) | ||
67 | - /// In the case of using `Get.create()`, it will generate an Instance | ||
68 | - /// each time you call `Get.find()`. | ||
69 | - S find<S>({String? tag}) => GetInstance().find<S>(tag: tag); | 148 | + /// Injects the Instance [S] builder into the `_singleton` HashMap. |
149 | + void _insert<S>({ | ||
150 | + bool? isSingleton, | ||
151 | + String? name, | ||
152 | + bool permanent = false, | ||
153 | + required InstanceBuilderCallback<S> builder, | ||
154 | + bool fenix = false, | ||
155 | + }) { | ||
156 | + final key = _getKey(S, name); | ||
70 | 157 | ||
71 | - /// Injects an `Instance<S>` in memory. | ||
72 | - /// | ||
73 | - /// No need to define the generic type `<[S]>` as it's inferred | ||
74 | - /// from the [dependency] parameter. | ||
75 | - /// | ||
76 | - /// - [dependency] The Instance to be injected. | ||
77 | - /// - [tag] optionally, use a [tag] as an "id" to create multiple records | ||
78 | - /// of the same `Type<S>` the [tag] does **not** conflict with the same tags | ||
79 | - /// used by other dependencies Types. | ||
80 | - /// - [permanent] keeps the Instance in memory and persist it, | ||
81 | - /// not following `Get.smartManagement` | ||
82 | - /// rules. Although, can be removed by `GetInstance.reset()` | ||
83 | - /// and `Get.delete()` | ||
84 | - /// - [builder] If defined, the [dependency] must be returned from here | ||
85 | - S put<S>(S dependency, | ||
86 | - {String? tag, | ||
87 | - bool permanent = false, | ||
88 | - InstanceBuilderCallback<S>? builder}) => | ||
89 | - GetInstance().put<S>(dependency, tag: tag, permanent: permanent); | 158 | + _InstanceBuilderFactory<S>? dep; |
159 | + if (_singl.containsKey(key)) { | ||
160 | + final _dep = _singl[key]; | ||
161 | + if (_dep == null || !_dep.isDirty) { | ||
162 | + return; | ||
163 | + } else { | ||
164 | + dep = _dep as _InstanceBuilderFactory<S>; | ||
165 | + } | ||
166 | + } | ||
167 | + _singl[key] = _InstanceBuilderFactory<S>( | ||
168 | + isSingleton: isSingleton, | ||
169 | + builderFunc: builder, | ||
170 | + permanent: permanent, | ||
171 | + isInit: false, | ||
172 | + fenix: fenix, | ||
173 | + tag: name, | ||
174 | + lateRemove: dep, | ||
175 | + ); | ||
176 | + } | ||
90 | 177 | ||
91 | - /// Clears all registered instances (and/or tags). | ||
92 | - /// Even the persistent ones. | ||
93 | - /// | ||
94 | - /// - `clearFactory` clears the callbacks registered by `Get.lazyPut()` | ||
95 | - /// - `clearRouteBindings` clears Instances associated with Routes when using | ||
96 | - /// [GetMaterialApp]. | ||
97 | - // bool reset( | ||
98 | - // {@deprecated bool clearFactory = true, | ||
99 | - // @deprecated bool clearRouteBindings = true}) => | ||
100 | - // GetInstance().reset( | ||
101 | - // // ignore: deprecated_member_use_from_same_package | ||
102 | - // clearFactory: clearFactory, | ||
103 | - // // ignore: deprecated_member_use_from_same_package | ||
104 | - // clearRouteBindings: clearRouteBindings); | ||
105 | - | ||
106 | - /// Deletes the `Instance<S>`, cleaning the memory and closes any open | ||
107 | - /// controllers (`DisposableInterface`). | ||
108 | - /// | ||
109 | - /// - [tag] Optional "tag" used to register the Instance | ||
110 | - /// - [force] Will delete an Instance even if marked as `permanent`. | ||
111 | - Future<bool> delete<S>({String? tag, bool force = false}) async => | ||
112 | - GetInstance().delete<S>(tag: tag, force: force); | 178 | + /// Initializes the dependencies for a Class Instance [S] (or tag), |
179 | + /// If its a Controller, it starts the lifecycle process. | ||
180 | + /// Optionally associating the current Route to the lifetime of the instance, | ||
181 | + /// if `Get.smartManagement` is marked as [SmartManagement.full] or | ||
182 | + /// [SmartManagement.keepFactory] | ||
183 | + /// Only flags `isInit` if it's using `Get.create()` | ||
184 | + /// (not for Singletons access). | ||
185 | + /// Returns the instance if not initialized, required for Get.create() to | ||
186 | + /// work properly. | ||
187 | + S? _initDependencies<S>({String? name}) { | ||
188 | + final key = _getKey(S, name); | ||
189 | + final isInit = _singl[key]!.isInit; | ||
190 | + S? i; | ||
191 | + if (!isInit) { | ||
192 | + i = _startController<S>(tag: name); | ||
193 | + if (_singl[key]!.isSingleton!) { | ||
194 | + _singl[key]!.isInit = true; | ||
195 | + if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
196 | + RouterReportManager.instance | ||
197 | + .reportDependencyLinkedToRoute(_getKey(S, name)); | ||
198 | + } | ||
199 | + } | ||
200 | + } | ||
201 | + return i; | ||
202 | + } | ||
113 | 203 | ||
114 | - /// Deletes all Instances, cleaning the memory and closes any open | ||
115 | - /// controllers (`DisposableInterface`). | ||
116 | - /// | ||
117 | - /// - [force] Will delete the Instances even if marked as `permanent`. | ||
118 | - Future<void> deleteAll({bool force = false}) async => | ||
119 | - GetInstance().deleteAll(force: force); | 204 | + InstanceInfo getInstanceInfo<S>({String? tag}) { |
205 | + final build = _getDependency<S>(tag: tag); | ||
120 | 206 | ||
121 | - void reloadAll({bool force = false}) => GetInstance().reloadAll(force: force); | 207 | + return InstanceInfo( |
208 | + isPermanent: build?.permanent, | ||
209 | + isSingleton: build?.isSingleton, | ||
210 | + isRegistered: isRegistered<S>(tag: tag), | ||
211 | + isPrepared: !(build?.isInit ?? true), | ||
212 | + isInit: build?.isInit, | ||
213 | + ); | ||
214 | + } | ||
122 | 215 | ||
123 | - void reload<S>({String? tag, String? key, bool force = false}) => | ||
124 | - GetInstance().reload<S>(tag: tag, key: key, force: force); | 216 | + _InstanceBuilderFactory? _getDependency<S>({String? tag, String? key}) { |
217 | + final newKey = key ?? _getKey(S, tag); | ||
125 | 218 | ||
126 | - /// Checks if a Class `Instance<S>` (or [tag]) is registered in memory. | ||
127 | - /// - [tag] optional, if you use a [tag] to register the Instance. | ||
128 | - bool isRegistered<S>({String? tag}) => | ||
129 | - GetInstance().isRegistered<S>(tag: tag); | 219 | + if (!_singl.containsKey(newKey)) { |
220 | + Get.log('Instance "$newKey" is not registered.', isError: true); | ||
221 | + return null; | ||
222 | + } else { | ||
223 | + return _singl[newKey]; | ||
224 | + } | ||
225 | + } | ||
130 | 226 | ||
131 | - /// Checks if an `Instance<S>` (or [tag]) returned from a factory builder | ||
132 | - /// `Get.lazyPut()`, is registered in memory. | ||
133 | - /// - [tag] optional, if you use a [tag] to register the Instance. | ||
134 | - bool isPrepared<S>({String? tag}) => GetInstance().isPrepared<S>(tag: tag); | 227 | + void markAsDirty<S>({String? tag, String? key}) { |
228 | + final newKey = key ?? _getKey(S, tag); | ||
229 | + if (_singl.containsKey(newKey)) { | ||
230 | + final dep = _singl[newKey]; | ||
231 | + if (dep != null && !dep.permanent) { | ||
232 | + dep.isDirty = true; | ||
233 | + } | ||
234 | + } | ||
235 | + } | ||
236 | + | ||
237 | + /// Initializes the controller | ||
238 | + S _startController<S>({String? tag}) { | ||
239 | + final key = _getKey(S, tag); | ||
240 | + final i = _singl[key]!.getDependency() as S; | ||
241 | + if (i is GetLifeCycleMixin) { | ||
242 | + i.onStart(); | ||
243 | + if (tag == null) { | ||
244 | + Get.log('Instance "$S" has been initialized'); | ||
245 | + } else { | ||
246 | + Get.log('Instance "$S" with tag "$tag" has been initialized'); | ||
247 | + } | ||
248 | + if (!_singl[key]!.isSingleton!) { | ||
249 | + RouterReportManager.instance.appendRouteByCreate(i); | ||
250 | + } | ||
251 | + } | ||
252 | + return i; | ||
253 | + } | ||
254 | + | ||
255 | + S putOrFind<S>(InstanceBuilderCallback<S> dep, {String? tag}) { | ||
256 | + final key = _getKey(S, tag); | ||
257 | + | ||
258 | + if (_singl.containsKey(key)) { | ||
259 | + return _singl[key]!.getDependency() as S; | ||
260 | + } else { | ||
261 | + return put(dep(), tag: tag); | ||
262 | + } | ||
263 | + } | ||
264 | + | ||
265 | + /// Finds the registered type <[S]> (or [tag]) | ||
266 | + /// In case of using Get.[create] to register a type <[S]> or [tag], | ||
267 | + /// it will create an instance each time you call [find]. | ||
268 | + /// If the registered type <[S]> (or [tag]) is a Controller, | ||
269 | + /// it will initialize it's lifecycle. | ||
270 | + S find<S>({String? tag}) { | ||
271 | + final key = _getKey(S, tag); | ||
272 | + if (isRegistered<S>(tag: tag)) { | ||
273 | + final dep = _singl[key]; | ||
274 | + if (dep == null) { | ||
275 | + if (tag == null) { | ||
276 | + throw 'Class "$S" is not registered'; | ||
277 | + } else { | ||
278 | + throw 'Class "$S" with tag "$tag" is not registered'; | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /// although dirty solution, the lifecycle starts inside | ||
283 | + /// `initDependencies`, so we have to return the instance from there | ||
284 | + /// to make it compatible with `Get.create()`. | ||
285 | + final i = _initDependencies<S>(name: tag); | ||
286 | + return i ?? dep.getDependency() as S; | ||
287 | + } else { | ||
288 | + // ignore: lines_longer_than_80_chars | ||
289 | + throw '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"'; | ||
290 | + } | ||
291 | + } | ||
135 | 292 | ||
136 | /// Replace a parent instance of a class in dependency management | 293 | /// Replace a parent instance of a class in dependency management |
137 | /// with a [child] instance | 294 | /// with a [child] instance |
138 | /// - [tag] optional, if you use a [tag] to register the Instance. | 295 | /// - [tag] optional, if you use a [tag] to register the Instance. |
139 | void replace<P>(P child, {String? tag}) { | 296 | void replace<P>(P child, {String? tag}) { |
140 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 297 | + final info = getInstanceInfo<P>(tag: tag); |
141 | final permanent = (info.isPermanent ?? false); | 298 | final permanent = (info.isPermanent ?? false); |
142 | delete<P>(tag: tag, force: permanent); | 299 | delete<P>(tag: tag, force: permanent); |
143 | put(child, tag: tag, permanent: permanent); | 300 | put(child, tag: tag, permanent: permanent); |
@@ -152,9 +309,251 @@ extension Inst on GetInterface { | @@ -152,9 +309,251 @@ extension Inst on GetInterface { | ||
152 | /// the parent instance was permanent | 309 | /// the parent instance was permanent |
153 | void lazyReplace<P>(InstanceBuilderCallback<P> builder, | 310 | void lazyReplace<P>(InstanceBuilderCallback<P> builder, |
154 | {String? tag, bool? fenix}) { | 311 | {String? tag, bool? fenix}) { |
155 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 312 | + final info = getInstanceInfo<P>(tag: tag); |
156 | final permanent = (info.isPermanent ?? false); | 313 | final permanent = (info.isPermanent ?? false); |
157 | delete<P>(tag: tag, force: permanent); | 314 | delete<P>(tag: tag, force: permanent); |
158 | lazyPut(builder, tag: tag, fenix: fenix ?? permanent); | 315 | lazyPut(builder, tag: tag, fenix: fenix ?? permanent); |
159 | } | 316 | } |
317 | + | ||
318 | + /// Generates the key based on [type] (and optionally a [name]) | ||
319 | + /// to register an Instance Builder in the hashmap. | ||
320 | + String _getKey(Type type, String? name) { | ||
321 | + return name == null ? type.toString() : type.toString() + name; | ||
322 | + } | ||
323 | + | ||
324 | + /// Clears all registered instances (and/or tags). | ||
325 | + /// Even the persistent ones. | ||
326 | + /// This should be used at the end or tearDown of unit tests. | ||
327 | + /// | ||
328 | + /// `clearFactory` clears the callbacks registered by [lazyPut] | ||
329 | + /// `clearRouteBindings` clears Instances associated with routes. | ||
330 | + /// | ||
331 | + bool resetInstance({bool clearRouteBindings = true}) { | ||
332 | + // if (clearFactory) _factory.clear(); | ||
333 | + // deleteAll(force: true); | ||
334 | + if (clearRouteBindings) RouterReportManager.instance.clearRouteKeys(); | ||
335 | + _singl.clear(); | ||
336 | + | ||
337 | + return true; | ||
338 | + } | ||
339 | + | ||
340 | + /// Delete registered Class Instance [S] (or [tag]) and, closes any open | ||
341 | + /// controllers `DisposableInterface`, cleans up the memory | ||
342 | + /// | ||
343 | + /// /// Deletes the Instance<[S]>, cleaning the memory. | ||
344 | + // /// | ||
345 | + // /// - [tag] Optional "tag" used to register the Instance | ||
346 | + // /// - [key] For internal usage, is the processed key used to register | ||
347 | + // /// the Instance. **don't use** it unless you know what you are doing. | ||
348 | + | ||
349 | + /// Deletes the Instance<[S]>, cleaning the memory and closes any open | ||
350 | + /// controllers (`DisposableInterface`). | ||
351 | + /// | ||
352 | + /// - [tag] Optional "tag" used to register the Instance | ||
353 | + /// - [key] For internal usage, is the processed key used to register | ||
354 | + /// the Instance. **don't use** it unless you know what you are doing. | ||
355 | + /// - [force] Will delete an Instance even if marked as `permanent`. | ||
356 | + bool delete<S>({String? tag, String? key, bool force = false}) { | ||
357 | + final newKey = key ?? _getKey(S, tag); | ||
358 | + | ||
359 | + if (!_singl.containsKey(newKey)) { | ||
360 | + Get.log('Instance "$newKey" already removed.', isError: true); | ||
361 | + return false; | ||
362 | + } | ||
363 | + | ||
364 | + final dep = _singl[newKey]; | ||
365 | + | ||
366 | + if (dep == null) return false; | ||
367 | + | ||
368 | + final _InstanceBuilderFactory builder; | ||
369 | + if (dep.isDirty) { | ||
370 | + builder = dep.lateRemove ?? dep; | ||
371 | + } else { | ||
372 | + builder = dep; | ||
373 | + } | ||
374 | + | ||
375 | + if (builder.permanent && !force) { | ||
376 | + Get.log( | ||
377 | + // ignore: lines_longer_than_80_chars | ||
378 | + '"$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.', | ||
379 | + isError: true, | ||
380 | + ); | ||
381 | + return false; | ||
382 | + } | ||
383 | + final i = builder.dependency; | ||
384 | + | ||
385 | + if (i is GetxServiceMixin && !force) { | ||
386 | + return false; | ||
387 | + } | ||
388 | + | ||
389 | + if (i is GetLifeCycleMixin) { | ||
390 | + i.onDelete(); | ||
391 | + Get.log('"$newKey" onDelete() called'); | ||
392 | + } | ||
393 | + | ||
394 | + if (builder.fenix) { | ||
395 | + builder.dependency = null; | ||
396 | + builder.isInit = false; | ||
397 | + return true; | ||
398 | + } else { | ||
399 | + if (dep.lateRemove != null) { | ||
400 | + dep.lateRemove = null; | ||
401 | + Get.log('"$newKey" deleted from memory'); | ||
402 | + return false; | ||
403 | + } else { | ||
404 | + _singl.remove(newKey); | ||
405 | + if (_singl.containsKey(newKey)) { | ||
406 | + Get.log('Error removing object "$newKey"', isError: true); | ||
407 | + } else { | ||
408 | + Get.log('"$newKey" deleted from memory'); | ||
409 | + } | ||
410 | + return true; | ||
411 | + } | ||
412 | + } | ||
413 | + } | ||
414 | + | ||
415 | + /// Delete all registered Class Instances and, closes any open | ||
416 | + /// controllers `DisposableInterface`, cleans up the memory | ||
417 | + /// | ||
418 | + /// - [force] Will delete the Instances even if marked as `permanent`. | ||
419 | + void deleteAll({bool force = false}) { | ||
420 | + final keys = _singl.keys.toList(); | ||
421 | + for (final key in keys) { | ||
422 | + delete(key: key, force: force); | ||
423 | + } | ||
424 | + } | ||
425 | + | ||
426 | + void reloadAll({bool force = false}) { | ||
427 | + _singl.forEach((key, value) { | ||
428 | + if (value.permanent && !force) { | ||
429 | + Get.log('Instance "$key" is permanent. Skipping reload'); | ||
430 | + } else { | ||
431 | + value.dependency = null; | ||
432 | + value.isInit = false; | ||
433 | + Get.log('Instance "$key" was reloaded.'); | ||
434 | + } | ||
435 | + }); | ||
436 | + } | ||
437 | + | ||
438 | + void reload<S>({ | ||
439 | + String? tag, | ||
440 | + String? key, | ||
441 | + bool force = false, | ||
442 | + }) { | ||
443 | + final newKey = key ?? _getKey(S, tag); | ||
444 | + | ||
445 | + final builder = _getDependency<S>(tag: tag, key: newKey); | ||
446 | + if (builder == null) return; | ||
447 | + | ||
448 | + if (builder.permanent && !force) { | ||
449 | + Get.log( | ||
450 | + '''Instance "$newKey" is permanent. Use [force = true] to force the restart.''', | ||
451 | + isError: true, | ||
452 | + ); | ||
453 | + return; | ||
454 | + } | ||
455 | + | ||
456 | + final i = builder.dependency; | ||
457 | + | ||
458 | + if (i is GetxServiceMixin && !force) { | ||
459 | + return; | ||
460 | + } | ||
461 | + | ||
462 | + if (i is GetLifeCycleMixin) { | ||
463 | + i.onDelete(); | ||
464 | + Get.log('"$newKey" onDelete() called'); | ||
465 | + } | ||
466 | + | ||
467 | + builder.dependency = null; | ||
468 | + builder.isInit = false; | ||
469 | + Get.log('Instance "$newKey" was restarted.'); | ||
470 | + } | ||
471 | + | ||
472 | + /// Check if a Class Instance<[S]> (or [tag]) is registered in memory. | ||
473 | + /// - [tag] is optional, if you used a [tag] to register the Instance. | ||
474 | + bool isRegistered<S>({String? tag}) => _singl.containsKey(_getKey(S, tag)); | ||
475 | + | ||
476 | + /// Checks if a lazy factory callback `Get.lazyPut()` that returns an | ||
477 | + /// Instance<[S]> is registered in memory. | ||
478 | + /// - [tag] is optional, if you used a [tag] to register the lazy Instance. | ||
479 | + bool isPrepared<S>({String? tag}) { | ||
480 | + final newKey = _getKey(S, tag); | ||
481 | + | ||
482 | + final builder = _getDependency<S>(tag: tag, key: newKey); | ||
483 | + if (builder == null) { | ||
484 | + return false; | ||
485 | + } | ||
486 | + | ||
487 | + if (!builder.isInit) { | ||
488 | + return true; | ||
489 | + } | ||
490 | + return false; | ||
491 | + } | ||
492 | +} | ||
493 | + | ||
494 | +typedef InstanceBuilderCallback<S> = S Function(); | ||
495 | + | ||
496 | +// typedef InjectorBuilderCallback<S> = S Function(Inst); | ||
497 | + | ||
498 | +typedef AsyncInstanceBuilderCallback<S> = Future<S> Function(); | ||
499 | + | ||
500 | +/// Internal class to register instances with `Get.put<S>()`. | ||
501 | +class _InstanceBuilderFactory<S> { | ||
502 | + /// Marks the Builder as a single instance. | ||
503 | + /// For reusing [dependency] instead of [builderFunc] | ||
504 | + bool? isSingleton; | ||
505 | + | ||
506 | + /// When fenix mode is avaliable, when a new instance is need | ||
507 | + /// Instance manager will recreate a new instance of S | ||
508 | + bool fenix; | ||
509 | + | ||
510 | + /// Stores the actual object instance when [isSingleton]=true. | ||
511 | + S? dependency; | ||
512 | + | ||
513 | + /// Generates (and regenerates) the instance when [isSingleton]=false. | ||
514 | + /// Usually used by factory methods | ||
515 | + InstanceBuilderCallback<S> builderFunc; | ||
516 | + | ||
517 | + /// Flag to persist the instance in memory, | ||
518 | + /// without considering `Get.smartManagement` | ||
519 | + bool permanent = false; | ||
520 | + | ||
521 | + bool isInit = false; | ||
522 | + | ||
523 | + _InstanceBuilderFactory<S>? lateRemove; | ||
524 | + | ||
525 | + bool isDirty = false; | ||
526 | + | ||
527 | + String? tag; | ||
528 | + | ||
529 | + _InstanceBuilderFactory({ | ||
530 | + required this.isSingleton, | ||
531 | + required this.builderFunc, | ||
532 | + required this.permanent, | ||
533 | + required this.isInit, | ||
534 | + required this.fenix, | ||
535 | + required this.tag, | ||
536 | + required this.lateRemove, | ||
537 | + }); | ||
538 | + | ||
539 | + void _showInitLog() { | ||
540 | + if (tag == null) { | ||
541 | + Get.log('Instance "$S" has been created'); | ||
542 | + } else { | ||
543 | + Get.log('Instance "$S" has been created with tag "$tag"'); | ||
544 | + } | ||
545 | + } | ||
546 | + | ||
547 | + /// Gets the actual instance by it's [builderFunc] or the persisted instance. | ||
548 | + S getDependency() { | ||
549 | + if (isSingleton!) { | ||
550 | + if (dependency == null) { | ||
551 | + _showInitLog(); | ||
552 | + dependency = builderFunc(); | ||
553 | + } | ||
554 | + return dependency!; | ||
555 | + } else { | ||
556 | + return builderFunc(); | ||
557 | + } | ||
558 | + } | ||
160 | } | 559 | } |
1 | -import 'dart:async'; | ||
2 | - | ||
3 | -import '../../get_core/get_core.dart'; | ||
4 | -import '../../get_navigation/src/router_report.dart'; | ||
5 | -import 'lifecycle.dart'; | ||
6 | - | ||
7 | -class InstanceInfo { | ||
8 | - final bool? isPermanent; | ||
9 | - final bool? isSingleton; | ||
10 | - bool get isCreate => !isSingleton!; | ||
11 | - final bool isRegistered; | ||
12 | - final bool isPrepared; | ||
13 | - final bool? isInit; | ||
14 | - const InstanceInfo({ | ||
15 | - required this.isPermanent, | ||
16 | - required this.isSingleton, | ||
17 | - required this.isRegistered, | ||
18 | - required this.isPrepared, | ||
19 | - required this.isInit, | ||
20 | - }); | ||
21 | -} | ||
22 | - | ||
23 | -class GetInstance { | ||
24 | - factory GetInstance() => _getInstance ??= GetInstance._(); | ||
25 | - | ||
26 | - const GetInstance._(); | ||
27 | - | ||
28 | - static GetInstance? _getInstance; | ||
29 | - | ||
30 | - T call<T>() => find<T>(); | ||
31 | - | ||
32 | - /// Holds references to every registered Instance when using | ||
33 | - /// `Get.put()` | ||
34 | - static final Map<String, _InstanceBuilderFactory> _singl = {}; | ||
35 | - | ||
36 | - /// Holds a reference to every registered callback when using | ||
37 | - /// `Get.lazyPut()` | ||
38 | - // static final Map<String, _Lazy> _factory = {}; | ||
39 | - | ||
40 | - void injector<S>( | ||
41 | - InjectorBuilderCallback<S> fn, { | ||
42 | - String? tag, | ||
43 | - bool fenix = false, | ||
44 | - // bool permanent = false, | ||
45 | - }) { | ||
46 | - lazyPut( | ||
47 | - () => fn(this), | ||
48 | - tag: tag, | ||
49 | - fenix: fenix, | ||
50 | - // permanent: permanent, | ||
51 | - ); | ||
52 | - } | ||
53 | - | ||
54 | - /// async version of `Get.put()`. | ||
55 | - /// Awaits for the resolution of the Future from `builder()` parameter and | ||
56 | - /// stores the Instance returned. | ||
57 | - Future<S> putAsync<S>( | ||
58 | - AsyncInstanceBuilderCallback<S> builder, { | ||
59 | - String? tag, | ||
60 | - bool permanent = false, | ||
61 | - }) async { | ||
62 | - return put<S>(await builder(), tag: tag, permanent: permanent); | ||
63 | - } | ||
64 | - | ||
65 | - /// Injects an instance `<S>` in memory to be globally accessible. | ||
66 | - /// | ||
67 | - /// No need to define the generic type `<S>` as it's inferred from | ||
68 | - /// the [dependency] | ||
69 | - /// | ||
70 | - /// - [dependency] The Instance to be injected. | ||
71 | - /// - [tag] optionally, use a [tag] as an "id" to create multiple records of | ||
72 | - /// the same Type<[S]> | ||
73 | - /// - [permanent] keeps the Instance in memory, not following | ||
74 | - /// `Get.smartManagement` rules. | ||
75 | - S put<S>( | ||
76 | - S dependency, { | ||
77 | - String? tag, | ||
78 | - bool permanent = false, | ||
79 | - @deprecated InstanceBuilderCallback<S>? builder, | ||
80 | - }) { | ||
81 | - _insert( | ||
82 | - isSingleton: true, | ||
83 | - name: tag, | ||
84 | - permanent: permanent, | ||
85 | - builder: builder ?? (() => dependency)); | ||
86 | - return find<S>(tag: tag); | ||
87 | - } | ||
88 | - | ||
89 | - /// Creates a new Instance<S> lazily from the `<S>builder()` callback. | ||
90 | - /// | ||
91 | - /// The first time you call `Get.find()`, the `builder()` callback will create | ||
92 | - /// the Instance and persisted as a Singleton (like you would | ||
93 | - /// use `Get.put()`). | ||
94 | - /// | ||
95 | - /// Using `Get.smartManagement` as [SmartManagement.keepFactory] has | ||
96 | - /// the same outcome as using `fenix:true` : | ||
97 | - /// The internal register of `builder()` will remain in memory to recreate | ||
98 | - /// the Instance if the Instance has been removed with `Get.delete()`. | ||
99 | - /// Therefore, future calls to `Get.find()` will return the same Instance. | ||
100 | - /// | ||
101 | - /// If you need to make use of GetxController's life-cycle | ||
102 | - /// (`onInit(), onStart(), onClose()`) [fenix] is a great choice to mix with | ||
103 | - /// `GetBuilder()` and `GetX()` widgets, and/or `GetMaterialApp` Navigation. | ||
104 | - /// | ||
105 | - /// You could use `Get.lazyPut(fenix:true)` in your app's `main()` instead | ||
106 | - /// of `Bindings()` for each `GetPage`. | ||
107 | - /// And the memory management will be similar. | ||
108 | - /// | ||
109 | - /// Subsequent calls to `Get.lazyPut()` with the same parameters | ||
110 | - /// (<[S]> and optionally [tag] will **not** override the original). | ||
111 | - void lazyPut<S>( | ||
112 | - InstanceBuilderCallback<S> builder, { | ||
113 | - String? tag, | ||
114 | - bool? fenix, | ||
115 | - bool permanent = false, | ||
116 | - }) { | ||
117 | - _insert( | ||
118 | - isSingleton: true, | ||
119 | - name: tag, | ||
120 | - permanent: permanent, | ||
121 | - builder: builder, | ||
122 | - fenix: fenix ?? Get.smartManagement == SmartManagement.keepFactory, | ||
123 | - ); | ||
124 | - } | ||
125 | - | ||
126 | - /// Creates a new Class Instance [S] from the builder callback[S]. | ||
127 | - /// Every time [find]<[S]>() is used, it calls the builder method to generate | ||
128 | - /// a new Instance [S]. | ||
129 | - /// It also registers each `instance.onClose()` with the current | ||
130 | - /// Route `Get.reference` to keep the lifecycle active. | ||
131 | - /// Is important to know that the instances created are only stored per Route. | ||
132 | - /// So, if you call `Get.delete<T>()` the "instance factory" used in this | ||
133 | - /// method (`Get.create<T>()`) will be removed, but NOT the instances | ||
134 | - /// already created by it. | ||
135 | - /// | ||
136 | - /// Example: | ||
137 | - /// | ||
138 | - /// ```create(() => Repl()); | ||
139 | - /// Repl a = find(); | ||
140 | - /// Repl b = find(); | ||
141 | - /// print(a==b); (false)``` | ||
142 | - void create<S>( | ||
143 | - InstanceBuilderCallback<S> builder, { | ||
144 | - String? tag, | ||
145 | - bool permanent = true, | ||
146 | - }) { | ||
147 | - _insert( | ||
148 | - isSingleton: false, | ||
149 | - name: tag, | ||
150 | - builder: builder, | ||
151 | - permanent: permanent, | ||
152 | - ); | ||
153 | - } | ||
154 | - | ||
155 | - /// Injects the Instance [S] builder into the `_singleton` HashMap. | ||
156 | - void _insert<S>({ | ||
157 | - bool? isSingleton, | ||
158 | - String? name, | ||
159 | - bool permanent = false, | ||
160 | - required InstanceBuilderCallback<S> builder, | ||
161 | - bool fenix = false, | ||
162 | - }) { | ||
163 | - final key = _getKey(S, name); | ||
164 | - | ||
165 | - _InstanceBuilderFactory<S>? dep; | ||
166 | - if (_singl.containsKey(key)) { | ||
167 | - final _dep = _singl[key]; | ||
168 | - if (_dep == null || !_dep.isDirty) { | ||
169 | - return; | ||
170 | - } else { | ||
171 | - dep = _dep as _InstanceBuilderFactory<S>; | ||
172 | - } | ||
173 | - } | ||
174 | - _singl[key] = _InstanceBuilderFactory<S>( | ||
175 | - isSingleton: isSingleton, | ||
176 | - builderFunc: builder, | ||
177 | - permanent: permanent, | ||
178 | - isInit: false, | ||
179 | - fenix: fenix, | ||
180 | - tag: name, | ||
181 | - lateRemove: dep, | ||
182 | - ); | ||
183 | - } | ||
184 | - | ||
185 | - /// Initializes the dependencies for a Class Instance [S] (or tag), | ||
186 | - /// If its a Controller, it starts the lifecycle process. | ||
187 | - /// Optionally associating the current Route to the lifetime of the instance, | ||
188 | - /// if `Get.smartManagement` is marked as [SmartManagement.full] or | ||
189 | - /// [SmartManagement.keepFactory] | ||
190 | - /// Only flags `isInit` if it's using `Get.create()` | ||
191 | - /// (not for Singletons access). | ||
192 | - /// Returns the instance if not initialized, required for Get.create() to | ||
193 | - /// work properly. | ||
194 | - S? _initDependencies<S>({String? name}) { | ||
195 | - final key = _getKey(S, name); | ||
196 | - final isInit = _singl[key]!.isInit; | ||
197 | - S? i; | ||
198 | - if (!isInit) { | ||
199 | - i = _startController<S>(tag: name); | ||
200 | - if (_singl[key]!.isSingleton!) { | ||
201 | - _singl[key]!.isInit = true; | ||
202 | - if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
203 | - RouterReportManager.instance | ||
204 | - .reportDependencyLinkedToRoute(_getKey(S, name)); | ||
205 | - } | ||
206 | - } | ||
207 | - } | ||
208 | - return i; | ||
209 | - } | ||
210 | - | ||
211 | - InstanceInfo getInstanceInfo<S>({String? tag}) { | ||
212 | - final build = _getDependency<S>(tag: tag); | ||
213 | - | ||
214 | - return InstanceInfo( | ||
215 | - isPermanent: build?.permanent, | ||
216 | - isSingleton: build?.isSingleton, | ||
217 | - isRegistered: isRegistered<S>(tag: tag), | ||
218 | - isPrepared: !(build?.isInit ?? true), | ||
219 | - isInit: build?.isInit, | ||
220 | - ); | ||
221 | - } | ||
222 | - | ||
223 | - _InstanceBuilderFactory? _getDependency<S>({String? tag, String? key}) { | ||
224 | - final newKey = key ?? _getKey(S, tag); | ||
225 | - | ||
226 | - if (!_singl.containsKey(newKey)) { | ||
227 | - Get.log('Instance "$newKey" is not registered.', isError: true); | ||
228 | - return null; | ||
229 | - } else { | ||
230 | - return _singl[newKey]; | ||
231 | - } | ||
232 | - } | ||
233 | - | ||
234 | - void markAsDirty<S>({String? tag, String? key}) { | ||
235 | - final newKey = key ?? _getKey(S, tag); | ||
236 | - if (_singl.containsKey(newKey)) { | ||
237 | - final dep = _singl[newKey]; | ||
238 | - if (dep != null && !dep.permanent) { | ||
239 | - dep.isDirty = true; | ||
240 | - } | ||
241 | - } | ||
242 | - } | ||
243 | - | ||
244 | - /// Initializes the controller | ||
245 | - S _startController<S>({String? tag}) { | ||
246 | - final key = _getKey(S, tag); | ||
247 | - final i = _singl[key]!.getDependency() as S; | ||
248 | - if (i is GetLifeCycleMixin) { | ||
249 | - i.onStart(); | ||
250 | - if (tag == null) { | ||
251 | - Get.log('Instance "$S" has been initialized'); | ||
252 | - } else { | ||
253 | - Get.log('Instance "$S" with tag "$tag" has been initialized'); | ||
254 | - } | ||
255 | - if (!_singl[key]!.isSingleton!) { | ||
256 | - RouterReportManager.instance.appendRouteByCreate(i); | ||
257 | - } | ||
258 | - } | ||
259 | - return i; | ||
260 | - } | ||
261 | - | ||
262 | - S putOrFind<S>(InstanceBuilderCallback<S> dep, {String? tag}) { | ||
263 | - final key = _getKey(S, tag); | ||
264 | - | ||
265 | - if (_singl.containsKey(key)) { | ||
266 | - return _singl[key]!.getDependency() as S; | ||
267 | - } else { | ||
268 | - return GetInstance().put(dep(), tag: tag); | ||
269 | - } | ||
270 | - } | ||
271 | - | ||
272 | - /// Finds the registered type <[S]> (or [tag]) | ||
273 | - /// In case of using Get.[create] to register a type <[S]> or [tag], | ||
274 | - /// it will create an instance each time you call [find]. | ||
275 | - /// If the registered type <[S]> (or [tag]) is a Controller, | ||
276 | - /// it will initialize it's lifecycle. | ||
277 | - S find<S>({String? tag}) { | ||
278 | - final key = _getKey(S, tag); | ||
279 | - if (isRegistered<S>(tag: tag)) { | ||
280 | - final dep = _singl[key]; | ||
281 | - if (dep == null) { | ||
282 | - if (tag == null) { | ||
283 | - throw 'Class "$S" is not registered'; | ||
284 | - } else { | ||
285 | - throw 'Class "$S" with tag "$tag" is not registered'; | ||
286 | - } | ||
287 | - } | ||
288 | - | ||
289 | - // if (dep.lateRemove != null) { | ||
290 | - // dep.isDirty = true; | ||
291 | - // if(dep.fenix) | ||
292 | - // } | ||
293 | - | ||
294 | - /// although dirty solution, the lifecycle starts inside | ||
295 | - /// `initDependencies`, so we have to return the instance from there | ||
296 | - /// to make it compatible with `Get.create()`. | ||
297 | - final i = _initDependencies<S>(name: tag); | ||
298 | - return i ?? dep.getDependency() as S; | ||
299 | - } else { | ||
300 | - // ignore: lines_longer_than_80_chars | ||
301 | - throw '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"'; | ||
302 | - } | ||
303 | - } | ||
304 | - | ||
305 | - /// Generates the key based on [type] (and optionally a [name]) | ||
306 | - /// to register an Instance Builder in the hashmap. | ||
307 | - String _getKey(Type type, String? name) { | ||
308 | - return name == null ? type.toString() : type.toString() + name; | ||
309 | - } | ||
310 | - | ||
311 | - /// Clears all registered instances (and/or tags). | ||
312 | - /// Even the persistent ones. | ||
313 | - /// This should be used at the end or tearDown of unit tests. | ||
314 | - /// | ||
315 | - /// `clearFactory` clears the callbacks registered by [lazyPut] | ||
316 | - /// `clearRouteBindings` clears Instances associated with routes. | ||
317 | - /// | ||
318 | - bool resetInstance( | ||
319 | - {@deprecated bool clearFactory = true, bool clearRouteBindings = true}) { | ||
320 | - // if (clearFactory) _factory.clear(); | ||
321 | - // deleteAll(force: true); | ||
322 | - if (clearRouteBindings) RouterReportManager.instance.clearRouteKeys(); | ||
323 | - _singl.clear(); | ||
324 | - | ||
325 | - return true; | ||
326 | - } | ||
327 | - | ||
328 | - /// Delete registered Class Instance [S] (or [tag]) and, closes any open | ||
329 | - /// controllers `DisposableInterface`, cleans up the memory | ||
330 | - /// | ||
331 | - /// /// Deletes the Instance<[S]>, cleaning the memory. | ||
332 | - // /// | ||
333 | - // /// - [tag] Optional "tag" used to register the Instance | ||
334 | - // /// - [key] For internal usage, is the processed key used to register | ||
335 | - // /// the Instance. **don't use** it unless you know what you are doing. | ||
336 | - | ||
337 | - /// Deletes the Instance<[S]>, cleaning the memory and closes any open | ||
338 | - /// controllers (`DisposableInterface`). | ||
339 | - /// | ||
340 | - /// - [tag] Optional "tag" used to register the Instance | ||
341 | - /// - [key] For internal usage, is the processed key used to register | ||
342 | - /// the Instance. **don't use** it unless you know what you are doing. | ||
343 | - /// - [force] Will delete an Instance even if marked as `permanent`. | ||
344 | - bool delete<S>({String? tag, String? key, bool force = false}) { | ||
345 | - final newKey = key ?? _getKey(S, tag); | ||
346 | - | ||
347 | - if (!_singl.containsKey(newKey)) { | ||
348 | - Get.log('Instance "$newKey" already removed.', isError: true); | ||
349 | - return false; | ||
350 | - } | ||
351 | - | ||
352 | - final dep = _singl[newKey]; | ||
353 | - | ||
354 | - if (dep == null) return false; | ||
355 | - | ||
356 | - final _InstanceBuilderFactory builder; | ||
357 | - if (dep.isDirty) { | ||
358 | - builder = dep.lateRemove ?? dep; | ||
359 | - } else { | ||
360 | - builder = dep; | ||
361 | - } | ||
362 | - | ||
363 | - if (builder.permanent && !force) { | ||
364 | - Get.log( | ||
365 | - // ignore: lines_longer_than_80_chars | ||
366 | - '"$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.', | ||
367 | - isError: true, | ||
368 | - ); | ||
369 | - return false; | ||
370 | - } | ||
371 | - final i = builder.dependency; | ||
372 | - | ||
373 | - if (i is GetxServiceMixin && !force) { | ||
374 | - return false; | ||
375 | - } | ||
376 | - | ||
377 | - if (i is GetLifeCycleMixin) { | ||
378 | - i.onDelete(); | ||
379 | - Get.log('"$newKey" onDelete() called'); | ||
380 | - } | ||
381 | - | ||
382 | - if (builder.fenix) { | ||
383 | - builder.dependency = null; | ||
384 | - builder.isInit = false; | ||
385 | - return true; | ||
386 | - } else { | ||
387 | - if (dep.lateRemove != null) { | ||
388 | - dep.lateRemove = null; | ||
389 | - Get.log('"$newKey" deleted from memory'); | ||
390 | - return false; | ||
391 | - } else { | ||
392 | - _singl.remove(newKey); | ||
393 | - if (_singl.containsKey(newKey)) { | ||
394 | - Get.log('Error removing object "$newKey"', isError: true); | ||
395 | - } else { | ||
396 | - Get.log('"$newKey" deleted from memory'); | ||
397 | - } | ||
398 | - return true; | ||
399 | - } | ||
400 | - } | ||
401 | - } | ||
402 | - | ||
403 | - /// Delete all registered Class Instances and, closes any open | ||
404 | - /// controllers `DisposableInterface`, cleans up the memory | ||
405 | - /// | ||
406 | - /// - [force] Will delete the Instances even if marked as `permanent`. | ||
407 | - void deleteAll({bool force = false}) { | ||
408 | - final keys = _singl.keys.toList(); | ||
409 | - for (final key in keys) { | ||
410 | - delete(key: key, force: force); | ||
411 | - } | ||
412 | - } | ||
413 | - | ||
414 | - void reloadAll({bool force = false}) { | ||
415 | - _singl.forEach((key, value) { | ||
416 | - if (value.permanent && !force) { | ||
417 | - Get.log('Instance "$key" is permanent. Skipping reload'); | ||
418 | - } else { | ||
419 | - value.dependency = null; | ||
420 | - value.isInit = false; | ||
421 | - Get.log('Instance "$key" was reloaded.'); | ||
422 | - } | ||
423 | - }); | ||
424 | - } | ||
425 | - | ||
426 | - void reload<S>({ | ||
427 | - String? tag, | ||
428 | - String? key, | ||
429 | - bool force = false, | ||
430 | - }) { | ||
431 | - final newKey = key ?? _getKey(S, tag); | ||
432 | - | ||
433 | - final builder = _getDependency<S>(tag: tag, key: newKey); | ||
434 | - if (builder == null) return; | ||
435 | - | ||
436 | - if (builder.permanent && !force) { | ||
437 | - Get.log( | ||
438 | - '''Instance "$newKey" is permanent. Use [force = true] to force the restart.''', | ||
439 | - isError: true, | ||
440 | - ); | ||
441 | - return; | ||
442 | - } | ||
443 | - | ||
444 | - final i = builder.dependency; | ||
445 | - | ||
446 | - if (i is GetxServiceMixin && !force) { | ||
447 | - return; | ||
448 | - } | ||
449 | - | ||
450 | - if (i is GetLifeCycleMixin) { | ||
451 | - i.onDelete(); | ||
452 | - Get.log('"$newKey" onDelete() called'); | ||
453 | - } | ||
454 | - | ||
455 | - builder.dependency = null; | ||
456 | - builder.isInit = false; | ||
457 | - Get.log('Instance "$newKey" was restarted.'); | ||
458 | - } | ||
459 | - | ||
460 | - /// Check if a Class Instance<[S]> (or [tag]) is registered in memory. | ||
461 | - /// - [tag] is optional, if you used a [tag] to register the Instance. | ||
462 | - bool isRegistered<S>({String? tag}) => _singl.containsKey(_getKey(S, tag)); | ||
463 | - | ||
464 | - /// Checks if a lazy factory callback `Get.lazyPut()` that returns an | ||
465 | - /// Instance<[S]> is registered in memory. | ||
466 | - /// - [tag] is optional, if you used a [tag] to register the lazy Instance. | ||
467 | - bool isPrepared<S>({String? tag}) { | ||
468 | - final newKey = _getKey(S, tag); | ||
469 | - | ||
470 | - final builder = _getDependency<S>(tag: tag, key: newKey); | ||
471 | - if (builder == null) { | ||
472 | - return false; | ||
473 | - } | ||
474 | - | ||
475 | - if (!builder.isInit) { | ||
476 | - return true; | ||
477 | - } | ||
478 | - return false; | ||
479 | - } | ||
480 | -} | ||
481 | - | ||
482 | -typedef InstanceBuilderCallback<S> = S Function(); | ||
483 | - | ||
484 | -typedef InjectorBuilderCallback<S> = S Function(GetInstance); | ||
485 | - | ||
486 | -typedef AsyncInstanceBuilderCallback<S> = Future<S> Function(); | ||
487 | - | ||
488 | -/// Internal class to register instances with `Get.put<S>()`. | ||
489 | -class _InstanceBuilderFactory<S> { | ||
490 | - /// Marks the Builder as a single instance. | ||
491 | - /// For reusing [dependency] instead of [builderFunc] | ||
492 | - bool? isSingleton; | ||
493 | - | ||
494 | - /// When fenix mode is avaliable, when a new instance is need | ||
495 | - /// Instance manager will recreate a new instance of S | ||
496 | - bool fenix; | ||
497 | - | ||
498 | - /// Stores the actual object instance when [isSingleton]=true. | ||
499 | - S? dependency; | ||
500 | - | ||
501 | - /// Generates (and regenerates) the instance when [isSingleton]=false. | ||
502 | - /// Usually used by factory methods | ||
503 | - InstanceBuilderCallback<S> builderFunc; | ||
504 | - | ||
505 | - /// Flag to persist the instance in memory, | ||
506 | - /// without considering `Get.smartManagement` | ||
507 | - bool permanent = false; | ||
508 | - | ||
509 | - bool isInit = false; | ||
510 | - | ||
511 | - _InstanceBuilderFactory<S>? lateRemove; | ||
512 | - | ||
513 | - bool isDirty = false; | ||
514 | - | ||
515 | - String? tag; | ||
516 | - | ||
517 | - _InstanceBuilderFactory({ | ||
518 | - required this.isSingleton, | ||
519 | - required this.builderFunc, | ||
520 | - required this.permanent, | ||
521 | - required this.isInit, | ||
522 | - required this.fenix, | ||
523 | - required this.tag, | ||
524 | - required this.lateRemove, | ||
525 | - }); | ||
526 | - | ||
527 | - void _showInitLog() { | ||
528 | - if (tag == null) { | ||
529 | - Get.log('Instance "$S" has been created'); | ||
530 | - } else { | ||
531 | - Get.log('Instance "$S" has been created with tag "$tag"'); | ||
532 | - } | ||
533 | - } | ||
534 | - | ||
535 | - /// Gets the actual instance by it's [builderFunc] or the persisted instance. | ||
536 | - S getDependency() { | ||
537 | - if (isSingleton!) { | ||
538 | - if (dependency == null) { | ||
539 | - _showInitLog(); | ||
540 | - dependency = builderFunc(); | ||
541 | - } | ||
542 | - return dependency!; | ||
543 | - } else { | ||
544 | - return builderFunc(); | ||
545 | - } | ||
546 | - } | ||
547 | -} |
@@ -304,8 +304,8 @@ extension ExtensionSnackbar on GetInterface { | @@ -304,8 +304,8 @@ extension ExtensionSnackbar on GetInterface { | ||
304 | AnimationController? progressIndicatorController, | 304 | AnimationController? progressIndicatorController, |
305 | Color? progressIndicatorBackgroundColor, | 305 | Color? progressIndicatorBackgroundColor, |
306 | Animation<Color>? progressIndicatorValueColor, | 306 | Animation<Color>? progressIndicatorValueColor, |
307 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
308 | - SnackStyle snackStyle = SnackStyle.FLOATING, | 307 | + SnackPosition snackPosition = SnackPosition.bottom, |
308 | + SnackStyle snackStyle = SnackStyle.floating, | ||
309 | Curve forwardAnimationCurve = Curves.easeOutCirc, | 309 | Curve forwardAnimationCurve = Curves.easeOutCirc, |
310 | Curve reverseAnimationCurve = Curves.easeOutCirc, | 310 | Curve reverseAnimationCurve = Curves.easeOutCirc, |
311 | Duration animationDuration = const Duration(seconds: 1), | 311 | Duration animationDuration = const Duration(seconds: 1), |
@@ -432,7 +432,7 @@ extension ExtensionSnackbar on GetInterface { | @@ -432,7 +432,7 @@ extension ExtensionSnackbar on GetInterface { | ||
432 | fontSize: 14, | 432 | fontSize: 14, |
433 | ), | 433 | ), |
434 | ), | 434 | ), |
435 | - snackPosition: snackPosition ?? SnackPosition.TOP, | 435 | + snackPosition: snackPosition ?? SnackPosition.top, |
436 | borderRadius: borderRadius ?? 15, | 436 | borderRadius: borderRadius ?? 15, |
437 | margin: margin ?? EdgeInsets.symmetric(horizontal: 10), | 437 | margin: margin ?? EdgeInsets.symmetric(horizontal: 10), |
438 | duration: duration, | 438 | duration: duration, |
@@ -455,7 +455,7 @@ extension ExtensionSnackbar on GetInterface { | @@ -455,7 +455,7 @@ extension ExtensionSnackbar on GetInterface { | ||
455 | progressIndicatorController: progressIndicatorController, | 455 | progressIndicatorController: progressIndicatorController, |
456 | progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, | 456 | progressIndicatorBackgroundColor: progressIndicatorBackgroundColor, |
457 | progressIndicatorValueColor: progressIndicatorValueColor, | 457 | progressIndicatorValueColor: progressIndicatorValueColor, |
458 | - snackStyle: snackStyle ?? SnackStyle.FLOATING, | 458 | + snackStyle: snackStyle ?? SnackStyle.floating, |
459 | forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc, | 459 | forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc, |
460 | reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc, | 460 | reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc, |
461 | animationDuration: animationDuration ?? Duration(seconds: 1), | 461 | animationDuration: animationDuration ?? Duration(seconds: 1), |
@@ -498,7 +498,7 @@ extension GetNavigationExt on GetInterface { | @@ -498,7 +498,7 @@ extension GetNavigationExt on GetInterface { | ||
498 | /// If you want the same behavior of ios that pops a route when the user drag, | 498 | /// If you want the same behavior of ios that pops a route when the user drag, |
499 | /// you can set [popGesture] to true | 499 | /// you can set [popGesture] to true |
500 | /// | 500 | /// |
501 | - /// If you're using the [Bindings] api, you must define it here | 501 | + /// If you're using the [BindingsInterface] api, you must define it here |
502 | /// | 502 | /// |
503 | /// By default, GetX will prevent you from push a route that you already in, | 503 | /// By default, GetX will prevent you from push a route that you already in, |
504 | /// if you want to push anyway, set [preventDuplicates] to false | 504 | /// if you want to push anyway, set [preventDuplicates] to false |
@@ -518,7 +518,7 @@ extension GetNavigationExt on GetInterface { | @@ -518,7 +518,7 @@ extension GetNavigationExt on GetInterface { | ||
518 | double Function(BuildContext context)? gestureWidth, | 518 | double Function(BuildContext context)? gestureWidth, |
519 | bool rebuildStack = true, | 519 | bool rebuildStack = true, |
520 | PreventDuplicateHandlingMode preventDuplicateHandlingMode = | 520 | PreventDuplicateHandlingMode preventDuplicateHandlingMode = |
521 | - PreventDuplicateHandlingMode.ReorderRoutes}) { | 521 | + PreventDuplicateHandlingMode.reorderRoutes}) { |
522 | return searchDelegate(id).to( | 522 | return searchDelegate(id).to( |
523 | page, | 523 | page, |
524 | opaque: opaque, | 524 | opaque: opaque, |
@@ -876,7 +876,7 @@ extension GetNavigationExt on GetInterface { | @@ -876,7 +876,7 @@ extension GetNavigationExt on GetInterface { | ||
876 | /// If you want the same behavior of ios that pops a route when the user drag, | 876 | /// If you want the same behavior of ios that pops a route when the user drag, |
877 | /// you can set [popGesture] to true | 877 | /// you can set [popGesture] to true |
878 | /// | 878 | /// |
879 | - /// If you're using the [Bindings] api, you must define it here | 879 | + /// If you're using the [BindingsInterface] api, you must define it here |
880 | /// | 880 | /// |
881 | /// By default, GetX will prevent you from push a route that you already in, | 881 | /// By default, GetX will prevent you from push a route that you already in, |
882 | /// if you want to push anyway, set [preventDuplicates] to false | 882 | /// if you want to push anyway, set [preventDuplicates] to false |
@@ -956,7 +956,7 @@ extension GetNavigationExt on GetInterface { | @@ -956,7 +956,7 @@ extension GetNavigationExt on GetInterface { | ||
956 | /// If you want the same behavior of ios that pops a route when the user drag, | 956 | /// If you want the same behavior of ios that pops a route when the user drag, |
957 | /// you can set [popGesture] to true | 957 | /// you can set [popGesture] to true |
958 | /// | 958 | /// |
959 | - /// If you're using the [Bindings] api, you must define it here | 959 | + /// If you're using the [BindingsInterface] api, you must define it here |
960 | /// | 960 | /// |
961 | /// By default, GetX will prevent you from push a route that you already in, | 961 | /// By default, GetX will prevent you from push a route that you already in, |
962 | /// if you want to push anyway, set [preventDuplicates] to false | 962 | /// if you want to push anyway, set [preventDuplicates] to false |
@@ -1077,18 +1077,7 @@ extension GetNavigationExt on GetInterface { | @@ -1077,18 +1077,7 @@ extension GetNavigationExt on GetInterface { | ||
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | GetDelegate? nestedKey(String? key) { | 1079 | GetDelegate? nestedKey(String? key) { |
1080 | - if (key == null) { | ||
1081 | - return routerDelegate as GetDelegate; | ||
1082 | - } | ||
1083 | - keys.putIfAbsent( | ||
1084 | - key, | ||
1085 | - () => GetDelegate( | ||
1086 | - showHashOnUrl: true, | ||
1087 | - //debugLabel: 'Getx nested key: ${key.toString()}', | ||
1088 | - pages: RouteDecoder.fromRoute(key).currentChildrens ?? [], | ||
1089 | - ), | ||
1090 | - ); | ||
1091 | - return keys[key]; | 1080 | + return _getxController.nestedKey(key); |
1092 | } | 1081 | } |
1093 | 1082 | ||
1094 | GetDelegate searchDelegate(dynamic k) { | 1083 | GetDelegate searchDelegate(dynamic k) { |
@@ -1262,88 +1251,50 @@ extension GetNavigationExt on GetInterface { | @@ -1262,88 +1251,50 @@ extension GetNavigationExt on GetInterface { | ||
1262 | set parameters(Map<String, String?> newParameters) => | 1251 | set parameters(Map<String, String?> newParameters) => |
1263 | _getxController.parameters = newParameters; | 1252 | _getxController.parameters = newParameters; |
1264 | 1253 | ||
1265 | - CustomTransition? get customTransition => _getxController.customTransition; | ||
1266 | - set customTransition(CustomTransition? newTransition) => | ||
1267 | - _getxController.customTransition = newTransition; | 1254 | + |
1268 | 1255 | ||
1269 | bool get testMode => _getxController.testMode; | 1256 | bool get testMode => _getxController.testMode; |
1270 | set testMode(bool isTest) => _getxController.testMode = isTest; | 1257 | set testMode(bool isTest) => _getxController.testMode = isTest; |
1271 | 1258 | ||
1272 | - void resetRootNavigator() { | ||
1273 | - _getxController = GetMaterialController(); | ||
1274 | - } | ||
1275 | - | ||
1276 | - static GetMaterialController _getxController = GetMaterialController(); | ||
1277 | -} | ||
1278 | - | ||
1279 | -extension NavTwoExt on GetInterface { | ||
1280 | - void addPages(List<GetPage> getPages) { | ||
1281 | - routeTree.addRoutes(getPages); | ||
1282 | - } | ||
1283 | - | ||
1284 | - void clearRouteTree() { | ||
1285 | - _routeTree.routes.clear(); | ||
1286 | - } | ||
1287 | - | ||
1288 | - static late final _routeTree = ParseRouteTree(routes: []); | ||
1289 | - | ||
1290 | - ParseRouteTree get routeTree => _routeTree; | 1259 | + /// Casts the stored router delegate to a desired type |
1260 | + TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() => | ||
1261 | + _getxController.routerDelegate as TDelegate?; | ||
1291 | 1262 | ||
1292 | - void addPage(GetPage getPage) { | ||
1293 | - routeTree.addRoute(getPage); | ||
1294 | - } | 1263 | + // void resetRootNavigator() { |
1264 | + // _getxController = GetMaterialController(); | ||
1265 | + // } | ||
1295 | 1266 | ||
1296 | - void removePage(GetPage getPage) { | ||
1297 | - routeTree.removeRoute(getPage); | ||
1298 | - } | 1267 | + // RouterDelegate? get routerDelegate => _getxController.routerDelegate; |
1268 | + // RouteInformationParser? get routeInformationParser => | ||
1269 | + // _getxController.routeInformationParser; | ||
1299 | 1270 | ||
1300 | - /// Casts the stored router delegate to a desired type | ||
1301 | - TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() => | ||
1302 | - routerDelegate as TDelegate?; | 1271 | + GetMaterialController get _getxController => GetMaterialController.to; |
1303 | 1272 | ||
1304 | - // // ignore: use_setters_to_change_properties | ||
1305 | - // void setDefaultDelegate(RouterDelegate? delegate) { | ||
1306 | - // _routerDelegate = delegate; | 1273 | + // void addPages(List<GetPage> getPages) { |
1274 | + // routeTree.addRoutes(getPages); | ||
1307 | // } | 1275 | // } |
1308 | 1276 | ||
1309 | - // GetDelegate? getDelegate() => delegate<GetDelegate, GetNavConfig>(); | 1277 | + // void clearRouteTree() { |
1278 | + // routeTree.routes.clear(); | ||
1279 | + // } | ||
1310 | 1280 | ||
1311 | - GetInformationParser createInformationParser({String initialRoute = '/'}) { | ||
1312 | - if (routeInformationParser == null) { | ||
1313 | - return routeInformationParser = GetInformationParser( | ||
1314 | - initialRoute: initialRoute, | ||
1315 | - ); | ||
1316 | - } else { | ||
1317 | - return routeInformationParser as GetInformationParser; | ||
1318 | - } | ||
1319 | - } | 1281 | + // ParseRouteTree get routeTree { |
1282 | + // final delegate = _getxController.routerDelegate; | ||
1283 | + // if (delegate is GetDelegate) { | ||
1284 | + // return delegate.routeTree; | ||
1285 | + // } else { | ||
1286 | + // //TODO: Urgent: Refactor this | ||
1287 | + // return ParseRouteTree(routes: []); | ||
1288 | + // } | ||
1289 | + // } | ||
1320 | 1290 | ||
1321 | - // static GetDelegate? _delegate; | 1291 | + // void addPage(GetPage getPage) { |
1292 | + // routeTree.addRoute(getPage); | ||
1293 | + // } | ||
1322 | 1294 | ||
1323 | - GetDelegate createDelegate({ | ||
1324 | - GetPage<dynamic>? notFoundRoute, | ||
1325 | - List<GetPage> pages = const [], | ||
1326 | - List<NavigatorObserver>? navigatorObservers, | ||
1327 | - TransitionDelegate<dynamic>? transitionDelegate, | ||
1328 | - PopMode backButtonPopMode = PopMode.History, | ||
1329 | - PreventDuplicateHandlingMode preventDuplicateHandlingMode = | ||
1330 | - PreventDuplicateHandlingMode.ReorderRoutes, | ||
1331 | - GlobalKey<NavigatorState>? navigatorKey, | ||
1332 | - }) { | ||
1333 | - if (routerDelegate == null) { | ||
1334 | - return routerDelegate = GetDelegate( | ||
1335 | - notFoundRoute: notFoundRoute, | ||
1336 | - navigatorObservers: navigatorObservers, | ||
1337 | - transitionDelegate: transitionDelegate, | ||
1338 | - backButtonPopMode: backButtonPopMode, | ||
1339 | - preventDuplicateHandlingMode: preventDuplicateHandlingMode, | ||
1340 | - pages: pages, | ||
1341 | - navigatorKey: navigatorKey, | ||
1342 | - ); | ||
1343 | - } else { | ||
1344 | - return routerDelegate as GetDelegate; | ||
1345 | - } | ||
1346 | - } | 1295 | + // void removePage(GetPage getPage) { |
1296 | + // routeTree.removeRoute(getPage); | ||
1297 | + // } | ||
1347 | } | 1298 | } |
1348 | 1299 | ||
1349 | extension OverlayExt on GetInterface { | 1300 | extension OverlayExt on GetInterface { |
@@ -192,11 +192,11 @@ class GetCupertinoApp extends StatelessWidget { | @@ -192,11 +192,11 @@ class GetCupertinoApp extends StatelessWidget { | ||
192 | init: Get.rootController, | 192 | init: Get.rootController, |
193 | dispose: (d) { | 193 | dispose: (d) { |
194 | onDispose?.call(); | 194 | onDispose?.call(); |
195 | - Get.clearRouteTree(); | ||
196 | - Get.clearTranslations(); | ||
197 | - Get.resetRootNavigator(); | ||
198 | - Get.routerDelegate = null; | ||
199 | - Get.routeInformationParser = null; | 195 | + // Get.clearRouteTree(); |
196 | + // Get.clearTranslations(); | ||
197 | + // Get.resetRootNavigator(); | ||
198 | + // Get.routerDelegate = null; | ||
199 | + // Get.routeInformationParser = null; | ||
200 | }, | 200 | }, |
201 | initState: (i) { | 201 | initState: (i) { |
202 | Get.engine.addPostFrameCallback((timeStamp) { | 202 | Get.engine.addPostFrameCallback((timeStamp) { |
@@ -212,19 +212,19 @@ class GetCupertinoApp extends StatelessWidget { | @@ -212,19 +212,19 @@ class GetCupertinoApp extends StatelessWidget { | ||
212 | Get.addTranslations(translationsKeys!); | 212 | Get.addTranslations(translationsKeys!); |
213 | } | 213 | } |
214 | 214 | ||
215 | - Get.customTransition = customTransition; | 215 | + // Get.customTransition = customTransition; |
216 | 216 | ||
217 | initialBinding?.dependencies(); | 217 | initialBinding?.dependencies(); |
218 | - if (getPages != null) { | ||
219 | - Get.addPages(getPages!); | ||
220 | - } else { | ||
221 | - Get.addPage( | ||
222 | - GetPage( | ||
223 | - name: _cleanRouteName("/${home.runtimeType}"), | ||
224 | - page: () => home!, | ||
225 | - ), | ||
226 | - ); | ||
227 | - } | 218 | + // if (getPages != null) { |
219 | + // Get.addPages(getPages!); | ||
220 | + // } else { | ||
221 | + // Get.addPage( | ||
222 | + // GetPage( | ||
223 | + // name: _cleanRouteName("/${home.runtimeType}"), | ||
224 | + // page: () => home!, | ||
225 | + // ), | ||
226 | + // ); | ||
227 | + // } | ||
228 | 228 | ||
229 | Get.smartManagement = smartManagement; | 229 | Get.smartManagement = smartManagement; |
230 | onInit?.call(); | 230 | onInit?.call(); |
@@ -240,7 +240,7 @@ class GetCupertinoApp extends StatelessWidget { | @@ -240,7 +240,7 @@ class GetCupertinoApp extends StatelessWidget { | ||
240 | ); | 240 | ); |
241 | }, | 241 | }, |
242 | builder: (_) { | 242 | builder: (_) { |
243 | - final routerDelegate = Get.createDelegate( | 243 | + final routerDelegate = _.createDelegate( |
244 | pages: getPages ?? [], | 244 | pages: getPages ?? [], |
245 | notFoundRoute: unknownRoute, | 245 | notFoundRoute: unknownRoute, |
246 | navigatorKey: navigatorKey, | 246 | navigatorKey: navigatorKey, |
@@ -252,7 +252,7 @@ class GetCupertinoApp extends StatelessWidget { | @@ -252,7 +252,7 @@ class GetCupertinoApp extends StatelessWidget { | ||
252 | GetObserver(routingCallback, Get.routing) | 252 | GetObserver(routingCallback, Get.routing) |
253 | ] | 253 | ] |
254 | ..addAll(navigatorObservers!))); | 254 | ..addAll(navigatorObservers!))); |
255 | - final routeInformationParser = Get.createInformationParser( | 255 | + final routeInformationParser = _.createInformationParser( |
256 | initialRoute: initialRoute ?? | 256 | initialRoute: initialRoute ?? |
257 | getPages?.first.name ?? | 257 | getPages?.first.name ?? |
258 | _cleanRouteName("/${home.runtimeType}"), | 258 | _cleanRouteName("/${home.runtimeType}"), |
@@ -297,16 +297,16 @@ class GetCupertinoApp extends StatelessWidget { | @@ -297,16 +297,16 @@ class GetCupertinoApp extends StatelessWidget { | ||
297 | ); | 297 | ); |
298 | } | 298 | } |
299 | 299 | ||
300 | - Route<dynamic> generator(RouteSettings settings) { | ||
301 | - return PageRedirect(settings: settings, unknownRoute: unknownRoute).page(); | ||
302 | - } | 300 | + // Route<dynamic> generator(RouteSettings settings) { |
301 | + // return PageRedirect(settings: settings, unknownRoute: unknownRoute).page(); | ||
302 | + // } | ||
303 | 303 | ||
304 | - List<Route<dynamic>> initialRoutesGenerate(String name) { | ||
305 | - return [ | ||
306 | - PageRedirect( | ||
307 | - settings: RouteSettings(name: name), | ||
308 | - unknownRoute: unknownRoute, | ||
309 | - ).page() | ||
310 | - ]; | ||
311 | - } | 304 | + // List<Route<dynamic>> initialRoutesGenerate(String name) { |
305 | + // return [ | ||
306 | + // PageRedirect( | ||
307 | + // settings: RouteSettings(name: name), | ||
308 | + // unknownRoute: unknownRoute, | ||
309 | + // ).page() | ||
310 | + // ]; | ||
311 | + // } | ||
312 | } | 312 | } |
@@ -6,10 +6,10 @@ import '../../../get_instance/get_instance.dart'; | @@ -6,10 +6,10 @@ import '../../../get_instance/get_instance.dart'; | ||
6 | import '../../../get_state_manager/get_state_manager.dart'; | 6 | import '../../../get_state_manager/get_state_manager.dart'; |
7 | import '../../../get_utils/get_utils.dart'; | 7 | import '../../../get_utils/get_utils.dart'; |
8 | import '../../get_navigation.dart'; | 8 | import '../../get_navigation.dart'; |
9 | +import '../router_report.dart'; | ||
9 | 10 | ||
10 | class GetMaterialApp extends StatelessWidget { | 11 | class GetMaterialApp extends StatelessWidget { |
11 | final GlobalKey<NavigatorState>? navigatorKey; | 12 | final GlobalKey<NavigatorState>? navigatorKey; |
12 | - | ||
13 | final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey; | 13 | final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey; |
14 | final Widget? home; | 14 | final Widget? home; |
15 | final Map<String, WidgetBuilder>? routes; | 15 | final Map<String, WidgetBuilder>? routes; |
@@ -56,7 +56,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -56,7 +56,7 @@ class GetMaterialApp extends StatelessWidget { | ||
56 | final LogWriterCallback? logWriterCallback; | 56 | final LogWriterCallback? logWriterCallback; |
57 | final bool? popGesture; | 57 | final bool? popGesture; |
58 | final SmartManagement smartManagement; | 58 | final SmartManagement smartManagement; |
59 | - final BindingsInterface? initialBinding; | 59 | + final List<Bind> binds; |
60 | final Duration? transitionDuration; | 60 | final Duration? transitionDuration; |
61 | final bool? defaultGlobalState; | 61 | final bool? defaultGlobalState; |
62 | final List<GetPage>? getPages; | 62 | final List<GetPage>? getPages; |
@@ -66,7 +66,8 @@ class GetMaterialApp extends StatelessWidget { | @@ -66,7 +66,8 @@ class GetMaterialApp extends StatelessWidget { | ||
66 | final RouterDelegate<Object>? routerDelegate; | 66 | final RouterDelegate<Object>? routerDelegate; |
67 | final BackButtonDispatcher? backButtonDispatcher; | 67 | final BackButtonDispatcher? backButtonDispatcher; |
68 | final bool useInheritedMediaQuery; | 68 | final bool useInheritedMediaQuery; |
69 | - GetMaterialApp({ | 69 | + |
70 | + const GetMaterialApp({ | ||
70 | Key? key, | 71 | Key? key, |
71 | this.navigatorKey, | 72 | this.navigatorKey, |
72 | this.scaffoldMessengerKey, | 73 | this.scaffoldMessengerKey, |
@@ -118,7 +119,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -118,7 +119,7 @@ class GetMaterialApp extends StatelessWidget { | ||
118 | this.transitionDuration, | 119 | this.transitionDuration, |
119 | this.defaultGlobalState, | 120 | this.defaultGlobalState, |
120 | this.smartManagement = SmartManagement.full, | 121 | this.smartManagement = SmartManagement.full, |
121 | - this.initialBinding, | 122 | + this.binds = const [], |
122 | this.unknownRoute, | 123 | this.unknownRoute, |
123 | this.highContrastTheme, | 124 | this.highContrastTheme, |
124 | this.highContrastDarkTheme, | 125 | this.highContrastDarkTheme, |
@@ -129,17 +130,6 @@ class GetMaterialApp extends StatelessWidget { | @@ -129,17 +130,6 @@ class GetMaterialApp extends StatelessWidget { | ||
129 | routerDelegate = null, | 130 | routerDelegate = null, |
130 | super(key: key); | 131 | super(key: key); |
131 | 132 | ||
132 | - static String _cleanRouteName(String name) { | ||
133 | - name = name.replaceAll('() => ', ''); | ||
134 | - | ||
135 | - /// uncommonent for URL styling. | ||
136 | - // name = name.paramCase!; | ||
137 | - if (!name.startsWith('/')) { | ||
138 | - name = '/$name'; | ||
139 | - } | ||
140 | - return Uri.tryParse(name)?.toString() ?? name; | ||
141 | - } | ||
142 | - | ||
143 | GetMaterialApp.router({ | 133 | GetMaterialApp.router({ |
144 | Key? key, | 134 | Key? key, |
145 | this.routeInformationProvider, | 135 | this.routeInformationProvider, |
@@ -186,7 +176,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -186,7 +176,7 @@ class GetMaterialApp extends StatelessWidget { | ||
186 | this.logWriterCallback, | 176 | this.logWriterCallback, |
187 | this.popGesture, | 177 | this.popGesture, |
188 | this.smartManagement = SmartManagement.full, | 178 | this.smartManagement = SmartManagement.full, |
189 | - this.initialBinding, | 179 | + this.binds = const [], |
190 | this.transitionDuration, | 180 | this.transitionDuration, |
191 | this.defaultGlobalState, | 181 | this.defaultGlobalState, |
192 | this.getPages, | 182 | this.getPages, |
@@ -202,92 +192,80 @@ class GetMaterialApp extends StatelessWidget { | @@ -202,92 +192,80 @@ class GetMaterialApp extends StatelessWidget { | ||
202 | super(key: key); | 192 | super(key: key); |
203 | 193 | ||
204 | @override | 194 | @override |
205 | - Widget build(BuildContext context) => GetBuilder<GetMaterialController>( | ||
206 | - init: Get.rootController, | ||
207 | - dispose: (d) { | ||
208 | - onDispose?.call(); | ||
209 | - Get.clearRouteTree(); | ||
210 | - Get.clearTranslations(); | ||
211 | - Get.resetRootNavigator(); | ||
212 | - Get.routerDelegate = null; | ||
213 | - Get.routeInformationParser = null; | ||
214 | - }, | ||
215 | - initState: (i) { | ||
216 | - // Get.routerDelegate = routerDelegate; | ||
217 | - // Get.routeInformationParser = routeInformationParser; | ||
218 | - Get.engine.addPostFrameCallback((timeStamp) { | ||
219 | - onReady?.call(); | ||
220 | - }); | ||
221 | - if (locale != null) Get.locale = locale; | ||
222 | - | ||
223 | - if (fallbackLocale != null) Get.fallbackLocale = fallbackLocale; | ||
224 | - | ||
225 | - if (translations != null) { | ||
226 | - Get.addTranslations(translations!.keys); | ||
227 | - } else if (translationsKeys != null) { | ||
228 | - Get.addTranslations(translationsKeys!); | ||
229 | - } | ||
230 | - | ||
231 | - Get.customTransition = customTransition; | ||
232 | - | ||
233 | - initialBinding?.dependencies(); | ||
234 | - if (getPages != null) { | ||
235 | - Get.addPages(getPages!); | ||
236 | - } else { | ||
237 | - Get.addPage( | ||
238 | - GetPage( | ||
239 | - name: _cleanRouteName("/${home.runtimeType}"), | ||
240 | - page: () => home!, | 195 | + Widget build(BuildContext context) { |
196 | + return Binds( | ||
197 | + binds: [ | ||
198 | + Bind.lazyPut<GetMaterialController>( | ||
199 | + () => GetMaterialController( | ||
200 | + ConfigData( | ||
201 | + backButtonDispatcher: backButtonDispatcher, | ||
202 | + binds: binds, | ||
203 | + customTransition: customTransition, | ||
204 | + defaultGlobalState: defaultGlobalState, | ||
205 | + defaultTransition: defaultTransition, | ||
206 | + enableLog: enableLog, | ||
207 | + fallbackLocale: fallbackLocale, | ||
208 | + getPages: getPages, | ||
209 | + home: home, | ||
210 | + initialRoute: initialRoute, | ||
211 | + locale: locale, | ||
212 | + logWriterCallback: logWriterCallback, | ||
213 | + navigatorKey: navigatorKey, | ||
214 | + navigatorObservers: navigatorObservers, | ||
215 | + onDispose: onDispose, | ||
216 | + onInit: onInit, | ||
217 | + onReady: onReady, | ||
218 | + opaqueRoute: opaqueRoute, | ||
219 | + popGesture: popGesture, | ||
220 | + routeInformationParser: routeInformationParser, | ||
221 | + routeInformationProvider: routeInformationProvider, | ||
222 | + routerDelegate: routerDelegate, | ||
223 | + routingCallback: routingCallback, | ||
224 | + scaffoldMessengerKey: scaffoldMessengerKey, | ||
225 | + smartManagement: smartManagement, | ||
226 | + transitionDuration: transitionDuration, | ||
227 | + translations: translations, | ||
228 | + translationsKeys: translationsKeys, | ||
229 | + unknownRoute: unknownRoute, | ||
241 | ), | 230 | ), |
242 | - ); | ||
243 | - } | ||
244 | - | ||
245 | - //Get.setDefaultDelegate(routerDelegate); | ||
246 | - Get.smartManagement = smartManagement; | ||
247 | - onInit?.call(); | ||
248 | - | ||
249 | - Get.config( | ||
250 | - enableLog: enableLog ?? Get.isLogEnable, | ||
251 | - logWriterCallback: logWriterCallback, | ||
252 | - defaultTransition: defaultTransition ?? Get.defaultTransition, | ||
253 | - defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault, | ||
254 | - defaultPopGesture: popGesture ?? Get.isPopGestureEnable, | ||
255 | - defaultDurationTransition: | ||
256 | - transitionDuration ?? Get.defaultTransitionDuration, | ||
257 | - ); | ||
258 | - }, | ||
259 | - builder: (_) { | ||
260 | - final routerDelegate = Get.createDelegate( | ||
261 | - pages: getPages ?? [], | ||
262 | - notFoundRoute: unknownRoute, | ||
263 | - navigatorKey: navigatorKey, | ||
264 | - navigatorObservers: (navigatorObservers == null | ||
265 | - ? <NavigatorObserver>[GetObserver(routingCallback, Get.routing)] | ||
266 | - : <NavigatorObserver>[ | ||
267 | - GetObserver(routingCallback, Get.routing), | ||
268 | - ...navigatorObservers! | ||
269 | - ])); | ||
270 | - | ||
271 | - final routeInformationParser = Get.createInformationParser( | ||
272 | - initialRoute: initialRoute ?? | ||
273 | - getPages?.first.name ?? | ||
274 | - _cleanRouteName("/${home.runtimeType}"), | ||
275 | - ); | 231 | + ), |
232 | + onClose: () { | ||
233 | + Get.clearTranslations(); | ||
234 | + RouterReportManager.dispose(); | ||
235 | + Get.resetInstance(clearRouteBindings: true); | ||
236 | + }, | ||
237 | + ), | ||
238 | + ...binds, | ||
239 | + ], | ||
240 | + child: Builder(builder: (context) { | ||
241 | + final controller = context.listen<GetMaterialController>(); | ||
276 | return MaterialApp.router( | 242 | return MaterialApp.router( |
277 | - routerDelegate: routerDelegate, | ||
278 | - routeInformationParser: routeInformationParser, | 243 | + routerDelegate: controller.routerDelegate, |
244 | + routeInformationParser: controller.routeInformationParser, | ||
279 | backButtonDispatcher: backButtonDispatcher, | 245 | backButtonDispatcher: backButtonDispatcher, |
280 | routeInformationProvider: routeInformationProvider, | 246 | routeInformationProvider: routeInformationProvider, |
281 | - key: _.unikey, | ||
282 | - builder: defaultBuilder, | 247 | + key: controller.unikey, |
248 | + builder: (context, child) => Directionality( | ||
249 | + textDirection: textDirection ?? | ||
250 | + (rtlLanguages.contains(Get.locale?.languageCode) | ||
251 | + ? TextDirection.rtl | ||
252 | + : TextDirection.ltr), | ||
253 | + child: builder == null | ||
254 | + ? (child ?? Material()) | ||
255 | + : builder!(context, child ?? Material()), | ||
256 | + ), | ||
283 | title: title, | 257 | title: title, |
284 | onGenerateTitle: onGenerateTitle, | 258 | onGenerateTitle: onGenerateTitle, |
285 | color: color, | 259 | color: color, |
286 | - theme: _.theme ?? theme ?? ThemeData.fallback(), | ||
287 | - darkTheme: _.darkTheme ?? darkTheme ?? theme ?? ThemeData.fallback(), | ||
288 | - themeMode: _.themeMode ?? themeMode, | 260 | + theme: controller.theme ?? theme ?? ThemeData.fallback(), |
261 | + darkTheme: controller.darkTheme ?? | ||
262 | + darkTheme ?? | ||
263 | + theme ?? | ||
264 | + ThemeData.fallback(), | ||
265 | + themeMode: controller.themeMode ?? themeMode, | ||
289 | locale: Get.locale ?? locale, | 266 | locale: Get.locale ?? locale, |
290 | - scaffoldMessengerKey: scaffoldMessengerKey ?? _.scaffoldMessengerKey, | 267 | + scaffoldMessengerKey: |
268 | + scaffoldMessengerKey ?? controller.scaffoldMessengerKey, | ||
291 | localizationsDelegates: localizationsDelegates, | 269 | localizationsDelegates: localizationsDelegates, |
292 | localeListResolutionCallback: localeListResolutionCallback, | 270 | localeListResolutionCallback: localeListResolutionCallback, |
293 | localeResolutionCallback: localeResolutionCallback, | 271 | localeResolutionCallback: localeResolutionCallback, |
@@ -302,30 +280,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -302,30 +280,7 @@ class GetMaterialApp extends StatelessWidget { | ||
302 | scrollBehavior: scrollBehavior, | 280 | scrollBehavior: scrollBehavior, |
303 | useInheritedMediaQuery: useInheritedMediaQuery, | 281 | useInheritedMediaQuery: useInheritedMediaQuery, |
304 | ); | 282 | ); |
305 | - }); | ||
306 | - | ||
307 | - Widget defaultBuilder(BuildContext context, Widget? child) { | ||
308 | - return Directionality( | ||
309 | - textDirection: textDirection ?? | ||
310 | - (rtlLanguages.contains(Get.locale?.languageCode) | ||
311 | - ? TextDirection.rtl | ||
312 | - : TextDirection.ltr), | ||
313 | - child: builder == null | ||
314 | - ? (child ?? Material()) | ||
315 | - : builder!(context, child ?? Material()), | 283 | + }), |
316 | ); | 284 | ); |
317 | } | 285 | } |
318 | - | ||
319 | - Route<dynamic> generator(RouteSettings settings) { | ||
320 | - return PageRedirect(settings: settings, unknownRoute: unknownRoute).page(); | ||
321 | - } | ||
322 | - | ||
323 | - // List<Route<dynamic>> initialRoutesGenerate(String name) { | ||
324 | - // return [ | ||
325 | - // PageRedirect( | ||
326 | - // settings: RouteSettings(name: name), | ||
327 | - // unknownRoute: unknownRoute, | ||
328 | - // ).page() | ||
329 | - // ]; | ||
330 | - // } | ||
331 | } | 286 | } |
1 | +import 'package:flutter/foundation.dart'; | ||
1 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
2 | 3 | ||
3 | import '../../../get.dart'; | 4 | import '../../../get.dart'; |
4 | 5 | ||
6 | +class ConfigData { | ||
7 | + final ValueChanged<Routing?>? routingCallback; | ||
8 | + final Transition? defaultTransition; | ||
9 | + final bool? opaqueRoute; | ||
10 | + final VoidCallback? onInit; | ||
11 | + final VoidCallback? onReady; | ||
12 | + final VoidCallback? onDispose; | ||
13 | + final bool? enableLog; | ||
14 | + final LogWriterCallback? logWriterCallback; | ||
15 | + final bool? popGesture; | ||
16 | + final SmartManagement smartManagement; | ||
17 | + final List<Bind> binds; | ||
18 | + final Duration? transitionDuration; | ||
19 | + final bool? defaultGlobalState; | ||
20 | + final List<GetPage>? getPages; | ||
21 | + final GetPage? unknownRoute; | ||
22 | + final RouteInformationProvider? routeInformationProvider; | ||
23 | + final RouteInformationParser<Object>? routeInformationParser; | ||
24 | + final RouterDelegate<Object>? routerDelegate; | ||
25 | + final BackButtonDispatcher? backButtonDispatcher; | ||
26 | + final List<NavigatorObserver>? navigatorObservers; | ||
27 | + final GlobalKey<NavigatorState>? navigatorKey; | ||
28 | + final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey; | ||
29 | + final Map<String, Map<String, String>>? translationsKeys; | ||
30 | + final Translations? translations; | ||
31 | + final Locale? locale; | ||
32 | + final Locale? fallbackLocale; | ||
33 | + final String? initialRoute; | ||
34 | + final CustomTransition? customTransition; | ||
35 | + final Widget? home; | ||
36 | + | ||
37 | + ConfigData({ | ||
38 | + required this.routingCallback, | ||
39 | + required this.defaultTransition, | ||
40 | + required this.opaqueRoute, | ||
41 | + required this.onInit, | ||
42 | + required this.onReady, | ||
43 | + required this.onDispose, | ||
44 | + required this.enableLog, | ||
45 | + required this.logWriterCallback, | ||
46 | + required this.popGesture, | ||
47 | + required this.smartManagement, | ||
48 | + required this.binds, | ||
49 | + required this.transitionDuration, | ||
50 | + required this.defaultGlobalState, | ||
51 | + required this.getPages, | ||
52 | + required this.unknownRoute, | ||
53 | + required this.routeInformationProvider, | ||
54 | + required this.routeInformationParser, | ||
55 | + required this.routerDelegate, | ||
56 | + required this.backButtonDispatcher, | ||
57 | + required this.navigatorObservers, | ||
58 | + required this.navigatorKey, | ||
59 | + required this.scaffoldMessengerKey, | ||
60 | + required this.translationsKeys, | ||
61 | + required this.translations, | ||
62 | + required this.locale, | ||
63 | + required this.fallbackLocale, | ||
64 | + required this.initialRoute, | ||
65 | + required this.customTransition, | ||
66 | + required this.home, | ||
67 | + }); | ||
68 | +} | ||
69 | + | ||
5 | class GetMaterialController extends FullLifeCycleController { | 70 | class GetMaterialController extends FullLifeCycleController { |
6 | - static GetMaterialController get to => Get.find(); | 71 | + GetMaterialController(this.config); |
72 | + | ||
73 | + static GetMaterialController get to { | ||
74 | + return Get.find(); | ||
75 | + } | ||
76 | + | ||
77 | + late final RouterDelegate<Object> routerDelegate; | ||
78 | + late final RouteInformationParser<Object> routeInformationParser; | ||
79 | + final ConfigData config; | ||
80 | + | ||
81 | + @override | ||
82 | + void onReady() { | ||
83 | + config.onReady?.call(); | ||
84 | + super.onReady(); | ||
85 | + } | ||
86 | + | ||
87 | + @override | ||
88 | + void onInit() { | ||
89 | + super.onInit(); | ||
90 | + | ||
91 | + if (config.getPages == null && config.home == null) { | ||
92 | + throw 'You need add pages or home'; | ||
93 | + } | ||
94 | + | ||
95 | + routerDelegate = config.routerDelegate ?? | ||
96 | + createDelegate( | ||
97 | + pages: config.getPages ?? | ||
98 | + [ | ||
99 | + GetPage( | ||
100 | + name: cleanRouteName("/${config.home.runtimeType}"), | ||
101 | + page: () => config.home!, | ||
102 | + ), | ||
103 | + ], | ||
104 | + notFoundRoute: config.unknownRoute, | ||
105 | + navigatorKey: config.navigatorKey, | ||
106 | + navigatorObservers: (config.navigatorObservers == null | ||
107 | + ? <NavigatorObserver>[ | ||
108 | + GetObserver(config.routingCallback, Get.routing) | ||
109 | + ] | ||
110 | + : <NavigatorObserver>[ | ||
111 | + GetObserver(config.routingCallback, routing), | ||
112 | + ...config.navigatorObservers! | ||
113 | + ]), | ||
114 | + ); | ||
115 | + | ||
116 | + routeInformationParser = config.routeInformationParser ?? | ||
117 | + createInformationParser( | ||
118 | + initialRoute: config.initialRoute ?? | ||
119 | + config.getPages?.first.name ?? | ||
120 | + cleanRouteName("/${config.home.runtimeType}"), | ||
121 | + ); | ||
122 | + | ||
123 | + if (config.locale != null) Get.locale = config.locale; | ||
124 | + | ||
125 | + if (config.fallbackLocale != null) { | ||
126 | + Get.fallbackLocale = config.fallbackLocale; | ||
127 | + } | ||
128 | + | ||
129 | + if (config.translations != null) { | ||
130 | + Get.addTranslations(config.translations!.keys); | ||
131 | + } else if (config.translationsKeys != null) { | ||
132 | + Get.addTranslations(config.translationsKeys!); | ||
133 | + } | ||
134 | + | ||
135 | + customTransition = config.customTransition; | ||
136 | + | ||
137 | + //Get.setDefaultDelegate(routerDelegate); | ||
138 | + Get.smartManagement = config.smartManagement; | ||
139 | + config.onInit?.call(); | ||
140 | + | ||
141 | + Get.isLogEnable = config.enableLog ?? kDebugMode; | ||
142 | + Get.log = config.logWriterCallback ?? defaultLogWriterCallback; | ||
143 | + defaultTransition = config.defaultTransition; | ||
144 | + defaultOpaqueRoute = config.opaqueRoute ?? true; | ||
145 | + defaultPopGesture = config.popGesture ?? GetPlatform.isIOS; | ||
146 | + defaultTransitionDuration = | ||
147 | + config.transitionDuration ?? Duration(milliseconds: 300); | ||
148 | + | ||
149 | + // defaultTransitionCurve = Curves.easeOutQuad; | ||
150 | + // defaultDialogTransitionCurve = Curves.easeOutQuad; | ||
151 | + // defaultDialogTransitionDuration = Duration(milliseconds: 300); | ||
152 | + } | ||
153 | + | ||
154 | + String cleanRouteName(String name) { | ||
155 | + name = name.replaceAll('() => ', ''); | ||
156 | + | ||
157 | + /// uncommonent for URL styling. | ||
158 | + // name = name.paramCase!; | ||
159 | + if (!name.startsWith('/')) { | ||
160 | + name = '/$name'; | ||
161 | + } | ||
162 | + return Uri.tryParse(name)?.toString() ?? name; | ||
163 | + } | ||
7 | 164 | ||
8 | bool testMode = false; | 165 | bool testMode = false; |
9 | Key? unikey; | 166 | Key? unikey; |
@@ -15,26 +172,22 @@ class GetMaterialController extends FullLifeCycleController { | @@ -15,26 +172,22 @@ class GetMaterialController extends FullLifeCycleController { | ||
15 | 172 | ||
16 | bool defaultPopGesture = GetPlatform.isIOS; | 173 | bool defaultPopGesture = GetPlatform.isIOS; |
17 | bool defaultOpaqueRoute = true; | 174 | bool defaultOpaqueRoute = true; |
18 | - | ||
19 | Transition? defaultTransition; | 175 | Transition? defaultTransition; |
20 | Duration defaultTransitionDuration = Duration(milliseconds: 300); | 176 | Duration defaultTransitionDuration = Duration(milliseconds: 300); |
21 | Curve defaultTransitionCurve = Curves.easeOutQuad; | 177 | Curve defaultTransitionCurve = Curves.easeOutQuad; |
22 | - | ||
23 | Curve defaultDialogTransitionCurve = Curves.easeOutQuad; | 178 | Curve defaultDialogTransitionCurve = Curves.easeOutQuad; |
24 | - | ||
25 | Duration defaultDialogTransitionDuration = Duration(milliseconds: 300); | 179 | Duration defaultDialogTransitionDuration = Duration(milliseconds: 300); |
26 | 180 | ||
27 | final routing = Routing(); | 181 | final routing = Routing(); |
28 | 182 | ||
29 | Map<String, String?> parameters = {}; | 183 | Map<String, String?> parameters = {}; |
30 | - | ||
31 | CustomTransition? customTransition; | 184 | CustomTransition? customTransition; |
32 | 185 | ||
33 | Map<dynamic, GetDelegate> keys = {}; | 186 | Map<dynamic, GetDelegate> keys = {}; |
34 | 187 | ||
35 | GlobalKey<NavigatorState> get key => rootDelegate.navigatorKey; | 188 | GlobalKey<NavigatorState> get key => rootDelegate.navigatorKey; |
36 | 189 | ||
37 | - GetDelegate get rootDelegate => Get.createDelegate(); | 190 | + GetDelegate get rootDelegate => routerDelegate as GetDelegate; |
38 | 191 | ||
39 | GlobalKey<NavigatorState>? addKey(GlobalKey<NavigatorState> newKey) { | 192 | GlobalKey<NavigatorState>? addKey(GlobalKey<NavigatorState> newKey) { |
40 | rootDelegate.navigatorKey = newKey; | 193 | rootDelegate.navigatorKey = newKey; |
@@ -73,4 +226,48 @@ class GetMaterialController extends FullLifeCycleController { | @@ -73,4 +226,48 @@ class GetMaterialController extends FullLifeCycleController { | ||
73 | themeMode = value; | 226 | themeMode = value; |
74 | update(); | 227 | update(); |
75 | } | 228 | } |
229 | + | ||
230 | + GetDelegate? nestedKey(String? key) { | ||
231 | + if (key == null) { | ||
232 | + return routerDelegate as GetDelegate; | ||
233 | + } | ||
234 | + keys.putIfAbsent( | ||
235 | + key, | ||
236 | + () => GetDelegate( | ||
237 | + showHashOnUrl: true, | ||
238 | + //debugLabel: 'Getx nested key: ${key.toString()}', | ||
239 | + pages: RouteDecoder.fromRoute(key).currentChildrens ?? [], | ||
240 | + ), | ||
241 | + ); | ||
242 | + return keys[key]; | ||
243 | + } | ||
244 | + | ||
245 | + GetInformationParser createInformationParser({String initialRoute = '/'}) { | ||
246 | + return GetInformationParser( | ||
247 | + initialRoute: initialRoute, | ||
248 | + ); | ||
249 | + } | ||
250 | + | ||
251 | + // static GetDelegate? _delegate; | ||
252 | + | ||
253 | + GetDelegate createDelegate({ | ||
254 | + GetPage<dynamic>? notFoundRoute, | ||
255 | + List<GetPage> pages = const [], | ||
256 | + List<NavigatorObserver>? navigatorObservers, | ||
257 | + TransitionDelegate<dynamic>? transitionDelegate, | ||
258 | + PopMode backButtonPopMode = PopMode.history, | ||
259 | + PreventDuplicateHandlingMode preventDuplicateHandlingMode = | ||
260 | + PreventDuplicateHandlingMode.reorderRoutes, | ||
261 | + GlobalKey<NavigatorState>? navigatorKey, | ||
262 | + }) { | ||
263 | + return GetDelegate( | ||
264 | + notFoundRoute: notFoundRoute, | ||
265 | + navigatorObservers: navigatorObservers, | ||
266 | + transitionDelegate: transitionDelegate, | ||
267 | + backButtonPopMode: backButtonPopMode, | ||
268 | + preventDuplicateHandlingMode: preventDuplicateHandlingMode, | ||
269 | + pages: pages, | ||
270 | + navigatorKey: navigatorKey, | ||
271 | + ); | ||
272 | + } | ||
76 | } | 273 | } |
@@ -15,7 +15,16 @@ class RouterReportManager<T> { | @@ -15,7 +15,16 @@ class RouterReportManager<T> { | ||
15 | /// non-singleton instances. | 15 | /// non-singleton instances. |
16 | final Map<T?, HashSet<Function>> _routesByCreate = {}; | 16 | final Map<T?, HashSet<Function>> _routesByCreate = {}; |
17 | 17 | ||
18 | - static late final RouterReportManager instance = RouterReportManager(); | 18 | + static RouterReportManager? _instance; |
19 | + | ||
20 | + RouterReportManager._(); | ||
21 | + | ||
22 | + static RouterReportManager get instance => | ||
23 | + _instance ??= RouterReportManager._(); | ||
24 | + | ||
25 | + static void dispose() { | ||
26 | + _instance = null; | ||
27 | + } | ||
19 | 28 | ||
20 | void printInstanceStack() { | 29 | void printInstanceStack() { |
21 | Get.log(_routesKey.toString()); | 30 | Get.log(_routesKey.toString()); |
@@ -75,7 +84,7 @@ class RouterReportManager<T> { | @@ -75,7 +84,7 @@ class RouterReportManager<T> { | ||
75 | } | 84 | } |
76 | 85 | ||
77 | for (final element in keysToRemove) { | 86 | for (final element in keysToRemove) { |
78 | - GetInstance().markAsDirty(key: element); | 87 | + Get.markAsDirty(key: element); |
79 | 88 | ||
80 | //_routesKey.remove(element); | 89 | //_routesKey.remove(element); |
81 | } | 90 | } |
@@ -104,7 +113,7 @@ class RouterReportManager<T> { | @@ -104,7 +113,7 @@ class RouterReportManager<T> { | ||
104 | } | 113 | } |
105 | 114 | ||
106 | for (final element in keysToRemove) { | 115 | for (final element in keysToRemove) { |
107 | - final value = GetInstance().delete(key: element); | 116 | + final value = Get.delete(key: element); |
108 | if (value) { | 117 | if (value) { |
109 | _routesKey[routeName]?.remove(element); | 118 | _routesKey[routeName]?.remove(element); |
110 | } | 119 | } |
1 | -import 'package:flutter/material.dart'; | 1 | +import 'package:flutter/cupertino.dart'; |
2 | 2 | ||
3 | import '../../../get.dart'; | 3 | import '../../../get.dart'; |
4 | import '../router_report.dart'; | 4 | import '../router_report.dart'; |
@@ -41,6 +41,7 @@ class GetPageRoute<T> extends PageRoute<T> | @@ -41,6 +41,7 @@ class GetPageRoute<T> extends PageRoute<T> | ||
41 | GetPageRoute({ | 41 | GetPageRoute({ |
42 | RouteSettings? settings, | 42 | RouteSettings? settings, |
43 | this.transitionDuration = const Duration(milliseconds: 300), | 43 | this.transitionDuration = const Duration(milliseconds: 300), |
44 | + this.reverseTransitionDuration = const Duration(milliseconds: 300), | ||
44 | this.opaque = true, | 45 | this.opaque = true, |
45 | this.parameter, | 46 | this.parameter, |
46 | this.gestureWidth, | 47 | this.gestureWidth, |
@@ -51,7 +52,8 @@ class GetPageRoute<T> extends PageRoute<T> | @@ -51,7 +52,8 @@ class GetPageRoute<T> extends PageRoute<T> | ||
51 | this.customTransition, | 52 | this.customTransition, |
52 | this.barrierDismissible = false, | 53 | this.barrierDismissible = false, |
53 | this.barrierColor, | 54 | this.barrierColor, |
54 | - this.bindings = const [], | 55 | + BindingsInterface? binding, |
56 | + List<BindingsInterface> bindings = const [], | ||
55 | this.binds, | 57 | this.binds, |
56 | this.routeName, | 58 | this.routeName, |
57 | this.page, | 59 | this.page, |
@@ -61,14 +63,17 @@ class GetPageRoute<T> extends PageRoute<T> | @@ -61,14 +63,17 @@ class GetPageRoute<T> extends PageRoute<T> | ||
61 | this.maintainState = true, | 63 | this.maintainState = true, |
62 | bool fullscreenDialog = false, | 64 | bool fullscreenDialog = false, |
63 | this.middlewares, | 65 | this.middlewares, |
64 | - }) : super( | 66 | + }) : bindings = (binding == null) ? bindings : [...bindings, binding], |
67 | + super( | ||
65 | settings: settings, | 68 | settings: settings, |
66 | fullscreenDialog: fullscreenDialog, | 69 | fullscreenDialog: fullscreenDialog, |
67 | - // builder: (context) => Container(), | ||
68 | ); | 70 | ); |
69 | 71 | ||
70 | @override | 72 | @override |
71 | final Duration transitionDuration; | 73 | final Duration transitionDuration; |
74 | + @override | ||
75 | + final Duration reverseTransitionDuration; | ||
76 | + | ||
72 | final GetPageBuilder? page; | 77 | final GetPageBuilder? page; |
73 | final String? routeName; | 78 | final String? routeName; |
74 | //final String reference; | 79 | //final String reference; |
@@ -19,7 +19,8 @@ class GetInformationParser extends RouteInformationParser<RouteDecoder> { | @@ -19,7 +19,8 @@ class GetInformationParser extends RouteInformationParser<RouteDecoder> { | ||
19 | if (location == '/') { | 19 | if (location == '/') { |
20 | //check if there is a corresponding page | 20 | //check if there is a corresponding page |
21 | //if not, relocate to initialRoute | 21 | //if not, relocate to initialRoute |
22 | - if (!Get.routeTree.routes.any((element) => element.name == '/')) { | 22 | + if (!(Get.rootController.routerDelegate as GetDelegate).registeredRoutes |
23 | + .any((element) => element.name == '/')) { | ||
23 | location = initialRoute; | 24 | location = initialRoute; |
24 | } | 25 | } |
25 | } | 26 | } |
@@ -32,9 +33,9 @@ class GetInformationParser extends RouteInformationParser<RouteDecoder> { | @@ -32,9 +33,9 @@ class GetInformationParser extends RouteInformationParser<RouteDecoder> { | ||
32 | } | 33 | } |
33 | 34 | ||
34 | @override | 35 | @override |
35 | - RouteInformation restoreRouteInformation(RouteDecoder config) { | 36 | + RouteInformation restoreRouteInformation(RouteDecoder configuration) { |
36 | return RouteInformation( | 37 | return RouteInformation( |
37 | - location: config.pageSettings?.name, | 38 | + location: configuration.pageSettings?.name, |
38 | state: null, | 39 | state: null, |
39 | ); | 40 | ); |
40 | } | 41 | } |
@@ -25,26 +25,26 @@ import '../routes/transitions_type.dart'; | @@ -25,26 +25,26 @@ import '../routes/transitions_type.dart'; | ||
25 | /// another pop will change the _activePages stack to: | 25 | /// another pop will change the _activePages stack to: |
26 | /// 1) /home | 26 | /// 1) /home |
27 | enum PopMode { | 27 | enum PopMode { |
28 | - History, | ||
29 | - Page, | 28 | + history, |
29 | + page, | ||
30 | } | 30 | } |
31 | 31 | ||
32 | /// Enables the user to customize the behavior when pushing multiple routes that | 32 | /// Enables the user to customize the behavior when pushing multiple routes that |
33 | /// shouldn't be duplicates | 33 | /// shouldn't be duplicates |
34 | enum PreventDuplicateHandlingMode { | 34 | enum PreventDuplicateHandlingMode { |
35 | /// Removes the _activePages entries until it reaches the old route | 35 | /// Removes the _activePages entries until it reaches the old route |
36 | - PopUntilOriginalRoute, | 36 | + popUntilOriginalRoute, |
37 | 37 | ||
38 | /// Simply don't push the new route | 38 | /// Simply don't push the new route |
39 | - DoNothing, | 39 | + doNothing, |
40 | 40 | ||
41 | /// Recommended - Moves the old route entry to the front | 41 | /// Recommended - Moves the old route entry to the front |
42 | /// | 42 | /// |
43 | /// With this mode, you guarantee there will be only one | 43 | /// With this mode, you guarantee there will be only one |
44 | /// route entry for each location | 44 | /// route entry for each location |
45 | - ReorderRoutes, | 45 | + reorderRoutes, |
46 | 46 | ||
47 | - Recreate, | 47 | + recreate, |
48 | } | 48 | } |
49 | 49 | ||
50 | mixin IGetNavigation { | 50 | mixin IGetNavigation { |
@@ -67,7 +67,7 @@ mixin IGetNavigation { | @@ -67,7 +67,7 @@ mixin IGetNavigation { | ||
67 | 67 | ||
68 | Future<void> popModeUntil( | 68 | Future<void> popModeUntil( |
69 | String fullRoute, { | 69 | String fullRoute, { |
70 | - PopMode popMode = PopMode.History, | 70 | + PopMode popMode = PopMode.history, |
71 | }); | 71 | }); |
72 | 72 | ||
73 | Future<T?> off<T>( | 73 | Future<T?> off<T>( |
@@ -147,6 +147,8 @@ mixin IGetNavigation { | @@ -147,6 +147,8 @@ mixin IGetNavigation { | ||
147 | Object? arguments, | 147 | Object? arguments, |
148 | ]); | 148 | ]); |
149 | 149 | ||
150 | + void removeRoute<T>(String name); | ||
151 | + | ||
150 | void back<T>([T? result]); | 152 | void back<T>([T? result]); |
151 | 153 | ||
152 | Future<R?> backAndtoNamed<T, R>(String page, {T? result, Object? arguments}); | 154 | Future<R?> backAndtoNamed<T, R>(String page, {T? result, Object? arguments}); |
@@ -34,6 +34,7 @@ class GetNavigator extends Navigator { | @@ -34,6 +34,7 @@ class GetNavigator extends Navigator { | ||
34 | settings: settings, | 34 | settings: settings, |
35 | ); | 35 | ); |
36 | } | 36 | } |
37 | + return null; | ||
37 | }, | 38 | }, |
38 | reportsRouteUpdateToEngine: reportsRouteUpdateToEngine, | 39 | reportsRouteUpdateToEngine: reportsRouteUpdateToEngine, |
39 | restorationScopeId: restorationScopeId, | 40 | restorationScopeId: restorationScopeId, |
1 | +// ignore_for_file: overridden_fields | ||
2 | + | ||
1 | import 'dart:async'; | 3 | import 'dart:async'; |
2 | 4 | ||
3 | import 'package:flutter/cupertino.dart'; | 5 | import 'package:flutter/cupertino.dart'; |
@@ -20,11 +22,12 @@ class GetPage<T> extends Page<T> { | @@ -20,11 +22,12 @@ class GetPage<T> extends Page<T> { | ||
20 | final bool maintainState; | 22 | final bool maintainState; |
21 | final bool opaque; | 23 | final bool opaque; |
22 | final double Function(BuildContext context)? gestureWidth; | 24 | final double Function(BuildContext context)? gestureWidth; |
23 | - //final BindingsInterface? binding; | 25 | + final BindingsInterface? binding; |
24 | final List<BindingsInterface> bindings; | 26 | final List<BindingsInterface> bindings; |
25 | final List<Bind> binds; | 27 | final List<Bind> binds; |
26 | final CustomTransition? customTransition; | 28 | final CustomTransition? customTransition; |
27 | final Duration? transitionDuration; | 29 | final Duration? transitionDuration; |
30 | + final Duration? reverseTransitionDuration; | ||
28 | final bool fullscreenDialog; | 31 | final bool fullscreenDialog; |
29 | final bool preventDuplicates; | 32 | final bool preventDuplicates; |
30 | final Completer<T?>? completer; | 33 | final Completer<T?>? completer; |
@@ -61,7 +64,9 @@ class GetPage<T> extends Page<T> { | @@ -61,7 +64,9 @@ class GetPage<T> extends Page<T> { | ||
61 | this.parameters, | 64 | this.parameters, |
62 | this.opaque = true, | 65 | this.opaque = true, |
63 | this.transitionDuration, | 66 | this.transitionDuration, |
67 | + this.reverseTransitionDuration, | ||
64 | this.popGesture, | 68 | this.popGesture, |
69 | + this.binding, | ||
65 | this.bindings = const [], | 70 | this.bindings = const [], |
66 | this.binds = const [], | 71 | this.binds = const [], |
67 | this.transition, | 72 | this.transition, |
@@ -74,7 +79,7 @@ class GetPage<T> extends Page<T> { | @@ -74,7 +79,7 @@ class GetPage<T> extends Page<T> { | ||
74 | this.showCupertinoParallax = true, | 79 | this.showCupertinoParallax = true, |
75 | this.preventDuplicates = true, | 80 | this.preventDuplicates = true, |
76 | this.preventDuplicateHandlingMode = | 81 | this.preventDuplicateHandlingMode = |
77 | - PreventDuplicateHandlingMode.ReorderRoutes, | 82 | + PreventDuplicateHandlingMode.reorderRoutes, |
78 | this.completer, | 83 | this.completer, |
79 | LocalKey? key, | 84 | LocalKey? key, |
80 | }) : path = _nameToRegex(name), | 85 | }) : path = _nameToRegex(name), |
@@ -100,10 +105,11 @@ class GetPage<T> extends Page<T> { | @@ -100,10 +105,11 @@ class GetPage<T> extends Page<T> { | ||
100 | bool? maintainState, | 105 | bool? maintainState, |
101 | bool? opaque, | 106 | bool? opaque, |
102 | List<BindingsInterface>? bindings, | 107 | List<BindingsInterface>? bindings, |
103 | - // BindingsInterface? binding, | 108 | + BindingsInterface? binding, |
104 | List<Bind>? binds, | 109 | List<Bind>? binds, |
105 | CustomTransition? customTransition, | 110 | CustomTransition? customTransition, |
106 | Duration? transitionDuration, | 111 | Duration? transitionDuration, |
112 | + Duration? reverseTransitionDuration, | ||
107 | bool? fullscreenDialog, | 113 | bool? fullscreenDialog, |
108 | RouteSettings? settings, | 114 | RouteSettings? settings, |
109 | List<GetPage<T>>? children, | 115 | List<GetPage<T>>? children, |
@@ -133,8 +139,11 @@ class GetPage<T> extends Page<T> { | @@ -133,8 +139,11 @@ class GetPage<T> extends Page<T> { | ||
133 | opaque: opaque ?? this.opaque, | 139 | opaque: opaque ?? this.opaque, |
134 | bindings: bindings ?? this.bindings, | 140 | bindings: bindings ?? this.bindings, |
135 | binds: binds ?? this.binds, | 141 | binds: binds ?? this.binds, |
142 | + binding: binding ?? this.binding, | ||
136 | customTransition: customTransition ?? this.customTransition, | 143 | customTransition: customTransition ?? this.customTransition, |
137 | transitionDuration: transitionDuration ?? this.transitionDuration, | 144 | transitionDuration: transitionDuration ?? this.transitionDuration, |
145 | + reverseTransitionDuration: | ||
146 | + reverseTransitionDuration ?? this.reverseTransitionDuration, | ||
138 | fullscreenDialog: fullscreenDialog ?? this.fullscreenDialog, | 147 | fullscreenDialog: fullscreenDialog ?? this.fullscreenDialog, |
139 | children: children ?? this.children, | 148 | children: children ?? this.children, |
140 | unknownRoute: unknownRoute ?? this.unknownRoute, | 149 | unknownRoute: unknownRoute ?? this.unknownRoute, |
@@ -154,7 +163,7 @@ class GetPage<T> extends Page<T> { | @@ -154,7 +163,7 @@ class GetPage<T> extends Page<T> { | ||
154 | route: this, | 163 | route: this, |
155 | settings: this, | 164 | settings: this, |
156 | unknownRoute: unknownRoute, | 165 | unknownRoute: unknownRoute, |
157 | - ).getPageToRoute<T>(this, unknownRoute); | 166 | + ).getPageToRoute<T>(this, unknownRoute, context); |
158 | 167 | ||
159 | return _page; | 168 | return _page; |
160 | } | 169 | } |
@@ -165,7 +174,7 @@ class GetPage<T> extends Page<T> { | @@ -165,7 +174,7 @@ class GetPage<T> extends Page<T> { | ||
165 | String _replace(Match pattern) { | 174 | String _replace(Match pattern) { |
166 | var buffer = StringBuffer('(?:'); | 175 | var buffer = StringBuffer('(?:'); |
167 | 176 | ||
168 | - if (pattern[1] != null) buffer.write('\.'); | 177 | + if (pattern[1] != null) buffer.write('.'); |
169 | buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))'); | 178 | buffer.write('([\\w%+-._~!\$&\'()*,;=:@]+))'); |
170 | if (pattern[3] != null) buffer.write('?'); | 179 | if (pattern[3] != null) buffer.write('?'); |
171 | 180 |
@@ -4,13 +4,12 @@ import 'package:flutter/foundation.dart'; | @@ -4,13 +4,12 @@ import 'package:flutter/foundation.dart'; | ||
4 | import 'package:flutter/material.dart'; | 4 | import 'package:flutter/material.dart'; |
5 | 5 | ||
6 | import '../../../get_instance/src/bindings_interface.dart'; | 6 | import '../../../get_instance/src/bindings_interface.dart'; |
7 | -import '../../../get_state_manager/src/simple/list_notifier.dart'; | ||
8 | import '../../../get_utils/src/platform/platform.dart'; | 7 | import '../../../get_utils/src/platform/platform.dart'; |
9 | import '../../../route_manager.dart'; | 8 | import '../../../route_manager.dart'; |
10 | 9 | ||
11 | class GetDelegate extends RouterDelegate<RouteDecoder> | 10 | class GetDelegate extends RouterDelegate<RouteDecoder> |
12 | with | 11 | with |
13 | - ListNotifierSingleMixin, | 12 | + ChangeNotifier, |
14 | PopNavigatorRouterDelegateMixin<RouteDecoder>, | 13 | PopNavigatorRouterDelegateMixin<RouteDecoder>, |
15 | IGetNavigation { | 14 | IGetNavigation { |
16 | final List<RouteDecoder> _activePages = <RouteDecoder>[]; | 15 | final List<RouteDecoder> _activePages = <RouteDecoder>[]; |
@@ -27,6 +26,30 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -27,6 +26,30 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
27 | 26 | ||
28 | List<RouteDecoder> get activePages => _activePages; | 27 | List<RouteDecoder> get activePages => _activePages; |
29 | 28 | ||
29 | + final _routeTree = ParseRouteTree(routes: []); | ||
30 | + | ||
31 | + List<GetPage> get registeredRoutes => _routeTree.routes; | ||
32 | + | ||
33 | + void addPages(List<GetPage> getPages) { | ||
34 | + _routeTree.addRoutes(getPages); | ||
35 | + } | ||
36 | + | ||
37 | + void clearRouteTree() { | ||
38 | + _routeTree.routes.clear(); | ||
39 | + } | ||
40 | + | ||
41 | + void addPage(GetPage getPage) { | ||
42 | + _routeTree.addRoute(getPage); | ||
43 | + } | ||
44 | + | ||
45 | + void removePage(GetPage getPage) { | ||
46 | + _routeTree.removeRoute(getPage); | ||
47 | + } | ||
48 | + | ||
49 | + RouteDecoder matchRoute(String name, {PageSettings? arguments}) { | ||
50 | + return _routeTree.matchRoute(name, arguments: arguments); | ||
51 | + } | ||
52 | + | ||
30 | // GlobalKey<NavigatorState> get navigatorKey => Get.key; | 53 | // GlobalKey<NavigatorState> get navigatorKey => Get.key; |
31 | 54 | ||
32 | @override | 55 | @override |
@@ -38,9 +61,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -38,9 +61,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
38 | GetPage? notFoundRoute, | 61 | GetPage? notFoundRoute, |
39 | this.navigatorObservers, | 62 | this.navigatorObservers, |
40 | this.transitionDelegate, | 63 | this.transitionDelegate, |
41 | - this.backButtonPopMode = PopMode.History, | 64 | + this.backButtonPopMode = PopMode.history, |
42 | this.preventDuplicateHandlingMode = | 65 | this.preventDuplicateHandlingMode = |
43 | - PreventDuplicateHandlingMode.ReorderRoutes, | 66 | + PreventDuplicateHandlingMode.reorderRoutes, |
44 | this.pickPagesForRootNavigator, | 67 | this.pickPagesForRootNavigator, |
45 | this.restorationScopeId, | 68 | this.restorationScopeId, |
46 | bool showHashOnUrl = false, | 69 | bool showHashOnUrl = false, |
@@ -54,8 +77,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -54,8 +77,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
54 | ), | 77 | ), |
55 | ) { | 78 | ) { |
56 | if (!showHashOnUrl && GetPlatform.isWeb) setUrlStrategy(); | 79 | if (!showHashOnUrl && GetPlatform.isWeb) setUrlStrategy(); |
57 | - Get.addPages(pages); | ||
58 | - Get.addPage(notFoundRoute); | 80 | + addPages(pages); |
81 | + addPage(notFoundRoute); | ||
59 | Get.log('GetDelegate is created !'); | 82 | Get.log('GetDelegate is created !'); |
60 | } | 83 | } |
61 | 84 | ||
@@ -69,6 +92,16 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -69,6 +92,16 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
69 | var redirectRes = await item.redirectDelegate(iterator); | 92 | var redirectRes = await item.redirectDelegate(iterator); |
70 | if (redirectRes == null) return null; | 93 | if (redirectRes == null) return null; |
71 | iterator = redirectRes; | 94 | iterator = redirectRes; |
95 | + // Stop the iteration over the middleware if we changed page | ||
96 | + // and that redirectRes is not the same as the current config. | ||
97 | + if (config != redirectRes) { | ||
98 | + break; | ||
99 | + } | ||
100 | + } | ||
101 | + // If the target is not the same as the source, we need | ||
102 | + // to run the middlewares for the new route. | ||
103 | + if (iterator != config) { | ||
104 | + return await runMiddleware(iterator); | ||
72 | } | 105 | } |
73 | return iterator; | 106 | return iterator; |
74 | } | 107 | } |
@@ -122,14 +155,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -122,14 +155,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
122 | (element) => element.pageSettings?.name == config.pageSettings?.name); | 155 | (element) => element.pageSettings?.name == config.pageSettings?.name); |
123 | if (originalEntryIndex >= 0) { | 156 | if (originalEntryIndex >= 0) { |
124 | switch (preventDuplicateHandlingMode) { | 157 | switch (preventDuplicateHandlingMode) { |
125 | - case PreventDuplicateHandlingMode.PopUntilOriginalRoute: | ||
126 | - popModeUntil(config.pageSettings!.name, popMode: PopMode.Page); | 158 | + case PreventDuplicateHandlingMode.popUntilOriginalRoute: |
159 | + popModeUntil(config.pageSettings!.name, popMode: PopMode.page); | ||
127 | break; | 160 | break; |
128 | - case PreventDuplicateHandlingMode.ReorderRoutes: | 161 | + case PreventDuplicateHandlingMode.reorderRoutes: |
129 | await _unsafeHistoryRemoveAt(originalEntryIndex, null); | 162 | await _unsafeHistoryRemoveAt(originalEntryIndex, null); |
130 | await _unsafeHistoryAdd(config); | 163 | await _unsafeHistoryAdd(config); |
131 | break; | 164 | break; |
132 | - case PreventDuplicateHandlingMode.DoNothing: | 165 | + case PreventDuplicateHandlingMode.doNothing: |
133 | default: | 166 | default: |
134 | break; | 167 | break; |
135 | } | 168 | } |
@@ -192,9 +225,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -192,9 +225,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
192 | 225 | ||
193 | Future<T?> _pop<T>(PopMode mode, T result) async { | 226 | Future<T?> _pop<T>(PopMode mode, T result) async { |
194 | switch (mode) { | 227 | switch (mode) { |
195 | - case PopMode.History: | 228 | + case PopMode.history: |
196 | return await _popHistory<T>(result); | 229 | return await _popHistory<T>(result); |
197 | - case PopMode.Page: | 230 | + case PopMode.page: |
198 | return await _popPage<T>(result); | 231 | return await _popPage<T>(result); |
199 | default: | 232 | default: |
200 | return null; | 233 | return null; |
@@ -225,9 +258,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -225,9 +258,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
225 | 258 | ||
226 | bool _canPop(mode) { | 259 | bool _canPop(mode) { |
227 | switch (mode) { | 260 | switch (mode) { |
228 | - case PopMode.History: | 261 | + case PopMode.history: |
229 | return _canPopHistory(); | 262 | return _canPopHistory(); |
230 | - case PopMode.Page: | 263 | + case PopMode.page: |
231 | default: | 264 | default: |
232 | return _canPopPage(); | 265 | return _canPopPage(); |
233 | } | 266 | } |
@@ -239,7 +272,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -239,7 +272,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
239 | Iterable<GetPage> getVisualPages(RouteDecoder? currentHistory) { | 272 | Iterable<GetPage> getVisualPages(RouteDecoder? currentHistory) { |
240 | final res = currentHistory!.currentTreeBranch | 273 | final res = currentHistory!.currentTreeBranch |
241 | .where((r) => r.participatesInRootNavigator != null); | 274 | .where((r) => r.participatesInRootNavigator != null); |
242 | - if (res.length == 0) { | 275 | + if (res.isEmpty) { |
243 | //default behavoir, all routes participate in root navigator | 276 | //default behavoir, all routes participate in root navigator |
244 | return _activePages.map((e) => e.route!); | 277 | return _activePages.map((e) => e.route!); |
245 | } else { | 278 | } else { |
@@ -256,7 +289,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -256,7 +289,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
256 | ? <GetPage>[] | 289 | ? <GetPage>[] |
257 | : pickPagesForRootNavigator?.call(currentHistory).toList() ?? | 290 | : pickPagesForRootNavigator?.call(currentHistory).toList() ?? |
258 | getVisualPages(currentHistory).toList(); | 291 | getVisualPages(currentHistory).toList(); |
259 | - if (pages.length == 0) { | 292 | + if (pages.isEmpty) { |
260 | return ColoredBox( | 293 | return ColoredBox( |
261 | color: Theme.of(context).scaffoldBackgroundColor, | 294 | color: Theme.of(context).scaffoldBackgroundColor, |
262 | ); | 295 | ); |
@@ -323,10 +356,11 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -323,10 +356,11 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
323 | double Function(BuildContext context)? gestureWidth, | 356 | double Function(BuildContext context)? gestureWidth, |
324 | bool rebuildStack = true, | 357 | bool rebuildStack = true, |
325 | PreventDuplicateHandlingMode preventDuplicateHandlingMode = | 358 | PreventDuplicateHandlingMode preventDuplicateHandlingMode = |
326 | - PreventDuplicateHandlingMode.ReorderRoutes, | 359 | + PreventDuplicateHandlingMode.reorderRoutes, |
327 | }) async { | 360 | }) async { |
328 | routeName = _cleanRouteName("/${page.runtimeType}"); | 361 | routeName = _cleanRouteName("/${page.runtimeType}"); |
329 | - // if (preventDuplicateHandlingMode == PreventDuplicateHandlingMode.Recreate) { | 362 | + // if (preventDuplicateHandlingMode == |
363 | + //PreventDuplicateHandlingMode.Recreate) { | ||
330 | // routeName = routeName + page.hashCode.toString(); | 364 | // routeName = routeName + page.hashCode.toString(); |
331 | // } | 365 | // } |
332 | 366 | ||
@@ -345,14 +379,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -345,14 +379,14 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
345 | preventDuplicateHandlingMode: preventDuplicateHandlingMode, | 379 | preventDuplicateHandlingMode: preventDuplicateHandlingMode, |
346 | ); | 380 | ); |
347 | 381 | ||
348 | - Get.addPage(getPage); | 382 | + _routeTree.addRoute(getPage); |
349 | final args = _buildPageSettings(routeName, arguments); | 383 | final args = _buildPageSettings(routeName, arguments); |
350 | final route = _getRouteDecoder<T>(args); | 384 | final route = _getRouteDecoder<T>(args); |
351 | final result = await _push<T>( | 385 | final result = await _push<T>( |
352 | route!, | 386 | route!, |
353 | rebuildStack: rebuildStack, | 387 | rebuildStack: rebuildStack, |
354 | ); | 388 | ); |
355 | - Get.removePage(getPage); | 389 | + _routeTree.removeRoute(getPage); |
356 | return result; | 390 | return result; |
357 | } | 391 | } |
358 | 392 | ||
@@ -437,13 +471,13 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -437,13 +471,13 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
437 | 471 | ||
438 | @override | 472 | @override |
439 | Future<T?>? offAllNamed<T>( | 473 | Future<T?>? offAllNamed<T>( |
440 | - String page, { | 474 | + String newRouteName, { |
441 | // bool Function(GetPage route)? predicate, | 475 | // bool Function(GetPage route)? predicate, |
442 | dynamic arguments, | 476 | dynamic arguments, |
443 | int? id, | 477 | int? id, |
444 | Map<String, String>? parameters, | 478 | Map<String, String>? parameters, |
445 | }) async { | 479 | }) async { |
446 | - final args = _buildPageSettings(page, arguments); | 480 | + final args = _buildPageSettings(newRouteName, arguments); |
447 | final route = _getRouteDecoder<T>(args); | 481 | final route = _getRouteDecoder<T>(args); |
448 | if (route == null) return null; | 482 | if (route == null) return null; |
449 | 483 | ||
@@ -530,7 +564,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -530,7 +564,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
530 | void back<T>([T? result]) { | 564 | void back<T>([T? result]) { |
531 | _checkIfCanBack(); | 565 | _checkIfCanBack(); |
532 | _popWithResult<T>(result); | 566 | _popWithResult<T>(result); |
533 | - refresh(); | 567 | + notifyListeners(); |
534 | } | 568 | } |
535 | 569 | ||
536 | bool get canBack { | 570 | bool get canBack { |
@@ -564,7 +598,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -564,7 +598,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
564 | @override | 598 | @override |
565 | Future<void> popModeUntil( | 599 | Future<void> popModeUntil( |
566 | String fullRoute, { | 600 | String fullRoute, { |
567 | - PopMode popMode = PopMode.History, | 601 | + PopMode popMode = PopMode.history, |
568 | }) async { | 602 | }) async { |
569 | // remove history or page entries until you meet route | 603 | // remove history or page entries until you meet route |
570 | var iterator = currentConfiguration; | 604 | var iterator = currentConfiguration; |
@@ -575,7 +609,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -575,7 +609,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
575 | // replace iterator | 609 | // replace iterator |
576 | iterator = currentConfiguration; | 610 | iterator = currentConfiguration; |
577 | } | 611 | } |
578 | - refresh(); | 612 | + notifyListeners(); |
579 | } | 613 | } |
580 | 614 | ||
581 | @override | 615 | @override |
@@ -584,12 +618,12 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -584,12 +618,12 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
584 | _popWithResult(); | 618 | _popWithResult(); |
585 | } | 619 | } |
586 | 620 | ||
587 | - refresh(); | 621 | + notifyListeners(); |
588 | } | 622 | } |
589 | 623 | ||
590 | Future<T?> _replace<T>(PageSettings arguments, GetPage<T> page) async { | 624 | Future<T?> _replace<T>(PageSettings arguments, GetPage<T> page) async { |
591 | final index = _activePages.length > 1 ? _activePages.length - 1 : 0; | 625 | final index = _activePages.length > 1 ? _activePages.length - 1 : 0; |
592 | - Get.addPage(page); | 626 | + _routeTree.addRoute(page); |
593 | 627 | ||
594 | final activePage = _getRouteDecoder(arguments); | 628 | final activePage = _getRouteDecoder(arguments); |
595 | 629 | ||
@@ -597,9 +631,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -597,9 +631,9 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
597 | 631 | ||
598 | _activePages[index] = activePage!; | 632 | _activePages[index] = activePage!; |
599 | 633 | ||
600 | - refresh(); | 634 | + notifyListeners(); |
601 | final result = await activePage.route?.completer?.future as Future<T?>?; | 635 | final result = await activePage.route?.completer?.future as Future<T?>?; |
602 | - Get.removePage(page); | 636 | + _routeTree.removeRoute(page); |
603 | 637 | ||
604 | return result; | 638 | return result; |
605 | } | 639 | } |
@@ -609,7 +643,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -609,7 +643,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
609 | // final activePage = _configureRouterDecoder<T>(page, arguments); | 643 | // final activePage = _configureRouterDecoder<T>(page, arguments); |
610 | _activePages[index] = activePage; | 644 | _activePages[index] = activePage; |
611 | 645 | ||
612 | - refresh(); | 646 | + notifyListeners(); |
613 | final result = await activePage.route?.completer?.future as Future<T?>?; | 647 | final result = await activePage.route?.completer?.future as Future<T?>?; |
614 | return result; | 648 | return result; |
615 | } | 649 | } |
@@ -644,7 +678,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -644,7 +678,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
644 | page = uri.toString(); | 678 | page = uri.toString(); |
645 | } | 679 | } |
646 | 680 | ||
647 | - final decoder = Get.routeTree.matchRoute(page, arguments: arguments); | 681 | + final decoder = _routeTree.matchRoute(page, arguments: arguments); |
648 | final route = decoder.route; | 682 | final route = decoder.route; |
649 | if (route == null) return null; | 683 | if (route == null) return null; |
650 | 684 | ||
@@ -680,7 +714,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -680,7 +714,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
680 | 714 | ||
681 | final preventDuplicateHandlingMode = | 715 | final preventDuplicateHandlingMode = |
682 | res.route?.preventDuplicateHandlingMode ?? | 716 | res.route?.preventDuplicateHandlingMode ?? |
683 | - PreventDuplicateHandlingMode.ReorderRoutes; | 717 | + PreventDuplicateHandlingMode.reorderRoutes; |
684 | 718 | ||
685 | final onStackPage = _activePages | 719 | final onStackPage = _activePages |
686 | .firstWhereOrNull((element) => element.route?.key == res.route?.key); | 720 | .firstWhereOrNull((element) => element.route?.key == res.route?.key); |
@@ -691,18 +725,18 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -691,18 +725,18 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
691 | } else { | 725 | } else { |
692 | /// There are duplicate routes, reorder | 726 | /// There are duplicate routes, reorder |
693 | switch (preventDuplicateHandlingMode) { | 727 | switch (preventDuplicateHandlingMode) { |
694 | - case PreventDuplicateHandlingMode.DoNothing: | 728 | + case PreventDuplicateHandlingMode.doNothing: |
695 | break; | 729 | break; |
696 | - case PreventDuplicateHandlingMode.ReorderRoutes: | 730 | + case PreventDuplicateHandlingMode.reorderRoutes: |
697 | _activePages.remove(onStackPage); | 731 | _activePages.remove(onStackPage); |
698 | _activePages.add(res); | 732 | _activePages.add(res); |
699 | break; | 733 | break; |
700 | - case PreventDuplicateHandlingMode.PopUntilOriginalRoute: | 734 | + case PreventDuplicateHandlingMode.popUntilOriginalRoute: |
701 | while (_activePages.last == onStackPage) { | 735 | while (_activePages.last == onStackPage) { |
702 | _popWithResult(); | 736 | _popWithResult(); |
703 | } | 737 | } |
704 | break; | 738 | break; |
705 | - case PreventDuplicateHandlingMode.Recreate: | 739 | + case PreventDuplicateHandlingMode.recreate: |
706 | _activePages.remove(onStackPage); | 740 | _activePages.remove(onStackPage); |
707 | _activePages.add(res); | 741 | _activePages.add(res); |
708 | break; | 742 | break; |
@@ -710,7 +744,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -710,7 +744,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
710 | } | 744 | } |
711 | } | 745 | } |
712 | if (rebuildStack) { | 746 | if (rebuildStack) { |
713 | - refresh(); | 747 | + notifyListeners(); |
714 | } | 748 | } |
715 | 749 | ||
716 | return decoder.route?.completer?.future as Future<T?>?; | 750 | return decoder.route?.completer?.future as Future<T?>?; |
@@ -757,7 +791,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -757,7 +791,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
757 | final wasPopup = await handlePopupRoutes(result: result); | 791 | final wasPopup = await handlePopupRoutes(result: result); |
758 | if (wasPopup) return true; | 792 | if (wasPopup) return true; |
759 | final _popped = await _pop(popMode ?? backButtonPopMode, result); | 793 | final _popped = await _pop(popMode ?? backButtonPopMode, result); |
760 | - refresh(); | 794 | + notifyListeners(); |
761 | if (_popped != null) { | 795 | if (_popped != null) { |
762 | //emulate the old pop with result | 796 | //emulate the old pop with result |
763 | return true; | 797 | return true; |
@@ -780,7 +814,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | @@ -780,7 +814,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder> | ||
780 | _removeHistoryEntry(config, result); | 814 | _removeHistoryEntry(config, result); |
781 | } | 815 | } |
782 | } | 816 | } |
783 | - refresh(); | 817 | + notifyListeners(); |
784 | //return !route.navigator!.userGestureInProgress; | 818 | //return !route.navigator!.userGestureInProgress; |
785 | return true; | 819 | return true; |
786 | } | 820 | } |
@@ -187,8 +187,7 @@ class GetBackGestureController<T> { | @@ -187,8 +187,7 @@ class GetBackGestureController<T> { | ||
187 | // We want to cap the animation time, but we want to use a linear curve | 187 | // We want to cap the animation time, but we want to use a linear curve |
188 | // to determine it. | 188 | // to determine it. |
189 | final droppedPageForwardAnimationTime = min( | 189 | final droppedPageForwardAnimationTime = min( |
190 | - lerpDouble( | ||
191 | - _kMaxMidSwipePageForwardAnimationTime, 0, controller.value)! | 190 | + lerpDouble(_kMaxMidSwipePageForwardAnimationTime, 0, controller.value)! |
192 | .floor(), | 191 | .floor(), |
193 | _kMaxPageBackAnimationTime, | 192 | _kMaxPageBackAnimationTime, |
194 | ); | 193 | ); |
@@ -286,7 +285,10 @@ Cannot read the previousTitle for a route that has not yet been installed''', | @@ -286,7 +285,10 @@ Cannot read the previousTitle for a route that has not yet been installed''', | ||
286 | 285 | ||
287 | @override | 286 | @override |
288 | // A relatively rigorous eyeball estimation. | 287 | // A relatively rigorous eyeball estimation. |
289 | - Duration get transitionDuration => const Duration(milliseconds: 400); | 288 | + Duration get transitionDuration; |
289 | + | ||
290 | + @override | ||
291 | + Duration get reverseTransitionDuration; | ||
290 | 292 | ||
291 | /// Builds the primary contents of the route. | 293 | /// Builds the primary contents of the route. |
292 | @protected | 294 | @protected |
@@ -360,6 +362,7 @@ Cannot read the previousTitle for a route that has not yet been installed''', | @@ -360,6 +362,7 @@ Cannot read the previousTitle for a route that has not yet been installed''', | ||
360 | Widget child, { | 362 | Widget child, { |
361 | bool limitedSwipe = false, | 363 | bool limitedSwipe = false, |
362 | double initialOffset = 0, | 364 | double initialOffset = 0, |
365 | + Transition? transition, | ||
363 | }) { | 366 | }) { |
364 | // Check if the route has an animation that's currently participating | 367 | // Check if the route has an animation that's currently participating |
365 | // in a back swipe gesture. | 368 | // in a back swipe gesture. |
@@ -408,7 +411,7 @@ Cannot read the previousTitle for a route that has not yet been installed''', | @@ -408,7 +411,7 @@ Cannot read the previousTitle for a route that has not yet been installed''', | ||
408 | final iosAnimation = animation; | 411 | final iosAnimation = animation; |
409 | animation = CurvedAnimation(parent: animation, curve: finalCurve); | 412 | animation = CurvedAnimation(parent: animation, curve: finalCurve); |
410 | 413 | ||
411 | - switch (route.transition ?? Get.defaultTransition) { | 414 | + switch (transition ?? Get.defaultTransition) { |
412 | case Transition.leftToRight: | 415 | case Transition.leftToRight: |
413 | return SlideLeftTransition().buildTransitions( | 416 | return SlideLeftTransition().buildTransitions( |
414 | context, | 417 | context, |
@@ -714,8 +717,10 @@ Cannot read the previousTitle for a route that has not yet been installed''', | @@ -714,8 +717,10 @@ Cannot read the previousTitle for a route that has not yet been installed''', | ||
714 | )); | 717 | )); |
715 | 718 | ||
716 | default: | 719 | default: |
717 | - if (Get.customTransition != null) { | ||
718 | - return Get.customTransition!.buildTransition(context, route.curve, | 720 | + final customTransition = |
721 | + context.get<GetMaterialController>().customTransition; | ||
722 | + if (customTransition != null) { | ||
723 | + return customTransition.buildTransition(context, route.curve, | ||
719 | route.alignment, animation, secondaryAnimation, child); | 724 | route.alignment, animation, secondaryAnimation, child); |
720 | } | 725 | } |
721 | 726 |
@@ -6,7 +6,7 @@ import '../router_report.dart'; | @@ -6,7 +6,7 @@ import '../router_report.dart'; | ||
6 | class Dependencies { | 6 | class Dependencies { |
7 | void lazyPut<S>(InstanceBuilderCallback<S> builder, | 7 | void lazyPut<S>(InstanceBuilderCallback<S> builder, |
8 | {String? tag, bool fenix = false}) { | 8 | {String? tag, bool fenix = false}) { |
9 | - GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); | 9 | + Get.lazyPut<S>(builder, tag: tag, fenix: fenix); |
10 | } | 10 | } |
11 | 11 | ||
12 | S call<S>() { | 12 | S call<S>() { |
@@ -15,38 +15,37 @@ class Dependencies { | @@ -15,38 +15,37 @@ class Dependencies { | ||
15 | 15 | ||
16 | Future<S> putAsync<S>(AsyncInstanceBuilderCallback<S> builder, | 16 | Future<S> putAsync<S>(AsyncInstanceBuilderCallback<S> builder, |
17 | {String? tag, bool permanent = false}) async => | 17 | {String? tag, bool permanent = false}) async => |
18 | - GetInstance().putAsync<S>(builder, tag: tag, permanent: permanent); | 18 | + Get.putAsync<S>(builder, tag: tag, permanent: permanent); |
19 | 19 | ||
20 | void create<S>(InstanceBuilderCallback<S> builder, | 20 | void create<S>(InstanceBuilderCallback<S> builder, |
21 | {String? tag, bool permanent = true}) => | 21 | {String? tag, bool permanent = true}) => |
22 | - GetInstance().create<S>(builder, tag: tag, permanent: permanent); | 22 | + Get.create<S>(builder, tag: tag, permanent: permanent); |
23 | 23 | ||
24 | - S find<S>({String? tag}) => GetInstance().find<S>(tag: tag); | 24 | + S find<S>({String? tag}) => Get.find<S>(tag: tag); |
25 | 25 | ||
26 | S put<S>(S dependency, | 26 | S put<S>(S dependency, |
27 | {String? tag, | 27 | {String? tag, |
28 | bool permanent = false, | 28 | bool permanent = false, |
29 | InstanceBuilderCallback<S>? builder}) => | 29 | InstanceBuilderCallback<S>? builder}) => |
30 | - GetInstance().put<S>(dependency, tag: tag, permanent: permanent); | 30 | + Get.put<S>(dependency, tag: tag, permanent: permanent); |
31 | 31 | ||
32 | Future<bool> delete<S>({String? tag, bool force = false}) async => | 32 | Future<bool> delete<S>({String? tag, bool force = false}) async => |
33 | - GetInstance().delete<S>(tag: tag, force: force); | 33 | + Get.delete<S>(tag: tag, force: force); |
34 | 34 | ||
35 | Future<void> deleteAll({bool force = false}) async => | 35 | Future<void> deleteAll({bool force = false}) async => |
36 | - GetInstance().deleteAll(force: force); | 36 | + Get.deleteAll(force: force); |
37 | 37 | ||
38 | - void reloadAll({bool force = false}) => GetInstance().reloadAll(force: force); | 38 | + void reloadAll({bool force = false}) => Get.reloadAll(force: force); |
39 | 39 | ||
40 | void reload<S>({String? tag, String? key, bool force = false}) => | 40 | void reload<S>({String? tag, String? key, bool force = false}) => |
41 | - GetInstance().reload<S>(tag: tag, key: key, force: force); | 41 | + Get.reload<S>(tag: tag, key: key, force: force); |
42 | 42 | ||
43 | - bool isRegistered<S>({String? tag}) => | ||
44 | - GetInstance().isRegistered<S>(tag: tag); | 43 | + bool isRegistered<S>({String? tag}) => Get.isRegistered<S>(tag: tag); |
45 | 44 | ||
46 | - bool isPrepared<S>({String? tag}) => GetInstance().isPrepared<S>(tag: tag); | 45 | + bool isPrepared<S>({String? tag}) => Get.isPrepared<S>(tag: tag); |
47 | 46 | ||
48 | void replace<P>(P child, {String? tag}) { | 47 | void replace<P>(P child, {String? tag}) { |
49 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 48 | + final info = Get.getInstanceInfo<P>(tag: tag); |
50 | final permanent = (info.isPermanent ?? false); | 49 | final permanent = (info.isPermanent ?? false); |
51 | delete<P>(tag: tag, force: permanent); | 50 | delete<P>(tag: tag, force: permanent); |
52 | put(child, tag: tag, permanent: permanent); | 51 | put(child, tag: tag, permanent: permanent); |
@@ -54,7 +53,7 @@ class Dependencies { | @@ -54,7 +53,7 @@ class Dependencies { | ||
54 | 53 | ||
55 | void lazyReplace<P>(InstanceBuilderCallback<P> builder, | 54 | void lazyReplace<P>(InstanceBuilderCallback<P> builder, |
56 | {String? tag, bool? fenix}) { | 55 | {String? tag, bool? fenix}) { |
57 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 56 | + final info = Get.getInstanceInfo<P>(tag: tag); |
58 | final permanent = (info.isPermanent ?? false); | 57 | final permanent = (info.isPermanent ?? false); |
59 | delete<P>(tag: tag, force: permanent); | 58 | delete<P>(tag: tag, force: permanent); |
60 | lazyPut(builder, tag: tag, fenix: fenix ?? permanent); | 59 | lazyPut(builder, tag: tag, fenix: fenix ?? permanent); |
@@ -55,15 +55,12 @@ extension PageArgExt on BuildContext { | @@ -55,15 +55,12 @@ extension PageArgExt on BuildContext { | ||
55 | class PageSettings extends RouteSettings { | 55 | class PageSettings extends RouteSettings { |
56 | PageSettings( | 56 | PageSettings( |
57 | this.uri, [ | 57 | this.uri, [ |
58 | - this.arguments, | ||
59 | - ]); | 58 | + Object? arguments, |
59 | + ]) : super(arguments: arguments); | ||
60 | 60 | ||
61 | @override | 61 | @override |
62 | String get name => '$uri'; | 62 | String get name => '$uri'; |
63 | 63 | ||
64 | - @override | ||
65 | - late final Object? arguments; | ||
66 | - | ||
67 | final Uri uri; | 64 | final Uri uri; |
68 | 65 | ||
69 | final params = <String, String>{}; | 66 | final params = <String, String>{}; |
@@ -14,7 +14,8 @@ class RouteDecoder { | @@ -14,7 +14,8 @@ class RouteDecoder { | ||
14 | factory RouteDecoder.fromRoute(String location) { | 14 | factory RouteDecoder.fromRoute(String location) { |
15 | var uri = Uri.parse(location); | 15 | var uri = Uri.parse(location); |
16 | final args = PageSettings(uri); | 16 | final args = PageSettings(uri); |
17 | - final decoder = Get.routeTree.matchRoute(location, arguments: args); | 17 | + final decoder = (Get.rootController.routerDelegate as GetDelegate) |
18 | + .matchRoute(location, arguments: args); | ||
18 | decoder.route = decoder.route?.copy( | 19 | decoder.route = decoder.route?.copy( |
19 | completer: null, | 20 | completer: null, |
20 | arguments: args, | 21 | arguments: args, |
@@ -93,7 +94,7 @@ class ParseRouteTree { | @@ -93,7 +94,7 @@ class ParseRouteTree { | ||
93 | ]; | 94 | ]; |
94 | for (var item in split) { | 95 | for (var item in split) { |
95 | if (curPath.endsWith('/')) { | 96 | if (curPath.endsWith('/')) { |
96 | - curPath += '$item'; | 97 | + curPath += item; |
97 | } else { | 98 | } else { |
98 | curPath += '/$item'; | 99 | curPath += '/$item'; |
99 | } | 100 | } |
1 | +import 'dart:async'; | ||
2 | + | ||
1 | import 'package:flutter/cupertino.dart'; | 3 | import 'package:flutter/cupertino.dart'; |
2 | -import 'package:flutter/foundation.dart'; | ||
3 | 4 | ||
4 | import '../../../get.dart'; | 5 | import '../../../get.dart'; |
5 | 6 | ||
@@ -51,7 +52,7 @@ abstract class _RouteMiddleware { | @@ -51,7 +52,7 @@ abstract class _RouteMiddleware { | ||
51 | /// } | 52 | /// } |
52 | /// ``` | 53 | /// ``` |
53 | /// {@end-tool} | 54 | /// {@end-tool} |
54 | - Future<RouteDecoder?> redirectDelegate(RouteDecoder route); | 55 | + FutureOr<RouteDecoder?> redirectDelegate(RouteDecoder route); |
55 | 56 | ||
56 | /// This function will be called when this Page is called | 57 | /// This function will be called when this Page is called |
57 | /// you can use it to change something about the page or give it new page | 58 | /// you can use it to change something about the page or give it new page |
@@ -65,8 +66,8 @@ abstract class _RouteMiddleware { | @@ -65,8 +66,8 @@ abstract class _RouteMiddleware { | ||
65 | /// {@end-tool} | 66 | /// {@end-tool} |
66 | GetPage? onPageCalled(GetPage page); | 67 | GetPage? onPageCalled(GetPage page); |
67 | 68 | ||
68 | - /// This function will be called right before the [Bindings] are initialize. | ||
69 | - /// Here you can change [Bindings] for this page | 69 | + /// This function will be called right before the [BindingsInterface] are initialize. |
70 | + /// Here you can change [BindingsInterface] for this page | ||
70 | /// {@tool snippet} | 71 | /// {@tool snippet} |
71 | /// ```dart | 72 | /// ```dart |
72 | /// List<Bindings> onBindingsStart(List<Bindings> bindings) { | 73 | /// List<Bindings> onBindingsStart(List<Bindings> bindings) { |
@@ -80,7 +81,7 @@ abstract class _RouteMiddleware { | @@ -80,7 +81,7 @@ abstract class _RouteMiddleware { | ||
80 | /// {@end-tool} | 81 | /// {@end-tool} |
81 | List<R>? onBindingsStart<R>(List<R> bindings); | 82 | List<R>? onBindingsStart<R>(List<R> bindings); |
82 | 83 | ||
83 | - /// This function will be called right after the [Bindings] are initialize. | 84 | + /// This function will be called right after the [BindingsInterface] are initialize. |
84 | GetPageBuilder? onPageBuildStart(GetPageBuilder page); | 85 | GetPageBuilder? onPageBuildStart(GetPageBuilder page); |
85 | 86 | ||
86 | /// This function will be called right after the | 87 | /// This function will be called right after the |
@@ -120,8 +121,7 @@ class GetMiddleware implements _RouteMiddleware { | @@ -120,8 +121,7 @@ class GetMiddleware implements _RouteMiddleware { | ||
120 | void onPageDispose() {} | 121 | void onPageDispose() {} |
121 | 122 | ||
122 | @override | 123 | @override |
123 | - Future<RouteDecoder?> redirectDelegate(RouteDecoder route) => | ||
124 | - SynchronousFuture(route); | 124 | + FutureOr<RouteDecoder?> redirectDelegate(RouteDecoder route) => (route); |
125 | } | 125 | } |
126 | 126 | ||
127 | class MiddlewareRunner { | 127 | class MiddlewareRunner { |
@@ -195,37 +195,9 @@ class PageRedirect { | @@ -195,37 +195,9 @@ class PageRedirect { | ||
195 | }); | 195 | }); |
196 | 196 | ||
197 | // redirect all pages that needes redirecting | 197 | // redirect all pages that needes redirecting |
198 | - GetPageRoute<T> page<T>() { | ||
199 | - while (needRecheck()) {} | ||
200 | - final _r = (isUnknown ? unknownRoute : route)!; | ||
201 | - return GetPageRoute<T>( | ||
202 | - page: _r.page, | ||
203 | - parameter: _r.parameters, | ||
204 | - settings: isUnknown | ||
205 | - ? RouteSettings( | ||
206 | - name: _r.name, | ||
207 | - arguments: settings!.arguments, | ||
208 | - ) | ||
209 | - : settings, | ||
210 | - curve: _r.curve, | ||
211 | - opaque: _r.opaque, | ||
212 | - showCupertinoParallax: _r.showCupertinoParallax, | ||
213 | - gestureWidth: _r.gestureWidth, | ||
214 | - customTransition: _r.customTransition, | ||
215 | - bindings: _r.bindings, | ||
216 | - binds: _r.binds, | ||
217 | - transitionDuration: | ||
218 | - _r.transitionDuration ?? Get.defaultTransitionDuration, | ||
219 | - transition: _r.transition, | ||
220 | - popGesture: _r.popGesture, | ||
221 | - fullscreenDialog: _r.fullscreenDialog, | ||
222 | - middlewares: _r.middlewares, | ||
223 | - ); | ||
224 | - } | ||
225 | - | ||
226 | - // redirect all pages that needes redirecting | ||
227 | - GetPageRoute<T> getPageToRoute<T>(GetPage rou, GetPage? unk) { | ||
228 | - while (needRecheck()) {} | 198 | + GetPageRoute<T> getPageToRoute<T>( |
199 | + GetPage rou, GetPage? unk, BuildContext context) { | ||
200 | + while (needRecheck(context)) {} | ||
229 | final _r = (isUnknown ? unk : rou)!; | 201 | final _r = (isUnknown ? unk : rou)!; |
230 | 202 | ||
231 | return GetPageRoute<T>( | 203 | return GetPageRoute<T>( |
@@ -242,9 +214,14 @@ class PageRedirect { | @@ -242,9 +214,14 @@ class PageRedirect { | ||
242 | opaque: _r.opaque, | 214 | opaque: _r.opaque, |
243 | customTransition: _r.customTransition, | 215 | customTransition: _r.customTransition, |
244 | bindings: _r.bindings, | 216 | bindings: _r.bindings, |
217 | + binding: _r.binding, | ||
245 | binds: _r.binds, | 218 | binds: _r.binds, |
246 | transitionDuration: | 219 | transitionDuration: |
247 | _r.transitionDuration ?? Get.defaultTransitionDuration, | 220 | _r.transitionDuration ?? Get.defaultTransitionDuration, |
221 | + reverseTransitionDuration: | ||
222 | + _r.reverseTransitionDuration ?? Get.defaultTransitionDuration, | ||
223 | + // performIncomeAnimation: _r.performIncomeAnimation, | ||
224 | + // performOutGoingAnimation: _r.performOutGoingAnimation, | ||
248 | transition: _r.transition, | 225 | transition: _r.transition, |
249 | popGesture: _r.popGesture, | 226 | popGesture: _r.popGesture, |
250 | fullscreenDialog: _r.fullscreenDialog, | 227 | fullscreenDialog: _r.fullscreenDialog, |
@@ -253,11 +230,11 @@ class PageRedirect { | @@ -253,11 +230,11 @@ class PageRedirect { | ||
253 | } | 230 | } |
254 | 231 | ||
255 | /// check if redirect is needed | 232 | /// check if redirect is needed |
256 | - bool needRecheck() { | 233 | + bool needRecheck(BuildContext context) { |
257 | if (settings == null && route != null) { | 234 | if (settings == null && route != null) { |
258 | settings = route; | 235 | settings = route; |
259 | } | 236 | } |
260 | - final match = Get.routeTree.matchRoute(settings!.name!); | 237 | + final match = context.navigation.matchRoute(settings!.name!); |
261 | Get.parameters = match.parameters; | 238 | Get.parameters = match.parameters; |
262 | 239 | ||
263 | // No Match found | 240 | // No Match found |
@@ -29,7 +29,7 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object> | @@ -29,7 +29,7 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object> | ||
29 | final rDelegate = context.delegate as TDelegate; | 29 | final rDelegate = context.delegate as TDelegate; |
30 | var picked = | 30 | var picked = |
31 | currentConfig == null ? null : pickPages(currentConfig); | 31 | currentConfig == null ? null : pickPages(currentConfig); |
32 | - if (picked?.length == 0) { | 32 | + if (picked?.isEmpty ?? true) { |
33 | picked = null; | 33 | picked = null; |
34 | } | 34 | } |
35 | return pageBuilder(context, rDelegate, picked); | 35 | return pageBuilder(context, rDelegate, picked); |
@@ -68,7 +68,8 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | @@ -68,7 +68,8 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | ||
68 | @override | 68 | @override |
69 | void dispose() { | 69 | void dispose() { |
70 | super.dispose(); | 70 | super.dispose(); |
71 | - Get.routerDelegate?.removeListener(_listener); | 71 | + disposer?.call(); |
72 | + // Get.routerDelegate?.removeListener(_listener); | ||
72 | //_backButtonDispatcher.forget(_backButtonDispatcher) | 73 | //_backButtonDispatcher.forget(_backButtonDispatcher) |
73 | } | 74 | } |
74 | 75 | ||
@@ -146,7 +147,7 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | @@ -146,7 +147,7 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | ||
146 | return ret; | 147 | return ret; |
147 | }, | 148 | }, |
148 | emptyPage: (delegate) => | 149 | emptyPage: (delegate) => |
149 | - Get.routeTree.matchRoute(initialRoute).route ?? | 150 | + delegate.matchRoute(initialRoute).route ?? |
150 | delegate.notFoundRoute, | 151 | delegate.notFoundRoute, |
151 | key: Get.nestedKey(anchorRoute)?.navigatorKey, | 152 | key: Get.nestedKey(anchorRoute)?.navigatorKey, |
152 | delegate: delegate, | 153 | delegate: delegate, |
@@ -162,11 +163,10 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | @@ -162,11 +163,10 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> { | ||
162 | pageBuilder: (context, rDelegate, pages) { | 163 | pageBuilder: (context, rDelegate, pages) { |
163 | final pageRes = <GetPage?>[ | 164 | final pageRes = <GetPage?>[ |
164 | ...?pages, | 165 | ...?pages, |
165 | - if (pages == null || pages.length == 0) | ||
166 | - emptyPage?.call(rDelegate), | 166 | + if (pages == null || pages.isEmpty) emptyPage?.call(rDelegate), |
167 | ].whereType<GetPage>(); | 167 | ].whereType<GetPage>(); |
168 | 168 | ||
169 | - if (pageRes.length > 0) { | 169 | + if (pageRes.isNotEmpty) { |
170 | return GetNavigator( | 170 | return GetNavigator( |
171 | onPopPage: onPopPage ?? | 171 | onPopPage: onPopPage ?? |
172 | (route, result) { | 172 | (route, result) { |
1 | -import 'dart:html'; | ||
2 | - | ||
3 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | 1 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; |
4 | 2 | ||
5 | void removeHash() { | 3 | void removeHash() { |
6 | setUrlStrategy(PathUrlStrategy()); | 4 | setUrlStrategy(PathUrlStrategy()); |
7 | } | 5 | } |
8 | - | ||
9 | -void removeLastHistory(String? url) { | ||
10 | - window.location.replace(null); | ||
11 | -} |
@@ -40,8 +40,8 @@ class GetBar extends GetSnackBar { | @@ -40,8 +40,8 @@ class GetBar extends GetSnackBar { | ||
40 | AnimationController? progressIndicatorController, | 40 | AnimationController? progressIndicatorController, |
41 | Color? progressIndicatorBackgroundColor, | 41 | Color? progressIndicatorBackgroundColor, |
42 | Animation<Color>? progressIndicatorValueColor, | 42 | Animation<Color>? progressIndicatorValueColor, |
43 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
44 | - SnackStyle snackStyle = SnackStyle.FLOATING, | 43 | + SnackPosition snackPosition = SnackPosition.bottom, |
44 | + SnackStyle snackStyle = SnackStyle.floating, | ||
45 | Curve forwardAnimationCurve = Curves.easeOutCirc, | 45 | Curve forwardAnimationCurve = Curves.easeOutCirc, |
46 | Curve reverseAnimationCurve = Curves.easeOutCirc, | 46 | Curve reverseAnimationCurve = Curves.easeOutCirc, |
47 | Duration animationDuration = const Duration(seconds: 1), | 47 | Duration animationDuration = const Duration(seconds: 1), |
@@ -267,8 +267,8 @@ class GetSnackBar extends StatefulWidget { | @@ -267,8 +267,8 @@ class GetSnackBar extends StatefulWidget { | ||
267 | this.progressIndicatorController, | 267 | this.progressIndicatorController, |
268 | this.progressIndicatorBackgroundColor, | 268 | this.progressIndicatorBackgroundColor, |
269 | this.progressIndicatorValueColor, | 269 | this.progressIndicatorValueColor, |
270 | - this.snackPosition = SnackPosition.BOTTOM, | ||
271 | - this.snackStyle = SnackStyle.FLOATING, | 270 | + this.snackPosition = SnackPosition.bottom, |
271 | + this.snackStyle = SnackStyle.floating, | ||
272 | this.forwardAnimationCurve = Curves.easeOutCirc, | 272 | this.forwardAnimationCurve = Curves.easeOutCirc, |
273 | this.reverseAnimationCurve = Curves.easeOutCirc, | 273 | this.reverseAnimationCurve = Curves.easeOutCirc, |
274 | this.animationDuration = const Duration(seconds: 1), | 274 | this.animationDuration = const Duration(seconds: 1), |
@@ -337,16 +337,16 @@ class GetSnackBarState extends State<GetSnackBar> | @@ -337,16 +337,16 @@ class GetSnackBarState extends State<GetSnackBar> | ||
337 | return Align( | 337 | return Align( |
338 | heightFactor: 1.0, | 338 | heightFactor: 1.0, |
339 | child: Material( | 339 | child: Material( |
340 | - color: widget.snackStyle == SnackStyle.FLOATING | 340 | + color: widget.snackStyle == SnackStyle.floating |
341 | ? Colors.transparent | 341 | ? Colors.transparent |
342 | : widget.backgroundColor, | 342 | : widget.backgroundColor, |
343 | child: SafeArea( | 343 | child: SafeArea( |
344 | - minimum: widget.snackPosition == SnackPosition.BOTTOM | 344 | + minimum: widget.snackPosition == SnackPosition.bottom |
345 | ? EdgeInsets.only( | 345 | ? EdgeInsets.only( |
346 | bottom: MediaQuery.of(context).viewInsets.bottom) | 346 | bottom: MediaQuery.of(context).viewInsets.bottom) |
347 | : EdgeInsets.only(top: MediaQuery.of(context).padding.top), | 347 | : EdgeInsets.only(top: MediaQuery.of(context).padding.top), |
348 | - bottom: widget.snackPosition == SnackPosition.BOTTOM, | ||
349 | - top: widget.snackPosition == SnackPosition.TOP, | 348 | + bottom: widget.snackPosition == SnackPosition.bottom, |
349 | + top: widget.snackPosition == SnackPosition.top, | ||
350 | left: false, | 350 | left: false, |
351 | right: false, | 351 | right: false, |
352 | child: Stack( | 352 | child: Stack( |
@@ -651,10 +651,10 @@ enum RowStyle { | @@ -651,10 +651,10 @@ enum RowStyle { | ||
651 | /// snackbar display, [SnackbarStatus.CLOSING] Starts with the closing animation | 651 | /// snackbar display, [SnackbarStatus.CLOSING] Starts with the closing animation |
652 | /// and ends | 652 | /// and ends |
653 | /// with the full snackbar dispose | 653 | /// with the full snackbar dispose |
654 | -enum SnackbarStatus { OPEN, CLOSED, OPENING, CLOSING } | 654 | +enum SnackbarStatus { open, closed, opening, closing } |
655 | 655 | ||
656 | /// Indicates if snack is going to start at the [TOP] or at the [BOTTOM] | 656 | /// Indicates if snack is going to start at the [TOP] or at the [BOTTOM] |
657 | -enum SnackPosition { TOP, BOTTOM } | 657 | +enum SnackPosition { top, bottom } |
658 | 658 | ||
659 | /// Indicates if snack will be attached to the edge of the screen or not | 659 | /// Indicates if snack will be attached to the edge of the screen or not |
660 | -enum SnackStyle { FLOATING, GROUNDED } | 660 | +enum SnackStyle { floating, grounded } |
@@ -72,13 +72,13 @@ class SnackbarController { | @@ -72,13 +72,13 @@ class SnackbarController { | ||
72 | // ignore: avoid_returning_this | 72 | // ignore: avoid_returning_this |
73 | void _configureAlignment(SnackPosition snackPosition) { | 73 | void _configureAlignment(SnackPosition snackPosition) { |
74 | switch (snackbar.snackPosition) { | 74 | switch (snackbar.snackPosition) { |
75 | - case SnackPosition.TOP: | 75 | + case SnackPosition.top: |
76 | { | 76 | { |
77 | _initialAlignment = const Alignment(-1.0, -2.0); | 77 | _initialAlignment = const Alignment(-1.0, -2.0); |
78 | _endAlignment = const Alignment(-1.0, -1.0); | 78 | _endAlignment = const Alignment(-1.0, -1.0); |
79 | break; | 79 | break; |
80 | } | 80 | } |
81 | - case SnackPosition.BOTTOM: | 81 | + case SnackPosition.bottom: |
82 | { | 82 | { |
83 | _initialAlignment = const Alignment(-1.0, 2.0); | 83 | _initialAlignment = const Alignment(-1.0, 2.0); |
84 | _endAlignment = const Alignment(-1.0, 1.0); | 84 | _endAlignment = const Alignment(-1.0, 1.0); |
@@ -248,7 +248,7 @@ class SnackbarController { | @@ -248,7 +248,7 @@ class SnackbarController { | ||
248 | } | 248 | } |
249 | 249 | ||
250 | DismissDirection _getDefaultDismissDirection() { | 250 | DismissDirection _getDefaultDismissDirection() { |
251 | - if (snackbar.snackPosition == SnackPosition.TOP) { | 251 | + if (snackbar.snackPosition == SnackPosition.top) { |
252 | return DismissDirection.up; | 252 | return DismissDirection.up; |
253 | } | 253 | } |
254 | return DismissDirection.down; | 254 | return DismissDirection.down; |
@@ -259,8 +259,8 @@ class SnackbarController { | @@ -259,8 +259,8 @@ class SnackbarController { | ||
259 | direction: snackbar.dismissDirection ?? _getDefaultDismissDirection(), | 259 | direction: snackbar.dismissDirection ?? _getDefaultDismissDirection(), |
260 | resizeDuration: null, | 260 | resizeDuration: null, |
261 | confirmDismiss: (_) { | 261 | confirmDismiss: (_) { |
262 | - if (_currentStatus == SnackbarStatus.OPENING || | ||
263 | - _currentStatus == SnackbarStatus.CLOSING) { | 262 | + if (_currentStatus == SnackbarStatus.opening || |
263 | + _currentStatus == SnackbarStatus.closing) { | ||
264 | return Future.value(false); | 264 | return Future.value(false); |
265 | } | 265 | } |
266 | return Future.value(true); | 266 | return Future.value(true); |
@@ -284,23 +284,23 @@ class SnackbarController { | @@ -284,23 +284,23 @@ class SnackbarController { | ||
284 | void _handleStatusChanged(AnimationStatus status) { | 284 | void _handleStatusChanged(AnimationStatus status) { |
285 | switch (status) { | 285 | switch (status) { |
286 | case AnimationStatus.completed: | 286 | case AnimationStatus.completed: |
287 | - _currentStatus = SnackbarStatus.OPEN; | 287 | + _currentStatus = SnackbarStatus.open; |
288 | _snackbarStatus?.call(_currentStatus); | 288 | _snackbarStatus?.call(_currentStatus); |
289 | if (_overlayEntries.isNotEmpty) _overlayEntries.first.opaque = false; | 289 | if (_overlayEntries.isNotEmpty) _overlayEntries.first.opaque = false; |
290 | 290 | ||
291 | break; | 291 | break; |
292 | case AnimationStatus.forward: | 292 | case AnimationStatus.forward: |
293 | - _currentStatus = SnackbarStatus.OPENING; | 293 | + _currentStatus = SnackbarStatus.opening; |
294 | _snackbarStatus?.call(_currentStatus); | 294 | _snackbarStatus?.call(_currentStatus); |
295 | break; | 295 | break; |
296 | case AnimationStatus.reverse: | 296 | case AnimationStatus.reverse: |
297 | - _currentStatus = SnackbarStatus.CLOSING; | 297 | + _currentStatus = SnackbarStatus.closing; |
298 | _snackbarStatus?.call(_currentStatus); | 298 | _snackbarStatus?.call(_currentStatus); |
299 | if (_overlayEntries.isNotEmpty) _overlayEntries.first.opaque = false; | 299 | if (_overlayEntries.isNotEmpty) _overlayEntries.first.opaque = false; |
300 | break; | 300 | break; |
301 | case AnimationStatus.dismissed: | 301 | case AnimationStatus.dismissed: |
302 | assert(!_overlayEntries.first.opaque); | 302 | assert(!_overlayEntries.first.opaque); |
303 | - _currentStatus = SnackbarStatus.CLOSED; | 303 | + _currentStatus = SnackbarStatus.closed; |
304 | _snackbarStatus?.call(_currentStatus); | 304 | _snackbarStatus?.call(_currentStatus); |
305 | _removeOverlay(); | 305 | _removeOverlay(); |
306 | break; | 306 | break; |
@@ -145,7 +145,7 @@ abstract class _RxImpl<T> extends GetListenable<T> with RxObjectMixin<T> { | @@ -145,7 +145,7 @@ abstract class _RxImpl<T> extends GetListenable<T> with RxObjectMixin<T> { | ||
145 | subject.addError(error, stackTrace); | 145 | subject.addError(error, stackTrace); |
146 | } | 146 | } |
147 | 147 | ||
148 | - Stream<R> map<R>(R mapper(T? data)) => stream.map(mapper); | 148 | + Stream<R> map<R>(R Function(T? data) mapper) => stream.map(mapper); |
149 | 149 | ||
150 | /// Uses a callback to update [value] internally, similar to [refresh], | 150 | /// Uses a callback to update [value] internally, similar to [refresh], |
151 | /// but provides the current value as the argument. | 151 | /// but provides the current value as the argument. |
@@ -167,9 +167,9 @@ abstract class _RxImpl<T> extends GetListenable<T> with RxObjectMixin<T> { | @@ -167,9 +167,9 @@ abstract class _RxImpl<T> extends GetListenable<T> with RxObjectMixin<T> { | ||
167 | /// }); | 167 | /// }); |
168 | /// print( person ); | 168 | /// print( person ); |
169 | /// ``` | 169 | /// ``` |
170 | - void update(void fn(T? val)) { | ||
171 | - fn(value); | ||
172 | - subject.add(value); | 170 | + void update(T Function(T? val) fn) { |
171 | + value = fn(value); | ||
172 | + // subject.add(value); | ||
173 | } | 173 | } |
174 | 174 | ||
175 | /// Following certain practices on Rx data, we might want to react to certain | 175 | /// Following certain practices on Rx data, we might want to react to certain |
@@ -248,18 +248,21 @@ extension RxnBoolExt on Rx<bool?> { | @@ -248,18 +248,21 @@ extension RxnBoolExt on Rx<bool?> { | ||
248 | 248 | ||
249 | bool? get isFalse { | 249 | bool? get isFalse { |
250 | if (value != null) return !isTrue!; | 250 | if (value != null) return !isTrue!; |
251 | + return null; | ||
251 | } | 252 | } |
252 | 253 | ||
253 | bool? operator &(bool other) { | 254 | bool? operator &(bool other) { |
254 | if (value != null) { | 255 | if (value != null) { |
255 | return other && value!; | 256 | return other && value!; |
256 | } | 257 | } |
258 | + return null; | ||
257 | } | 259 | } |
258 | 260 | ||
259 | bool? operator |(bool other) { | 261 | bool? operator |(bool other) { |
260 | if (value != null) { | 262 | if (value != null) { |
261 | return other || value!; | 263 | return other || value!; |
262 | } | 264 | } |
265 | + return null; | ||
263 | } | 266 | } |
264 | 267 | ||
265 | bool? operator ^(bool other) => !other == value; | 268 | bool? operator ^(bool other) => !other == value; |
@@ -269,6 +269,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -269,6 +269,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
269 | if (value != null) { | 269 | if (value != null) { |
270 | return value! * other; | 270 | return value! * other; |
271 | } | 271 | } |
272 | + return null; | ||
272 | } | 273 | } |
273 | 274 | ||
274 | /// Euclidean modulo operator. | 275 | /// Euclidean modulo operator. |
@@ -288,6 +289,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -288,6 +289,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
288 | if (value != null) { | 289 | if (value != null) { |
289 | return value! % other; | 290 | return value! % other; |
290 | } | 291 | } |
292 | + return null; | ||
291 | } | 293 | } |
292 | 294 | ||
293 | /// Division operator. | 295 | /// Division operator. |
@@ -295,6 +297,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -295,6 +297,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
295 | if (value != null) { | 297 | if (value != null) { |
296 | return value! / other; | 298 | return value! / other; |
297 | } | 299 | } |
300 | + return null; | ||
298 | } | 301 | } |
299 | 302 | ||
300 | /// Truncating division operator. | 303 | /// Truncating division operator. |
@@ -308,6 +311,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -308,6 +311,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
308 | if (value != null) { | 311 | if (value != null) { |
309 | return value! ~/ other; | 312 | return value! ~/ other; |
310 | } | 313 | } |
314 | + return null; | ||
311 | } | 315 | } |
312 | 316 | ||
313 | /// Negate operator. | 317 | /// Negate operator. |
@@ -315,6 +319,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -315,6 +319,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
315 | if (value != null) { | 319 | if (value != null) { |
316 | return -value!; | 320 | return -value!; |
317 | } | 321 | } |
322 | + return null; | ||
318 | } | 323 | } |
319 | 324 | ||
320 | /// Returns the remainder of the truncating division of `this` by [other]. | 325 | /// Returns the remainder of the truncating division of `this` by [other]. |
@@ -330,6 +335,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -330,6 +335,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
330 | if (value != null) { | 335 | if (value != null) { |
331 | return value! < other; | 336 | return value! < other; |
332 | } | 337 | } |
338 | + return null; | ||
333 | } | 339 | } |
334 | 340 | ||
335 | /// Relational less than or equal operator. | 341 | /// Relational less than or equal operator. |
@@ -337,6 +343,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -337,6 +343,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
337 | if (value != null) { | 343 | if (value != null) { |
338 | return value! <= other; | 344 | return value! <= other; |
339 | } | 345 | } |
346 | + return null; | ||
340 | } | 347 | } |
341 | 348 | ||
342 | /// Relational greater than operator. | 349 | /// Relational greater than operator. |
@@ -344,6 +351,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -344,6 +351,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
344 | if (value != null) { | 351 | if (value != null) { |
345 | return value! > other; | 352 | return value! > other; |
346 | } | 353 | } |
354 | + return null; | ||
347 | } | 355 | } |
348 | 356 | ||
349 | /// Relational greater than or equal operator. | 357 | /// Relational greater than or equal operator. |
@@ -351,6 +359,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | @@ -351,6 +359,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { | ||
351 | if (value != null) { | 359 | if (value != null) { |
352 | return value! >= other; | 360 | return value! >= other; |
353 | } | 361 | } |
362 | + return null; | ||
354 | } | 363 | } |
355 | 364 | ||
356 | /// True if the number is the double Not-a-Number value; otherwise, false. | 365 | /// True if the number is the double Not-a-Number value; otherwise, false. |
@@ -585,6 +594,7 @@ class RxnNum extends Rx<num?> { | @@ -585,6 +594,7 @@ class RxnNum extends Rx<num?> { | ||
585 | value = value! + other; | 594 | value = value! + other; |
586 | return value; | 595 | return value; |
587 | } | 596 | } |
597 | + return null; | ||
588 | } | 598 | } |
589 | 599 | ||
590 | /// Subtraction operator. | 600 | /// Subtraction operator. |
@@ -593,6 +603,7 @@ class RxnNum extends Rx<num?> { | @@ -593,6 +603,7 @@ class RxnNum extends Rx<num?> { | ||
593 | value = value! - other; | 603 | value = value! - other; |
594 | return value; | 604 | return value; |
595 | } | 605 | } |
606 | + return null; | ||
596 | } | 607 | } |
597 | } | 608 | } |
598 | 609 | ||
@@ -711,6 +722,7 @@ extension RxnDoubleExt on Rx<double?> { | @@ -711,6 +722,7 @@ extension RxnDoubleExt on Rx<double?> { | ||
711 | value = value! + other; | 722 | value = value! + other; |
712 | return this; | 723 | return this; |
713 | } | 724 | } |
725 | + return null; | ||
714 | } | 726 | } |
715 | 727 | ||
716 | /// Subtraction operator. | 728 | /// Subtraction operator. |
@@ -719,6 +731,7 @@ extension RxnDoubleExt on Rx<double?> { | @@ -719,6 +731,7 @@ extension RxnDoubleExt on Rx<double?> { | ||
719 | value = value! + other; | 731 | value = value! + other; |
720 | return this; | 732 | return this; |
721 | } | 733 | } |
734 | + return null; | ||
722 | } | 735 | } |
723 | 736 | ||
724 | /// Multiplication operator. | 737 | /// Multiplication operator. |
@@ -726,12 +739,14 @@ extension RxnDoubleExt on Rx<double?> { | @@ -726,12 +739,14 @@ extension RxnDoubleExt on Rx<double?> { | ||
726 | if (value != null) { | 739 | if (value != null) { |
727 | return value! * other; | 740 | return value! * other; |
728 | } | 741 | } |
742 | + return null; | ||
729 | } | 743 | } |
730 | 744 | ||
731 | double? operator %(num other) { | 745 | double? operator %(num other) { |
732 | if (value != null) { | 746 | if (value != null) { |
733 | return value! % other; | 747 | return value! % other; |
734 | } | 748 | } |
749 | + return null; | ||
735 | } | 750 | } |
736 | 751 | ||
737 | /// Division operator. | 752 | /// Division operator. |
@@ -739,6 +754,7 @@ extension RxnDoubleExt on Rx<double?> { | @@ -739,6 +754,7 @@ extension RxnDoubleExt on Rx<double?> { | ||
739 | if (value != null) { | 754 | if (value != null) { |
740 | return value! / other; | 755 | return value! / other; |
741 | } | 756 | } |
757 | + return null; | ||
742 | } | 758 | } |
743 | 759 | ||
744 | /// Truncating division operator. | 760 | /// Truncating division operator. |
@@ -749,6 +765,7 @@ extension RxnDoubleExt on Rx<double?> { | @@ -749,6 +765,7 @@ extension RxnDoubleExt on Rx<double?> { | ||
749 | if (value != null) { | 765 | if (value != null) { |
750 | return value! ~/ other; | 766 | return value! ~/ other; |
751 | } | 767 | } |
768 | + return null; | ||
752 | } | 769 | } |
753 | 770 | ||
754 | /// Negate operator. */ | 771 | /// Negate operator. */ |
@@ -756,6 +773,7 @@ extension RxnDoubleExt on Rx<double?> { | @@ -756,6 +773,7 @@ extension RxnDoubleExt on Rx<double?> { | ||
756 | if (value != null) { | 773 | if (value != null) { |
757 | return -value!; | 774 | return -value!; |
758 | } | 775 | } |
776 | + return null; | ||
759 | } | 777 | } |
760 | 778 | ||
761 | /// Returns the absolute value of this [double]. | 779 | /// Returns the absolute value of this [double]. |
@@ -1104,6 +1122,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1104,6 +1122,7 @@ extension RxnIntExt on Rx<int?> { | ||
1104 | if (value != null) { | 1122 | if (value != null) { |
1105 | return value! & other; | 1123 | return value! & other; |
1106 | } | 1124 | } |
1125 | + return null; | ||
1107 | } | 1126 | } |
1108 | 1127 | ||
1109 | /// Bit-wise or operator. | 1128 | /// Bit-wise or operator. |
@@ -1118,6 +1137,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1118,6 +1137,7 @@ extension RxnIntExt on Rx<int?> { | ||
1118 | if (value != null) { | 1137 | if (value != null) { |
1119 | return value! | other; | 1138 | return value! | other; |
1120 | } | 1139 | } |
1140 | + return null; | ||
1121 | } | 1141 | } |
1122 | 1142 | ||
1123 | /// Bit-wise exclusive-or operator. | 1143 | /// Bit-wise exclusive-or operator. |
@@ -1132,6 +1152,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1132,6 +1152,7 @@ extension RxnIntExt on Rx<int?> { | ||
1132 | if (value != null) { | 1152 | if (value != null) { |
1133 | return value! ^ other; | 1153 | return value! ^ other; |
1134 | } | 1154 | } |
1155 | + return null; | ||
1135 | } | 1156 | } |
1136 | 1157 | ||
1137 | /// The bit-wise negate operator. | 1158 | /// The bit-wise negate operator. |
@@ -1144,6 +1165,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1144,6 +1165,7 @@ extension RxnIntExt on Rx<int?> { | ||
1144 | if (value != null) { | 1165 | if (value != null) { |
1145 | return ~value!; | 1166 | return ~value!; |
1146 | } | 1167 | } |
1168 | + return null; | ||
1147 | } | 1169 | } |
1148 | 1170 | ||
1149 | /// Shift the bits of this integer to the left by [shiftAmount]. | 1171 | /// Shift the bits of this integer to the left by [shiftAmount]. |
@@ -1160,6 +1182,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1160,6 +1182,7 @@ extension RxnIntExt on Rx<int?> { | ||
1160 | if (value != null) { | 1182 | if (value != null) { |
1161 | return value! << shiftAmount; | 1183 | return value! << shiftAmount; |
1162 | } | 1184 | } |
1185 | + return null; | ||
1163 | } | 1186 | } |
1164 | 1187 | ||
1165 | /// Shift the bits of this integer to the right by [shiftAmount]. | 1188 | /// Shift the bits of this integer to the right by [shiftAmount]. |
@@ -1173,6 +1196,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1173,6 +1196,7 @@ extension RxnIntExt on Rx<int?> { | ||
1173 | if (value != null) { | 1196 | if (value != null) { |
1174 | return value! >> shiftAmount; | 1197 | return value! >> shiftAmount; |
1175 | } | 1198 | } |
1199 | + return null; | ||
1176 | } | 1200 | } |
1177 | 1201 | ||
1178 | /// Returns this integer to the power of [exponent] modulo [modulus]. | 1202 | /// Returns this integer to the power of [exponent] modulo [modulus]. |
@@ -1290,6 +1314,7 @@ extension RxnIntExt on Rx<int?> { | @@ -1290,6 +1314,7 @@ extension RxnIntExt on Rx<int?> { | ||
1290 | if (value != null) { | 1314 | if (value != null) { |
1291 | return -value!; | 1315 | return -value!; |
1292 | } | 1316 | } |
1317 | + return null; | ||
1293 | } | 1318 | } |
1294 | 1319 | ||
1295 | /// Returns the absolute value of this integer. | 1320 | /// Returns the absolute value of this integer. |
@@ -24,7 +24,7 @@ class RxList<E> extends GetListenable<List<E>> | @@ -24,7 +24,7 @@ class RxList<E> extends GetListenable<List<E>> | ||
24 | } | 24 | } |
25 | 25 | ||
26 | /// Generates a list of values. | 26 | /// Generates a list of values. |
27 | - factory RxList.generate(int length, E generator(int index), | 27 | + factory RxList.generate(int length, E Function(int index) generator, |
28 | {bool growable = true}) { | 28 | {bool growable = true}) { |
29 | return RxList(List.generate(length, generator, growable: growable)); | 29 | return RxList(List.generate(length, generator, growable: growable)); |
30 | } | 30 | } |
@@ -58,25 +58,25 @@ class RxList<E> extends GetListenable<List<E>> | @@ -58,25 +58,25 @@ class RxList<E> extends GetListenable<List<E>> | ||
58 | } | 58 | } |
59 | 59 | ||
60 | @override | 60 | @override |
61 | - void add(E item) { | ||
62 | - value.add(item); | 61 | + void add(E element) { |
62 | + value.add(element); | ||
63 | refresh(); | 63 | refresh(); |
64 | } | 64 | } |
65 | 65 | ||
66 | @override | 66 | @override |
67 | - void addAll(Iterable<E> item) { | ||
68 | - value.addAll(item); | 67 | + void addAll(Iterable<E> iterable) { |
68 | + value.addAll(iterable); | ||
69 | refresh(); | 69 | refresh(); |
70 | } | 70 | } |
71 | 71 | ||
72 | @override | 72 | @override |
73 | - void removeWhere(bool test(E element)) { | 73 | + void removeWhere(bool Function(E element) test) { |
74 | value.removeWhere(test); | 74 | value.removeWhere(test); |
75 | refresh(); | 75 | refresh(); |
76 | } | 76 | } |
77 | 77 | ||
78 | @override | 78 | @override |
79 | - void retainWhere(bool test(E element)) { | 79 | + void retainWhere(bool Function(E element) test) { |
80 | value.retainWhere(test); | 80 | value.retainWhere(test); |
81 | refresh(); | 81 | refresh(); |
82 | } | 82 | } |
@@ -117,7 +117,7 @@ class RxList<E> extends GetListenable<List<E>> | @@ -117,7 +117,7 @@ class RxList<E> extends GetListenable<List<E>> | ||
117 | } | 117 | } |
118 | 118 | ||
119 | @override | 119 | @override |
120 | - void sort([int compare(E a, E b)?]) { | 120 | + void sort([int Function(E a, E b)? compare]) { |
121 | value.sort(compare); | 121 | value.sort(compare); |
122 | refresh(); | 122 | refresh(); |
123 | } | 123 | } |
@@ -29,8 +29,8 @@ class RxMap<K, V> extends GetListenable<Map<K, V>> | @@ -29,8 +29,8 @@ class RxMap<K, V> extends GetListenable<Map<K, V>> | ||
29 | } | 29 | } |
30 | 30 | ||
31 | @override | 31 | @override |
32 | - void operator []=(K key, V val) { | ||
33 | - value[key] = val; | 32 | + void operator []=(K key, V value) { |
33 | + this.value[key] = value; | ||
34 | refresh(); | 34 | refresh(); |
35 | } | 35 | } |
36 | 36 |
@@ -12,7 +12,7 @@ class RxSet<E> extends GetListenable<Set<E>> | @@ -12,7 +12,7 @@ class RxSet<E> extends GetListenable<Set<E>> | ||
12 | return this; | 12 | return this; |
13 | } | 13 | } |
14 | 14 | ||
15 | - void update(void fn(Iterable<E>? value)) { | 15 | + void update(void Function(Iterable<E>? value) fn) { |
16 | fn(value); | 16 | fn(value); |
17 | refresh(); | 17 | refresh(); |
18 | } | 18 | } |
@@ -34,8 +34,8 @@ class RxSet<E> extends GetListenable<Set<E>> | @@ -34,8 +34,8 @@ class RxSet<E> extends GetListenable<Set<E>> | ||
34 | } | 34 | } |
35 | 35 | ||
36 | @override | 36 | @override |
37 | - bool add(E val) { | ||
38 | - final hasAdded = value.add(val); | 37 | + bool add(E value) { |
38 | + final hasAdded = this.value.add(value); | ||
39 | if (hasAdded) { | 39 | if (hasAdded) { |
40 | refresh(); | 40 | refresh(); |
41 | } | 41 | } |
@@ -54,13 +54,13 @@ class RxSet<E> extends GetListenable<Set<E>> | @@ -54,13 +54,13 @@ class RxSet<E> extends GetListenable<Set<E>> | ||
54 | int get length => value.length; | 54 | int get length => value.length; |
55 | 55 | ||
56 | @override | 56 | @override |
57 | - E? lookup(Object? object) { | ||
58 | - return value.lookup(object); | 57 | + E? lookup(Object? element) { |
58 | + return value.lookup(element); | ||
59 | } | 59 | } |
60 | 60 | ||
61 | @override | 61 | @override |
62 | - bool remove(Object? item) { | ||
63 | - var hasRemoved = value.remove(item); | 62 | + bool remove(Object? value) { |
63 | + var hasRemoved = this.value.remove(value); | ||
64 | if (hasRemoved) { | 64 | if (hasRemoved) { |
65 | refresh(); | 65 | refresh(); |
66 | } | 66 | } |
@@ -73,8 +73,8 @@ class RxSet<E> extends GetListenable<Set<E>> | @@ -73,8 +73,8 @@ class RxSet<E> extends GetListenable<Set<E>> | ||
73 | } | 73 | } |
74 | 74 | ||
75 | @override | 75 | @override |
76 | - void addAll(Iterable<E> item) { | ||
77 | - value.addAll(item); | 76 | + void addAll(Iterable<E> elements) { |
77 | + value.addAll(elements); | ||
78 | refresh(); | 78 | refresh(); |
79 | } | 79 | } |
80 | 80 | ||
@@ -97,8 +97,8 @@ class RxSet<E> extends GetListenable<Set<E>> | @@ -97,8 +97,8 @@ class RxSet<E> extends GetListenable<Set<E>> | ||
97 | } | 97 | } |
98 | 98 | ||
99 | @override | 99 | @override |
100 | - void retainWhere(bool Function(E) E) { | ||
101 | - value.retainWhere(E); | 100 | + void retainWhere(bool Function(E) test) { |
101 | + value.retainWhere(test); | ||
102 | refresh(); | 102 | refresh(); |
103 | } | 103 | } |
104 | } | 104 | } |
@@ -101,11 +101,10 @@ Worker everAll( | @@ -101,11 +101,10 @@ Worker everAll( | ||
101 | evers.add(sub); | 101 | evers.add(sub); |
102 | } | 102 | } |
103 | 103 | ||
104 | - Future<void> cancel() { | 104 | + Future<void> cancel() async { |
105 | for (var i in evers) { | 105 | for (var i in evers) { |
106 | i.cancel(); | 106 | i.cancel(); |
107 | } | 107 | } |
108 | - return Future.value(() {}); | ||
109 | } | 108 | } |
110 | 109 | ||
111 | return Worker(cancel, '[everAll]'); | 110 | return Worker(cancel, '[everAll]'); |
@@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; | @@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; | ||
2 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
3 | 3 | ||
4 | import '../../../get_core/get_core.dart'; | 4 | import '../../../get_core/get_core.dart'; |
5 | -import '../../../get_instance/src/get_instance.dart'; | 5 | +import '../../../get_instance/src/extension_instance.dart'; |
6 | import '../../../get_instance/src/lifecycle.dart'; | 6 | import '../../../get_instance/src/lifecycle.dart'; |
7 | import '../simple/list_notifier.dart'; | 7 | import '../simple/list_notifier.dart'; |
8 | 8 | ||
@@ -61,17 +61,17 @@ class GetXState<T extends GetLifeCycleMixin> extends State<GetX<T>> { | @@ -61,17 +61,17 @@ class GetXState<T extends GetLifeCycleMixin> extends State<GetX<T>> { | ||
61 | 61 | ||
62 | @override | 62 | @override |
63 | void initState() { | 63 | void initState() { |
64 | - // var isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | ||
65 | - final isRegistered = GetInstance().isRegistered<T>(tag: widget.tag); | 64 | + // var isPrepared = Get.isPrepared<T>(tag: widget.tag); |
65 | + final isRegistered = Get.isRegistered<T>(tag: widget.tag); | ||
66 | 66 | ||
67 | if (widget.global) { | 67 | if (widget.global) { |
68 | if (isRegistered) { | 68 | if (isRegistered) { |
69 | - _isCreator = GetInstance().isPrepared<T>(tag: widget.tag); | ||
70 | - controller = GetInstance().find<T>(tag: widget.tag); | 69 | + _isCreator = Get.isPrepared<T>(tag: widget.tag); |
70 | + controller = Get.find<T>(tag: widget.tag); | ||
71 | } else { | 71 | } else { |
72 | controller = widget.init; | 72 | controller = widget.init; |
73 | _isCreator = true; | 73 | _isCreator = true; |
74 | - GetInstance().put<T>(controller!, tag: widget.tag); | 74 | + Get.put<T>(controller!, tag: widget.tag); |
75 | } | 75 | } |
76 | } else { | 76 | } else { |
77 | controller = widget.init; | 77 | controller = widget.init; |
@@ -104,8 +104,8 @@ class GetXState<T extends GetLifeCycleMixin> extends State<GetX<T>> { | @@ -104,8 +104,8 @@ class GetXState<T extends GetLifeCycleMixin> extends State<GetX<T>> { | ||
104 | void dispose() { | 104 | void dispose() { |
105 | if (widget.dispose != null) widget.dispose!(this); | 105 | if (widget.dispose != null) widget.dispose!(this); |
106 | if (_isCreator! || widget.assignId) { | 106 | if (_isCreator! || widget.assignId) { |
107 | - if (widget.autoRemove && GetInstance().isRegistered<T>(tag: widget.tag)) { | ||
108 | - GetInstance().delete<T>(tag: widget.tag); | 107 | + if (widget.autoRemove && Get.isRegistered<T>(tag: widget.tag)) { |
108 | + Get.delete<T>(tag: widget.tag); | ||
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 |
@@ -82,7 +82,7 @@ mixin StateMixin<T> on ListNotifier { | @@ -82,7 +82,7 @@ mixin StateMixin<T> on ListNotifier { | ||
82 | // } | 82 | // } |
83 | } | 83 | } |
84 | 84 | ||
85 | - void futurize(Future<T> Function() body(), | 85 | + void futurize(Future<T> Function() Function() body, |
86 | {String? errorMessage, bool useEmpty = true}) { | 86 | {String? errorMessage, bool useEmpty = true}) { |
87 | final compute = body(); | 87 | final compute = body(); |
88 | compute().then((newValue) { | 88 | compute().then((newValue) { |
@@ -203,9 +203,9 @@ class Value<T> extends ListNotifier | @@ -203,9 +203,9 @@ class Value<T> extends ListNotifier | ||
203 | return value; | 203 | return value; |
204 | } | 204 | } |
205 | 205 | ||
206 | - void update(void fn(T? value)) { | ||
207 | - fn(value); | ||
208 | - refresh(); | 206 | + void update(T Function(T? value) fn) { |
207 | + value = fn(value); | ||
208 | + // refresh(); | ||
209 | } | 209 | } |
210 | 210 | ||
211 | @override | 211 | @override |
@@ -236,9 +236,8 @@ extension StateExt<T> on StateMixin<T> { | @@ -236,9 +236,8 @@ extension StateExt<T> on StateMixin<T> { | ||
236 | ? onError(status.errorMessage) | 236 | ? onError(status.errorMessage) |
237 | : Center(child: Text('A error occurred: ${status.errorMessage}')); | 237 | : Center(child: Text('A error occurred: ${status.errorMessage}')); |
238 | } else if (status.isEmpty) { | 238 | } else if (status.isEmpty) { |
239 | - return onEmpty != null | ||
240 | - ? onEmpty | ||
241 | - : SizedBox.shrink(); // Also can be widget(null); but is risky | 239 | + return onEmpty ?? |
240 | + SizedBox.shrink(); // Also can be widget(null); but is risky | ||
242 | } else if (status.isSuccess) { | 241 | } else if (status.isSuccess) { |
243 | return widget(value); | 242 | return widget(value); |
244 | } else if (status.isCustom) { | 243 | } else if (status.isCustom) { |
@@ -119,16 +119,16 @@ class ResponsiveScreen { | @@ -119,16 +119,16 @@ class ResponsiveScreen { | ||
119 | double get width => context.width; | 119 | double get width => context.width; |
120 | 120 | ||
121 | /// Is [screenType] [ScreenType.Desktop] | 121 | /// Is [screenType] [ScreenType.Desktop] |
122 | - bool get isDesktop => (screenType == ScreenType.Desktop); | 122 | + bool get isDesktop => (screenType == ScreenType.desktop); |
123 | 123 | ||
124 | /// Is [screenType] [ScreenType.Tablet] | 124 | /// Is [screenType] [ScreenType.Tablet] |
125 | - bool get isTablet => (screenType == ScreenType.Tablet); | 125 | + bool get isTablet => (screenType == ScreenType.tablet); |
126 | 126 | ||
127 | /// Is [screenType] [ScreenType.Phone] | 127 | /// Is [screenType] [ScreenType.Phone] |
128 | - bool get isPhone => (screenType == ScreenType.Phone); | 128 | + bool get isPhone => (screenType == ScreenType.phone); |
129 | 129 | ||
130 | /// Is [screenType] [ScreenType.Watch] | 130 | /// Is [screenType] [ScreenType.Watch] |
131 | - bool get isWatch => (screenType == ScreenType.Watch); | 131 | + bool get isWatch => (screenType == ScreenType.watch); |
132 | 132 | ||
133 | double get _getdeviceWidth { | 133 | double get _getdeviceWidth { |
134 | if (_isPaltformDesktop) { | 134 | if (_isPaltformDesktop) { |
@@ -139,10 +139,10 @@ class ResponsiveScreen { | @@ -139,10 +139,10 @@ class ResponsiveScreen { | ||
139 | 139 | ||
140 | ScreenType get screenType { | 140 | ScreenType get screenType { |
141 | final deviceWidth = _getdeviceWidth; | 141 | final deviceWidth = _getdeviceWidth; |
142 | - if (deviceWidth >= settings.desktopChangePoint) return ScreenType.Desktop; | ||
143 | - if (deviceWidth >= settings.tabletChangePoint) return ScreenType.Tablet; | ||
144 | - if (deviceWidth < settings.watchChangePoint) return ScreenType.Watch; | ||
145 | - return ScreenType.Phone; | 142 | + if (deviceWidth >= settings.desktopChangePoint) return ScreenType.desktop; |
143 | + if (deviceWidth >= settings.tabletChangePoint) return ScreenType.tablet; | ||
144 | + if (deviceWidth < settings.watchChangePoint) return ScreenType.watch; | ||
145 | + return ScreenType.phone; | ||
146 | } | 146 | } |
147 | 147 | ||
148 | /// Return widget according to screen type | 148 | /// Return widget according to screen type |
@@ -165,8 +165,8 @@ class ResponsiveScreen { | @@ -165,8 +165,8 @@ class ResponsiveScreen { | ||
165 | } | 165 | } |
166 | 166 | ||
167 | enum ScreenType { | 167 | enum ScreenType { |
168 | - Watch, | ||
169 | - Phone, | ||
170 | - Tablet, | ||
171 | - Desktop, | 168 | + watch, |
169 | + phone, | ||
170 | + tablet, | ||
171 | + desktop, | ||
172 | } | 172 | } |
1 | +// ignore_for_file: overridden_fields | ||
2 | + | ||
1 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
2 | 4 | ||
3 | import '../../../instance_manager.dart'; | 5 | import '../../../instance_manager.dart'; |
@@ -70,6 +72,7 @@ class GetBuilder<T extends GetxController> extends StatelessWidget { | @@ -70,6 +72,7 @@ class GetBuilder<T extends GetxController> extends StatelessWidget { | ||
70 | tag: tag, | 72 | tag: tag, |
71 | dispose: dispose, | 73 | dispose: dispose, |
72 | id: id, | 74 | id: id, |
75 | + lazy: false, | ||
73 | didChangeDependencies: didChangeDependencies, | 76 | didChangeDependencies: didChangeDependencies, |
74 | didUpdateWidget: didUpdateWidget, | 77 | didUpdateWidget: didUpdateWidget, |
75 | child: Builder(builder: (context) { | 78 | child: Builder(builder: (context) { |
@@ -114,11 +117,12 @@ abstract class Bind<T> extends StatelessWidget { | @@ -114,11 +117,12 @@ abstract class Bind<T> extends StatelessWidget { | ||
114 | 117 | ||
115 | final Widget? child; | 118 | final Widget? child; |
116 | 119 | ||
117 | - static Bind put<S>(S dependency, | ||
118 | - {String? tag, | ||
119 | - bool permanent = false, | ||
120 | - InstanceBuilderCallback<S>? builder}) { | ||
121 | - Get.put<S>(dependency, tag: tag, permanent: permanent, builder: builder); | 120 | + static Bind put<S>( |
121 | + S dependency, { | ||
122 | + String? tag, | ||
123 | + bool permanent = false, | ||
124 | + }) { | ||
125 | + Get.put<S>(dependency, tag: tag, permanent: permanent); | ||
122 | return _FactoryBind<S>( | 126 | return _FactoryBind<S>( |
123 | autoRemove: permanent, | 127 | autoRemove: permanent, |
124 | assignId: true, | 128 | assignId: true, |
@@ -130,10 +134,18 @@ abstract class Bind<T> extends StatelessWidget { | @@ -130,10 +134,18 @@ abstract class Bind<T> extends StatelessWidget { | ||
130 | InstanceBuilderCallback<S> builder, { | 134 | InstanceBuilderCallback<S> builder, { |
131 | String? tag, | 135 | String? tag, |
132 | bool fenix = true, | 136 | bool fenix = true, |
137 | + // VoidCallback? onInit, | ||
138 | + VoidCallback? onClose, | ||
133 | }) { | 139 | }) { |
134 | Get.lazyPut<S>(builder, tag: tag, fenix: fenix); | 140 | Get.lazyPut<S>(builder, tag: tag, fenix: fenix); |
135 | return _FactoryBind<S>( | 141 | return _FactoryBind<S>( |
136 | tag: tag, | 142 | tag: tag, |
143 | + // initState: (_) { | ||
144 | + // onInit?.call(); | ||
145 | + // }, | ||
146 | + dispose: (_) { | ||
147 | + onClose?.call(); | ||
148 | + }, | ||
137 | ); | 149 | ); |
138 | } | 150 | } |
139 | 151 | ||
@@ -145,39 +157,36 @@ abstract class Bind<T> extends StatelessWidget { | @@ -145,39 +157,36 @@ abstract class Bind<T> extends StatelessWidget { | ||
145 | ); | 157 | ); |
146 | } | 158 | } |
147 | 159 | ||
148 | - static S find<S>({String? tag}) => GetInstance().find<S>(tag: tag); | 160 | + static S find<S>({String? tag}) => Get.find<S>(tag: tag); |
149 | 161 | ||
150 | static Future<bool> delete<S>({String? tag, bool force = false}) async => | 162 | static Future<bool> delete<S>({String? tag, bool force = false}) async => |
151 | - GetInstance().delete<S>(tag: tag, force: force); | 163 | + Get.delete<S>(tag: tag, force: force); |
152 | 164 | ||
153 | static Future<void> deleteAll({bool force = false}) async => | 165 | static Future<void> deleteAll({bool force = false}) async => |
154 | - GetInstance().deleteAll(force: force); | 166 | + Get.deleteAll(force: force); |
155 | 167 | ||
156 | - static void reloadAll({bool force = false}) => | ||
157 | - GetInstance().reloadAll(force: force); | 168 | + static void reloadAll({bool force = false}) => Get.reloadAll(force: force); |
158 | 169 | ||
159 | static void reload<S>({String? tag, String? key, bool force = false}) => | 170 | static void reload<S>({String? tag, String? key, bool force = false}) => |
160 | - GetInstance().reload<S>(tag: tag, key: key, force: force); | 171 | + Get.reload<S>(tag: tag, key: key, force: force); |
161 | 172 | ||
162 | - static bool isRegistered<S>({String? tag}) => | ||
163 | - GetInstance().isRegistered<S>(tag: tag); | 173 | + static bool isRegistered<S>({String? tag}) => Get.isRegistered<S>(tag: tag); |
164 | 174 | ||
165 | - static bool isPrepared<S>({String? tag}) => | ||
166 | - GetInstance().isPrepared<S>(tag: tag); | 175 | + static bool isPrepared<S>({String? tag}) => Get.isPrepared<S>(tag: tag); |
167 | 176 | ||
168 | static void replace<P>(P child, {String? tag}) { | 177 | static void replace<P>(P child, {String? tag}) { |
169 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 178 | + final info = Get.getInstanceInfo<P>(tag: tag); |
170 | final permanent = (info.isPermanent ?? false); | 179 | final permanent = (info.isPermanent ?? false); |
171 | delete<P>(tag: tag, force: permanent); | 180 | delete<P>(tag: tag, force: permanent); |
172 | - GetInstance().put(child, tag: tag, permanent: permanent); | 181 | + Get.put(child, tag: tag, permanent: permanent); |
173 | } | 182 | } |
174 | 183 | ||
175 | static void lazyReplace<P>(InstanceBuilderCallback<P> builder, | 184 | static void lazyReplace<P>(InstanceBuilderCallback<P> builder, |
176 | {String? tag, bool? fenix}) { | 185 | {String? tag, bool? fenix}) { |
177 | - final info = GetInstance().getInstanceInfo<P>(tag: tag); | 186 | + final info = Get.getInstanceInfo<P>(tag: tag); |
178 | final permanent = (info.isPermanent ?? false); | 187 | final permanent = (info.isPermanent ?? false); |
179 | delete<P>(tag: tag, force: permanent); | 188 | delete<P>(tag: tag, force: permanent); |
180 | - GetInstance().lazyPut(builder, tag: tag, fenix: fenix ?? permanent); | 189 | + Get.lazyPut(builder, tag: tag, fenix: fenix ?? permanent); |
181 | } | 190 | } |
182 | 191 | ||
183 | factory Bind.builder({ | 192 | factory Bind.builder({ |
@@ -232,9 +241,9 @@ abstract class Bind<T> extends StatelessWidget { | @@ -232,9 +241,9 @@ abstract class Bind<T> extends StatelessWidget { | ||
232 | // } | 241 | // } |
233 | } | 242 | } |
234 | 243 | ||
235 | - var widget = inheritedElement.controller; | 244 | + final controller = inheritedElement.controller; |
236 | 245 | ||
237 | - return widget; | 246 | + return controller; |
238 | } | 247 | } |
239 | 248 | ||
240 | @factory | 249 | @factory |
@@ -335,7 +344,7 @@ class Binds extends StatelessWidget { | @@ -335,7 +344,7 @@ class Binds extends StatelessWidget { | ||
335 | 344 | ||
336 | @override | 345 | @override |
337 | Widget build(BuildContext context) => | 346 | Widget build(BuildContext context) => |
338 | - binds.reversed.fold(child, (acc, e) => e._copyWithChild(acc)); | 347 | + binds.reversed.fold(child, (widget, e) => e._copyWithChild(widget)); |
339 | } | 348 | } |
340 | 349 | ||
341 | class Binder<T> extends InheritedWidget { | 350 | class Binder<T> extends InheritedWidget { |
@@ -350,6 +359,7 @@ class Binder<T> extends InheritedWidget { | @@ -350,6 +359,7 @@ class Binder<T> extends InheritedWidget { | ||
350 | this.global = true, | 359 | this.global = true, |
351 | this.autoRemove = true, | 360 | this.autoRemove = true, |
352 | this.assignId = false, | 361 | this.assignId = false, |
362 | + this.lazy = true, | ||
353 | this.initState, | 363 | this.initState, |
354 | this.filter, | 364 | this.filter, |
355 | this.tag, | 365 | this.tag, |
@@ -363,6 +373,7 @@ class Binder<T> extends InheritedWidget { | @@ -363,6 +373,7 @@ class Binder<T> extends InheritedWidget { | ||
363 | final bool global; | 373 | final bool global; |
364 | final Object? id; | 374 | final Object? id; |
365 | final String? tag; | 375 | final String? tag; |
376 | + final bool lazy; | ||
366 | final bool autoRemove; | 377 | final bool autoRemove; |
367 | final bool assignId; | 378 | final bool assignId; |
368 | final Object Function(T value)? filter; | 379 | final Object Function(T value)? filter; |
@@ -419,21 +430,25 @@ class BindElement<T> extends InheritedElement { | @@ -419,21 +430,25 @@ class BindElement<T> extends InheritedElement { | ||
419 | void initState() { | 430 | void initState() { |
420 | widget.initState?.call(this); | 431 | widget.initState?.call(this); |
421 | 432 | ||
422 | - var isRegistered = GetInstance().isRegistered<T>(tag: widget.tag); | 433 | + var isRegistered = Get.isRegistered<T>(tag: widget.tag); |
423 | 434 | ||
424 | if (widget.global) { | 435 | if (widget.global) { |
425 | if (isRegistered) { | 436 | if (isRegistered) { |
426 | - if (GetInstance().isPrepared<T>(tag: widget.tag)) { | 437 | + if (Get.isPrepared<T>(tag: widget.tag)) { |
427 | _isCreator = true; | 438 | _isCreator = true; |
428 | } else { | 439 | } else { |
429 | _isCreator = false; | 440 | _isCreator = false; |
430 | } | 441 | } |
431 | 442 | ||
432 | - _controllerBuilder = () => GetInstance().find<T>(tag: widget.tag); | 443 | + _controllerBuilder = () => Get.find<T>(tag: widget.tag); |
433 | } else { | 444 | } else { |
434 | _controllerBuilder = widget.init; | 445 | _controllerBuilder = widget.init; |
435 | _isCreator = true; | 446 | _isCreator = true; |
436 | - GetInstance().lazyPut<T>(_controllerBuilder!, tag: widget.tag); | 447 | + if (widget.lazy) { |
448 | + Get.lazyPut<T>(_controllerBuilder!, tag: widget.tag); | ||
449 | + } else { | ||
450 | + Get.put<T>(_controllerBuilder!(), tag: widget.tag); | ||
451 | + } | ||
437 | } | 452 | } |
438 | } else { | 453 | } else { |
439 | _controllerBuilder = widget.init; | 454 | _controllerBuilder = widget.init; |
@@ -481,8 +496,8 @@ class BindElement<T> extends InheritedElement { | @@ -481,8 +496,8 @@ class BindElement<T> extends InheritedElement { | ||
481 | void dispose() { | 496 | void dispose() { |
482 | widget.dispose?.call(this); | 497 | widget.dispose?.call(this); |
483 | if (_isCreator! || widget.assignId) { | 498 | if (_isCreator! || widget.assignId) { |
484 | - if (widget.autoRemove && GetInstance().isRegistered<T>(tag: widget.tag)) { | ||
485 | - GetInstance().delete<T>(tag: widget.tag); | 499 | + if (widget.autoRemove && Get.isRegistered<T>(tag: widget.tag)) { |
500 | + Get.delete<T>(tag: widget.tag); | ||
486 | } | 501 | } |
487 | } | 502 | } |
488 | 503 |
@@ -35,7 +35,7 @@ abstract class GetView<T> extends StatelessWidget { | @@ -35,7 +35,7 @@ abstract class GetView<T> extends StatelessWidget { | ||
35 | 35 | ||
36 | final String? tag = null; | 36 | final String? tag = null; |
37 | 37 | ||
38 | - T get controller => GetInstance().find<T>(tag: tag)!; | 38 | + T get controller => Get.find<T>(tag: tag)!; |
39 | 39 | ||
40 | @override | 40 | @override |
41 | Widget build(BuildContext context); | 41 | Widget build(BuildContext context); |
@@ -72,7 +72,7 @@ class _GetCache<S extends GetLifeCycleMixin> extends WidgetCache<GetWidget<S>> { | @@ -72,7 +72,7 @@ class _GetCache<S extends GetLifeCycleMixin> extends WidgetCache<GetWidget<S>> { | ||
72 | InstanceInfo? info; | 72 | InstanceInfo? info; |
73 | @override | 73 | @override |
74 | void onInit() { | 74 | void onInit() { |
75 | - info = GetInstance().getInstanceInfo<S>(tag: widget!.tag); | 75 | + info = Get.getInstanceInfo<S>(tag: widget!.tag); |
76 | 76 | ||
77 | _isCreator = info!.isPrepared && info!.isCreate; | 77 | _isCreator = info!.isPrepared && info!.isCreate; |
78 | 78 |
@@ -31,11 +31,6 @@ class GetWidgetCacheElement extends ComponentElement { | @@ -31,11 +31,6 @@ class GetWidgetCacheElement extends ComponentElement { | ||
31 | final WidgetCache<GetWidgetCache> cache; | 31 | final WidgetCache<GetWidgetCache> cache; |
32 | 32 | ||
33 | @override | 33 | @override |
34 | - void performRebuild() { | ||
35 | - super.performRebuild(); | ||
36 | - } | ||
37 | - | ||
38 | - @override | ||
39 | void activate() { | 34 | void activate() { |
40 | super.activate(); | 35 | super.activate(); |
41 | markNeedsBuild(); | 36 | markNeedsBuild(); |
@@ -15,5 +15,6 @@ extension GetDurationUtils on Duration { | @@ -15,5 +15,6 @@ extension GetDurationUtils on Duration { | ||
15 | /// await 0.7.seconds.delay(() { | 15 | /// await 0.7.seconds.delay(() { |
16 | /// } | 16 | /// } |
17 | ///``` | 17 | ///``` |
18 | - Future delay([FutureOr callback()?]) async => Future.delayed(this, callback); | 18 | + Future delay([FutureOr Function()? callback]) async => |
19 | + Future.delayed(this, callback); | ||
19 | } | 20 | } |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | + | ||
2 | import '../../../get_core/src/get_interface.dart'; | 3 | import '../../../get_core/src/get_interface.dart'; |
3 | 4 | ||
4 | extension LoopEventsExt on GetInterface { | 5 | extension LoopEventsExt on GetInterface { |
5 | - Future<T> toEnd<T>(FutureOr<T> computation()) async { | 6 | + Future<T> toEnd<T>(FutureOr<T> Function() computation) async { |
6 | await Future.delayed(Duration.zero); | 7 | await Future.delayed(Duration.zero); |
7 | final val = computation(); | 8 | final val = computation(); |
8 | return val; | 9 | return val; |
9 | } | 10 | } |
10 | 11 | ||
11 | - FutureOr<T> asap<T>(T computation(), {bool Function()? condition}) async { | 12 | + FutureOr<T> asap<T>(T Function() computation, |
13 | + {bool Function()? condition}) async { | ||
12 | T val; | 14 | T val; |
13 | if (condition == null || !condition()) { | 15 | if (condition == null || !condition()) { |
14 | await Future.delayed(Duration.zero); | 16 | await Future.delayed(Duration.zero); |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | + | ||
2 | import '../get_utils/get_utils.dart'; | 3 | import '../get_utils/get_utils.dart'; |
3 | 4 | ||
4 | extension GetNumUtils on num { | 5 | extension GetNumUtils on num { |
@@ -23,7 +24,7 @@ extension GetNumUtils on num { | @@ -23,7 +24,7 @@ extension GetNumUtils on num { | ||
23 | /// print('currently running callback 1.2sec'); | 24 | /// print('currently running callback 1.2sec'); |
24 | /// } | 25 | /// } |
25 | ///``` | 26 | ///``` |
26 | - Future delay([FutureOr callback()?]) async => Future.delayed( | 27 | + Future delay([FutureOr Function()? callback]) async => Future.delayed( |
27 | Duration(milliseconds: (this * 1000).round()), | 28 | Duration(milliseconds: (this * 1000).round()), |
28 | callback, | 29 | callback, |
29 | ); | 30 | ); |
@@ -68,7 +68,7 @@ class GetUtils { | @@ -68,7 +68,7 @@ class GetUtils { | ||
68 | /// "value":value==null?null:value; someVar.nil will force the null type | 68 | /// "value":value==null?null:value; someVar.nil will force the null type |
69 | /// if the var is null or undefined. | 69 | /// if the var is null or undefined. |
70 | /// `nil` taken from ObjC just to have a shorter sintax. | 70 | /// `nil` taken from ObjC just to have a shorter sintax. |
71 | - static dynamic nil(dynamic s) => s == null ? null : s; | 71 | + static dynamic nil(dynamic s) => s; |
72 | 72 | ||
73 | /// Checks if data is null or blank (empty or only contains whitespace). | 73 | /// Checks if data is null or blank (empty or only contains whitespace). |
74 | static bool? isNullOrBlank(dynamic value) { | 74 | static bool? isNullOrBlank(dynamic value) { |
@@ -331,13 +331,6 @@ class GetUtils { | @@ -331,13 +331,6 @@ class GetUtils { | ||
331 | return length >= maxLength; | 331 | return length >= maxLength; |
332 | } | 332 | } |
333 | 333 | ||
334 | - /// Checks if length of data is LOWER than maxLength. | ||
335 | - /// | ||
336 | - /// This method is deprecated, use [isLengthLessThan] instead | ||
337 | - @deprecated | ||
338 | - static bool isLengthLowerThan(dynamic value, int maxLength) => | ||
339 | - isLengthLessThan(value, maxLength); | ||
340 | - | ||
341 | /// Checks if length of data is LESS than maxLength. | 334 | /// Checks if length of data is LESS than maxLength. |
342 | static bool isLengthLessThan(dynamic value, int maxLength) { | 335 | static bool isLengthLessThan(dynamic value, int maxLength) { |
343 | final length = _obtainDynamicLength(value); | 336 | final length = _obtainDynamicLength(value); |
@@ -348,13 +341,6 @@ class GetUtils { | @@ -348,13 +341,6 @@ class GetUtils { | ||
348 | return length < maxLength; | 341 | return length < maxLength; |
349 | } | 342 | } |
350 | 343 | ||
351 | - /// Checks if length of data is LOWER OR EQUAL to maxLength. | ||
352 | - /// | ||
353 | - /// This method is deprecated, use [isLengthLessOrEqual] instead | ||
354 | - @deprecated | ||
355 | - static bool isLengthLowerOrEqual(dynamic value, int maxLength) => | ||
356 | - isLengthLessOrEqual(value, maxLength); | ||
357 | - | ||
358 | /// Checks if length of data is LESS OR EQUAL to maxLength. | 344 | /// Checks if length of data is LESS OR EQUAL to maxLength. |
359 | static bool isLengthLessOrEqual(dynamic value, int maxLength) { | 345 | static bool isLengthLessOrEqual(dynamic value, int maxLength) { |
360 | final length = _obtainDynamicLength(value); | 346 | final length = _obtainDynamicLength(value); |
1 | name: get | 1 | name: get |
2 | description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX. | 2 | description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX. |
3 | -version: 5.0.0-beta.30 | 3 | +version: 5.0.0-beta.45 |
4 | homepage: https://github.com/jonataslaw/getx | 4 | homepage: https://github.com/jonataslaw/getx |
5 | 5 | ||
6 | environment: | 6 | environment: |
7 | - sdk: '>=2.13.0 <3.0.0' | 7 | + sdk: '>=2.16.0 <3.0.0' |
8 | 8 | ||
9 | dependencies: | 9 | dependencies: |
10 | flutter: | 10 | flutter: |
@@ -15,6 +15,7 @@ dependencies: | @@ -15,6 +15,7 @@ dependencies: | ||
15 | dev_dependencies: | 15 | dev_dependencies: |
16 | flutter_test: | 16 | flutter_test: |
17 | sdk: flutter | 17 | sdk: flutter |
18 | + lints: ^1.0.1 | ||
18 | 19 | ||
19 | 20 | ||
20 | # For information on the generic Dart part of this file, see the | 21 | # For information on the generic Dart part of this file, see the |
@@ -117,7 +117,7 @@ void main() { | @@ -117,7 +117,7 @@ void main() { | ||
117 | expect(ct1.count, 1); | 117 | expect(ct1.count, 1); |
118 | ct1 = Get.find<Controller>(); | 118 | ct1 = Get.find<Controller>(); |
119 | expect(ct1.count, 1); | 119 | expect(ct1.count, 1); |
120 | - GetInstance().reload<Controller>(); | 120 | + Get.reload<Controller>(); |
121 | ct1 = Get.find<Controller>(); | 121 | ct1 = Get.find<Controller>(); |
122 | expect(ct1.count, 0); | 122 | expect(ct1.count, 0); |
123 | Get.reset(); | 123 | Get.reset(); |
@@ -165,7 +165,7 @@ void main() { | @@ -165,7 +165,7 @@ void main() { | ||
165 | 165 | ||
166 | test('Get.delete test with disposable controller', () async { | 166 | test('Get.delete test with disposable controller', () async { |
167 | // Get.put(DisposableController()); | 167 | // Get.put(DisposableController()); |
168 | - expect(await Get.delete<DisposableController>(), true); | 168 | + expect(Get.delete<DisposableController>(), true); |
169 | expect(() => Get.find<DisposableController>(), | 169 | expect(() => Get.find<DisposableController>(), |
170 | throwsA(m.TypeMatcher<String>())); | 170 | throwsA(m.TypeMatcher<String>())); |
171 | }); | 171 | }); |
@@ -151,7 +151,7 @@ void main() { | @@ -151,7 +151,7 @@ void main() { | ||
151 | 151 | ||
152 | test('Rx String with non null values', () async { | 152 | test('Rx String with non null values', () async { |
153 | final reactiveString = Rx<String>("abc"); | 153 | final reactiveString = Rx<String>("abc"); |
154 | - var currentString; | 154 | + String? currentString; |
155 | reactiveString.listen((newString) { | 155 | reactiveString.listen((newString) { |
156 | currentString = newString; | 156 | currentString = newString; |
157 | }); | 157 | }); |
@@ -167,7 +167,7 @@ void main() { | @@ -167,7 +167,7 @@ void main() { | ||
167 | 167 | ||
168 | test('Rx String with null values', () async { | 168 | test('Rx String with null values', () async { |
169 | var reactiveString = Rx<String?>(null); | 169 | var reactiveString = Rx<String?>(null); |
170 | - var currentString; | 170 | + String? currentString; |
171 | 171 | ||
172 | reactiveString.listen((newString) { | 172 | reactiveString.listen((newString) { |
173 | currentString = newString; | 173 | currentString = newString; |
@@ -593,11 +593,11 @@ void main() { | @@ -593,11 +593,11 @@ void main() { | ||
593 | final currencies = [ | 593 | final currencies = [ |
594 | 'R\$50.58', | 594 | 'R\$50.58', |
595 | '\$82.48', | 595 | '\$82.48', |
596 | - '\₩54.24', | ||
597 | - '\¥81.04', | ||
598 | - '\€4.06', | ||
599 | - '\₹37.40', | ||
600 | - '\₽18.12', | 596 | + '₩54.24', |
597 | + '¥81.04', | ||
598 | + '€4.06', | ||
599 | + '₹37.40', | ||
600 | + '₽18.12', | ||
601 | 'fr95.15', | 601 | 'fr95.15', |
602 | 'R81.04', | 602 | 'R81.04', |
603 | '9.35USD', | 603 | '9.35USD', |
@@ -10,10 +10,8 @@ class EmptyClass {} | @@ -10,10 +10,8 @@ class EmptyClass {} | ||
10 | void main() { | 10 | void main() { |
11 | dynamic _id(dynamic e) => e; | 11 | dynamic _id(dynamic e) => e; |
12 | 12 | ||
13 | - Null _test; | ||
14 | - | ||
15 | test('null isNullOrBlank should be true for null', () { | 13 | test('null isNullOrBlank should be true for null', () { |
16 | - expect(GetUtils.isNullOrBlank(_test), true); | 14 | + expect(GetUtils.isNullOrBlank(null), true); |
17 | }); | 15 | }); |
18 | 16 | ||
19 | test('isNullOrBlank should be false for unsupported types', () { | 17 | test('isNullOrBlank should be false for unsupported types', () { |
-
Please register or login to post a comment