fix(lint/analyser): Added analyser + effective dart
* Reformated all sources under lib * Fixed almost all (now) detected lint and type issues * Added public api type annotations * Broke RxSet api (appeared to be a copy from RxList with wrong methods, this needs to be rewrited) * Broke anyone that relied on **wrong** type annotations that were omitted from this package * Maybe broke controller close overrides (DisposableInterface from rx core seems to have been always returned a future close method)
Showing
67 changed files
with
1088 additions
and
776 deletions
analysis_options.yaml
0 → 100644
| 1 | +include: package:effective_dart/analysis_options.1.2.0.yaml | ||
| 2 | +analyzer: | ||
| 3 | + strong-mode: | ||
| 4 | + implicit-casts: false | ||
| 5 | +linter: | ||
| 6 | + rules: | ||
| 7 | + await_only_futures: true | ||
| 8 | + # This one is desirable, but that's a lot of work for now | ||
| 9 | + public_member_api_docs: false | ||
| 10 | + # Desirable, but would be breaking changes: | ||
| 11 | + avoid_positional_boolean_parameters: false | ||
| 12 | + constant_identifier_names: false |
| @@ -4,13 +4,15 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | @@ -4,13 +4,15 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | ||
| 4 | 4 | ||
| 5 | class HomeRepository implements IHomeRepository { | 5 | class HomeRepository implements IHomeRepository { |
| 6 | HomeRepository({this.dio}); | 6 | HomeRepository({this.dio}); |
| 7 | + | ||
| 7 | final Dio dio; | 8 | final Dio dio; |
| 8 | 9 | ||
| 9 | @override | 10 | @override |
| 10 | Future<CasesModel> getCases() async { | 11 | Future<CasesModel> getCases() async { |
| 11 | try { | 12 | try { |
| 12 | final response = await dio.get("https://api.covid19api.com/summary"); | 13 | final response = await dio.get("https://api.covid19api.com/summary"); |
| 13 | - return CasesModel.fromJson(response.data); | 14 | + |
| 15 | + return CasesModel.fromJson(response.data as Map<String, dynamic>); | ||
| 14 | } catch (e) { | 16 | } catch (e) { |
| 15 | print(e.toString()); | 17 | print(e.toString()); |
| 16 | return Future.error(e.toString()); | 18 | return Future.error(e.toString()); |
| @@ -16,17 +16,21 @@ class CasesModel { | @@ -16,17 +16,21 @@ class CasesModel { | ||
| 16 | }); | 16 | }); |
| 17 | 17 | ||
| 18 | factory CasesModel.fromRawJson(String str) => | 18 | factory CasesModel.fromRawJson(String str) => |
| 19 | - CasesModel.fromJson(json.decode(str)); | 19 | + CasesModel.fromJson(json.decode(str) as Map<String, dynamic>); |
| 20 | 20 | ||
| 21 | String toRawJson() => json.encode(toJson()); | 21 | String toRawJson() => json.encode(toJson()); |
| 22 | 22 | ||
| 23 | factory CasesModel.fromJson(Map<String, dynamic> json) => CasesModel( | 23 | factory CasesModel.fromJson(Map<String, dynamic> json) => CasesModel( |
| 24 | - global: json["Global"] == null ? null : Global.fromJson(json["Global"]), | 24 | + global: json["Global"] == null |
| 25 | + ? null | ||
| 26 | + : Global.fromJson(json["Global"] as Map<String, dynamic>), | ||
| 25 | countries: json["Countries"] == null | 27 | countries: json["Countries"] == null |
| 26 | ? null | 28 | ? null |
| 27 | : List<Country>.from( | 29 | : List<Country>.from( |
| 28 | - json["Countries"].map((x) => Country.fromJson(x))), | ||
| 29 | - date: json["Date"] == null ? null : json["Date"], | 30 | + (json["Countries"] as List<dynamic>) |
| 31 | + .map((x) => Country.fromJson(x as Map<String, dynamic>)), | ||
| 32 | + ), | ||
| 33 | + date: json["Date"] == null ? null : json["Date"] as String, | ||
| 30 | ); | 34 | ); |
| 31 | 35 | ||
| 32 | Map<String, dynamic> toJson() => { | 36 | Map<String, dynamic> toJson() => { |
| @@ -63,25 +67,30 @@ class Country { | @@ -63,25 +67,30 @@ class Country { | ||
| 63 | this.date, | 67 | this.date, |
| 64 | }); | 68 | }); |
| 65 | 69 | ||
| 66 | - factory Country.fromRawJson(String str) => Country.fromJson(json.decode(str)); | 70 | + factory Country.fromRawJson(String str) => |
| 71 | + Country.fromJson(json.decode(str) as Map<String, dynamic>); | ||
| 67 | 72 | ||
| 68 | String toRawJson() => json.encode(toJson()); | 73 | String toRawJson() => json.encode(toJson()); |
| 69 | 74 | ||
| 70 | factory Country.fromJson(Map<String, dynamic> json) => Country( | 75 | factory Country.fromJson(Map<String, dynamic> json) => Country( |
| 71 | - country: json["Country"] == null ? null : json["Country"], | ||
| 72 | - countryCode: json["CountryCode"] == null ? null : json["CountryCode"], | ||
| 73 | - slug: json["Slug"] == null ? null : json["Slug"], | 76 | + country: json["Country"] == null ? null : json["Country"] as String, |
| 77 | + countryCode: | ||
| 78 | + json["CountryCode"] == null ? null : json["CountryCode"] as String, | ||
| 79 | + slug: json["Slug"] == null ? null : json["Slug"] as String, | ||
| 74 | newConfirmed: | 80 | newConfirmed: |
| 75 | - json["NewConfirmed"] == null ? null : json["NewConfirmed"], | ||
| 76 | - totalConfirmed: | ||
| 77 | - json["TotalConfirmed"] == null ? null : json["TotalConfirmed"], | ||
| 78 | - newDeaths: json["NewDeaths"] == null ? null : json["NewDeaths"], | ||
| 79 | - totalDeaths: json["TotalDeaths"] == null ? null : json["TotalDeaths"], | 81 | + json["NewConfirmed"] == null ? null : json["NewConfirmed"] as int, |
| 82 | + totalConfirmed: json["TotalConfirmed"] == null | ||
| 83 | + ? null | ||
| 84 | + : json["TotalConfirmed"] as int, | ||
| 85 | + newDeaths: json["NewDeaths"] == null ? null : json["NewDeaths"] as int, | ||
| 86 | + totalDeaths: | ||
| 87 | + json["TotalDeaths"] == null ? null : json["TotalDeaths"] as int, | ||
| 80 | newRecovered: | 88 | newRecovered: |
| 81 | - json["NewRecovered"] == null ? null : json["NewRecovered"], | ||
| 82 | - totalRecovered: | ||
| 83 | - json["TotalRecovered"] == null ? null : json["TotalRecovered"], | ||
| 84 | - date: json["Date"] == null ? null : json["Date"], | 89 | + json["NewRecovered"] == null ? null : json["NewRecovered"] as int, |
| 90 | + totalRecovered: json["TotalRecovered"] == null | ||
| 91 | + ? null | ||
| 92 | + : json["TotalRecovered"] as int, | ||
| 93 | + date: json["Date"] == null ? null : json["Date"] as String, | ||
| 85 | ); | 94 | ); |
| 86 | 95 | ||
| 87 | Map<String, dynamic> toJson() => { | 96 | Map<String, dynamic> toJson() => { |
| @@ -115,21 +124,25 @@ class Global { | @@ -115,21 +124,25 @@ class Global { | ||
| 115 | this.totalRecovered, | 124 | this.totalRecovered, |
| 116 | }); | 125 | }); |
| 117 | 126 | ||
| 118 | - factory Global.fromRawJson(String str) => Global.fromJson(json.decode(str)); | 127 | + factory Global.fromRawJson(String str) => |
| 128 | + Global.fromJson(json.decode(str) as Map<String, dynamic>); | ||
| 119 | 129 | ||
| 120 | String toRawJson() => json.encode(toJson()); | 130 | String toRawJson() => json.encode(toJson()); |
| 121 | 131 | ||
| 122 | factory Global.fromJson(Map<String, dynamic> json) => Global( | 132 | factory Global.fromJson(Map<String, dynamic> json) => Global( |
| 123 | newConfirmed: | 133 | newConfirmed: |
| 124 | - json["NewConfirmed"] == null ? null : json["NewConfirmed"], | ||
| 125 | - totalConfirmed: | ||
| 126 | - json["TotalConfirmed"] == null ? null : json["TotalConfirmed"], | ||
| 127 | - newDeaths: json["NewDeaths"] == null ? null : json["NewDeaths"], | ||
| 128 | - totalDeaths: json["TotalDeaths"] == null ? null : json["TotalDeaths"], | 134 | + json["NewConfirmed"] == null ? null : json["NewConfirmed"] as int, |
| 135 | + totalConfirmed: json["TotalConfirmed"] == null | ||
| 136 | + ? null | ||
| 137 | + : json["TotalConfirmed"] as int, | ||
| 138 | + newDeaths: json["NewDeaths"] == null ? null : json["NewDeaths"] as int, | ||
| 139 | + totalDeaths: | ||
| 140 | + json["TotalDeaths"] == null ? null : json["TotalDeaths"] as int, | ||
| 129 | newRecovered: | 141 | newRecovered: |
| 130 | - json["NewRecovered"] == null ? null : json["NewRecovered"], | ||
| 131 | - totalRecovered: | ||
| 132 | - json["TotalRecovered"] == null ? null : json["TotalRecovered"], | 142 | + json["NewRecovered"] == null ? null : json["NewRecovered"] as int, |
| 143 | + totalRecovered: json["TotalRecovered"] == null | ||
| 144 | + ? null | ||
| 145 | + : json["TotalRecovered"] as int, | ||
| 133 | ); | 146 | ); |
| 134 | 147 | ||
| 135 | Map<String, dynamic> toJson() => { | 148 | Map<String, dynamic> toJson() => { |
| 1 | import 'dart:ui'; | 1 | import 'dart:ui'; |
| 2 | + | ||
| 2 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 3 | import 'package:get/get.dart'; | 4 | import 'package:get/get.dart'; |
| 4 | import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | 5 | import 'package:get_state/pages/home/domain/entity/cases_model.dart'; |
| @@ -6,14 +7,16 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | @@ -6,14 +7,16 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | ||
| 6 | class DetailsView extends StatelessWidget { | 7 | class DetailsView extends StatelessWidget { |
| 7 | @override | 8 | @override |
| 8 | Widget build(BuildContext context) { | 9 | Widget build(BuildContext context) { |
| 9 | - Country country = Get.arguments; | 10 | + Country country = Get.arguments as Country; |
| 10 | return Container( | 11 | return Container( |
| 11 | decoration: BoxDecoration( | 12 | decoration: BoxDecoration( |
| 12 | image: DecorationImage( | 13 | image: DecorationImage( |
| 13 | fit: BoxFit.cover, | 14 | fit: BoxFit.cover, |
| 14 | colorFilter: ColorFilter.linearToSrgbGamma(), | 15 | colorFilter: ColorFilter.linearToSrgbGamma(), |
| 15 | image: NetworkImage( | 16 | image: NetworkImage( |
| 16 | - "https://flagpedia.net/data/flags/normal/${country.countryCode.toLowerCase()}.png"))), | 17 | + "https://flagpedia.net/data/flags/normal/${country.countryCode.toLowerCase()}.png"), |
| 18 | + ), | ||
| 19 | + ), | ||
| 17 | child: BackdropFilter( | 20 | child: BackdropFilter( |
| 18 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), | 21 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), |
| 19 | child: Container( | 22 | child: Container( |
| 1 | import 'dart:ui'; | 1 | import 'dart:ui'; |
| 2 | + | ||
| 2 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 3 | import 'package:get/get.dart'; | 4 | import 'package:get/get.dart'; |
| 4 | import 'package:get_state/pages/home/presentation/controllers/home_controller.dart'; | 5 | import 'package:get_state/pages/home/presentation/controllers/home_controller.dart'; |
| @@ -13,7 +14,9 @@ class HomeView extends GetView<HomeController> { | @@ -13,7 +14,9 @@ class HomeView extends GetView<HomeController> { | ||
| 13 | fit: BoxFit.cover, | 14 | fit: BoxFit.cover, |
| 14 | colorFilter: ColorFilter.linearToSrgbGamma(), | 15 | colorFilter: ColorFilter.linearToSrgbGamma(), |
| 15 | image: NetworkImage( | 16 | image: NetworkImage( |
| 16 | - "https://images.pexels.com/photos/3902882/pexels-photo-3902882.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"))), | 17 | + "https://images.pexels.com/photos/3902882/pexels-photo-3902882.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"), |
| 18 | + ), | ||
| 19 | + ), | ||
| 17 | child: Scaffold( | 20 | child: Scaffold( |
| 18 | backgroundColor: Colors.transparent, | 21 | backgroundColor: Colors.transparent, |
| 19 | appBar: AppBar( | 22 | appBar: AppBar( |
| 1 | import 'dart:math'; | 1 | import 'dart:math'; |
| 2 | + | ||
| 2 | import 'package:flutter_test/flutter_test.dart'; | 3 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:get/get.dart'; | 4 | import 'package:get/get.dart'; |
| 4 | import 'package:get_state/pages/home/domain/adapters/repository_adapter.dart'; | 5 | import 'package:get_state/pages/home/domain/adapters/repository_adapter.dart'; |
| @@ -6,21 +7,24 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | @@ -6,21 +7,24 @@ import 'package:get_state/pages/home/domain/entity/cases_model.dart'; | ||
| 6 | import 'package:get_state/pages/home/presentation/controllers/home_controller.dart'; | 7 | import 'package:get_state/pages/home/presentation/controllers/home_controller.dart'; |
| 7 | import 'package:matcher/matcher.dart'; | 8 | import 'package:matcher/matcher.dart'; |
| 8 | 9 | ||
| 9 | -class MockReposity implements IHomeRepository { | 10 | +class MockRepository implements IHomeRepository { |
| 10 | @override | 11 | @override |
| 11 | Future<CasesModel> getCases() async { | 12 | Future<CasesModel> getCases() async { |
| 12 | await Future.delayed(Duration(milliseconds: 100)); | 13 | await Future.delayed(Duration(milliseconds: 100)); |
| 13 | - return Random().nextBool() | ||
| 14 | - ? CasesModel( | 14 | + |
| 15 | + if (Random().nextBool()) { | ||
| 16 | + CasesModel( | ||
| 15 | global: Global(totalDeaths: 100, totalConfirmed: 200), | 17 | global: Global(totalDeaths: 100, totalConfirmed: 200), |
| 16 | - ) | ||
| 17 | - : Future.error('error'); | 18 | + ); |
| 19 | + } | ||
| 20 | + | ||
| 21 | + return Future<CasesModel>.error('error'); | ||
| 18 | } | 22 | } |
| 19 | } | 23 | } |
| 20 | 24 | ||
| 21 | void main() { | 25 | void main() { |
| 22 | final binding = BindingsBuilder(() { | 26 | final binding = BindingsBuilder(() { |
| 23 | - Get.lazyPut<IHomeRepository>(() => MockReposity()); | 27 | + Get.lazyPut<IHomeRepository>(() => MockRepository()); |
| 24 | Get.lazyPut<HomeController>( | 28 | Get.lazyPut<HomeController>( |
| 25 | () => HomeController(homeRepository: Get.find())); | 29 | () => HomeController(homeRepository: Get.find())); |
| 26 | }); | 30 | }); |
| 1 | -export 'src/instance/get_instance.dart'; | ||
| 2 | export 'src/instance/extension_instance.dart'; | 1 | export 'src/instance/extension_instance.dart'; |
| 2 | +export 'src/instance/get_instance.dart'; | ||
| 3 | export 'src/navigation/routes/bindings_interface.dart'; | 3 | export 'src/navigation/routes/bindings_interface.dart'; |
| 1 | +export 'src/core/get_main.dart'; | ||
| 2 | +export 'src/navigation/bottomsheet/bottomsheet.dart'; | ||
| 3 | +export 'src/navigation/extension_navigation.dart'; | ||
| 4 | +export 'src/navigation/root/root_widget.dart'; | ||
| 5 | +export 'src/navigation/root/smart_management.dart'; | ||
| 1 | export 'src/navigation/routes/custom_transition.dart'; | 6 | export 'src/navigation/routes/custom_transition.dart'; |
| 2 | -export 'src/navigation/routes/transitions_type.dart'; | ||
| 3 | -export 'src/navigation/routes/get_route.dart'; | ||
| 4 | export 'src/navigation/routes/default_route.dart'; | 7 | export 'src/navigation/routes/default_route.dart'; |
| 8 | +export 'src/navigation/routes/default_route.dart'; | ||
| 9 | +export 'src/navigation/routes/get_route.dart'; | ||
| 5 | export 'src/navigation/routes/observers/route_observer.dart'; | 10 | export 'src/navigation/routes/observers/route_observer.dart'; |
| 6 | -export 'src/navigation/root/root_widget.dart'; | ||
| 7 | -export 'src/navigation/snackbar/snack_route.dart'; | ||
| 8 | -export 'src/navigation/bottomsheet/bottomsheet.dart'; | 11 | +export 'src/navigation/routes/transitions_type.dart'; |
| 9 | export 'src/navigation/snackbar/snack.dart'; | 12 | export 'src/navigation/snackbar/snack.dart'; |
| 10 | -export 'src/core/get_main.dart'; | ||
| 11 | -export 'src/navigation/routes/default_route.dart'; | ||
| 12 | -export 'src/navigation/root/smart_management.dart'; | ||
| 13 | -export 'src/navigation/extension_navigation.dart'; | 13 | +export 'src/navigation/snackbar/snack_route.dart'; |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | + | ||
| 3 | +import '../../utils.dart'; | ||
| 2 | import '../navigation/root/parse_route.dart'; | 4 | import '../navigation/root/parse_route.dart'; |
| 3 | import '../navigation/root/root_controller.dart'; | 5 | import '../navigation/root/root_controller.dart'; |
| 4 | import '../navigation/routes/custom_transition.dart'; | 6 | import '../navigation/routes/custom_transition.dart'; |
| 5 | import '../navigation/routes/observers/route_observer.dart'; | 7 | import '../navigation/routes/observers/route_observer.dart'; |
| 6 | import '../navigation/routes/transitions_type.dart'; | 8 | import '../navigation/routes/transitions_type.dart'; |
| 7 | -import '../../utils.dart'; | ||
| 8 | 9 | ||
| 9 | -///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, | ||
| 10 | -///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 11 | -///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. | ||
| 12 | -///To return to the previous screen, use Get.back(). | ||
| 13 | -///No need to pass any context to Get, just put the name of the route inside | ||
| 14 | -///the parentheses and the magic will occur. | 10 | +/// Use Get.to instead of Navigator.push, Get.off instead |
| 11 | +/// of Navigator.pushReplacement, | ||
| 12 | +/// Get.offAll instead of Navigator.pushAndRemoveUntil. | ||
| 13 | +/// For named routes just add "named" after them. Example: Get.toNamed, | ||
| 14 | +/// Get.offNamed, and Get.AllNamed. | ||
| 15 | +/// To return to the previous screen, use Get.back(). | ||
| 16 | +/// No need to pass any context to Get, just put the name of the route inside | ||
| 17 | +/// the parentheses and the magic will occur. | ||
| 15 | 18 | ||
| 16 | abstract class GetInterface { | 19 | abstract class GetInterface { |
| 17 | bool defaultPopGesture = GetPlatform.isIOS; | 20 | bool defaultPopGesture = GetPlatform.isIOS; |
| 1 | -import 'package:get/src/core/get_interface.dart'; | 1 | +import 'get_interface.dart'; |
| 2 | 2 | ||
| 3 | ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, | 3 | ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, |
| 4 | -///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
| 5 | -///after them. Example: toNamed, offNamed, and AllNamed. | 4 | +///offAll instead of Navigator.pushAndRemoveUntil. For named routes just |
| 5 | +///add "named" after them. Example: toNamed, offNamed, and AllNamed. | ||
| 6 | ///To return to the previous screen, use back(). | 6 | ///To return to the previous screen, use back(). |
| 7 | ///No need to pass any context to Get, just put the name of the route inside | 7 | ///No need to pass any context to Get, just put the name of the route inside |
| 8 | ///the parentheses and the magic will occur. | 8 | ///the parentheses and the magic will occur. |
| 1 | -import 'package:get/instance_manager.dart'; | ||
| 2 | import 'dart:developer' as developer; | 1 | import 'dart:developer' as developer; |
| 3 | 2 | ||
| 3 | +import '../../instance_manager.dart'; | ||
| 4 | + | ||
| 4 | typedef LogWriterCallback = void Function(String text, {bool isError}); | 5 | typedef LogWriterCallback = void Function(String text, {bool isError}); |
| 5 | 6 | ||
| 6 | void defaultLogWriterCallback(String value, {bool isError = false}) { | 7 | void defaultLogWriterCallback(String value, {bool isError = false}) { |
| 1 | -import 'package:get/src/core/get_interface.dart'; | ||
| 2 | - | 1 | +import '../core/get_interface.dart'; |
| 3 | import 'get_instance.dart'; | 2 | import 'get_instance.dart'; |
| 4 | 3 | ||
| 5 | extension Inst on GetInterface { | 4 | extension Inst on GetInterface { |
| 6 | /// Creates a new Instance<S> lazily from the [<S>builder()] callback. | 5 | /// Creates a new Instance<S> lazily from the [<S>builder()] callback. |
| 7 | /// | 6 | /// |
| 8 | /// The first time you call [Get.find()], the [builder()] callback will create | 7 | /// The first time you call [Get.find()], the [builder()] callback will create |
| 9 | - /// the Instance and persisted as a Singleton (like you would use [Get.put()]). | 8 | + /// the Instance and persisted as a Singleton (like you would use |
| 9 | + /// [Get.put()]). | ||
| 10 | /// | 10 | /// |
| 11 | - /// Using [GetConfig.smartManagement] as [SmartManagement.keepFactory] has the same outcome | 11 | + /// Using [GetConfig.smartManagement] as [SmartManagement.keepFactory] has |
| 12 | + /// the same outcome | ||
| 12 | /// as using [fenix:true] : | 13 | /// as using [fenix:true] : |
| 13 | - /// The internal register of [builder()] will remain in memory to recreate the Instance | ||
| 14 | - /// if the Instance has been removed with [Get.delete()]. | 14 | + /// The internal register of [builder()] will remain in memory to recreate |
| 15 | + /// the Instance if the Instance has been removed with [Get.delete()]. | ||
| 15 | /// Therefore, future calls to [Get.find()] will return the same Instance. | 16 | /// Therefore, future calls to [Get.find()] will return the same Instance. |
| 16 | /// | 17 | /// |
| 17 | - /// If you need to make use of GetxController's life-cycle ([onInit(), onStart(), onClose()]) | ||
| 18 | - /// [fenix] is a great choice to mix with [GetBuilder()] and [GetX()] widgets, and/or [GetMaterialApp] Navigation. | 18 | + /// 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. | ||
| 19 | /// | 22 | /// |
| 20 | - /// You could use [Get.lazyPut(fenix:true)] in your app's [main()] instead of [Bindings()] for each [GetPage]. | 23 | + /// You could use [Get.lazyPut(fenix:true)] in your app's [main()] instead of |
| 24 | + /// [Bindings()] for each [GetPage]. | ||
| 21 | /// And the memory management will be similar. | 25 | /// And the memory management will be similar. |
| 22 | /// | 26 | /// |
| 23 | - /// Subsequent calls to [Get.lazyPut()] with the same parameters (<[S]> and optionally [tag] | ||
| 24 | - /// will **not** override the original). | 27 | + /// Subsequent calls to [Get.lazyPut()] with the same parameters |
| 28 | + /// (<[S]> and optionally [tag] will **not** override the original). | ||
| 25 | void lazyPut<S>(InstanceBuilderCallback<S> builder, | 29 | void lazyPut<S>(InstanceBuilderCallback<S> builder, |
| 26 | {String tag, bool fenix = false}) { | 30 | {String tag, bool fenix = false}) { |
| 27 | GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); | 31 | GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); |
| @@ -55,14 +59,17 @@ extension Inst on GetInterface { | @@ -55,14 +59,17 @@ extension Inst on GetInterface { | ||
| 55 | 59 | ||
| 56 | /// Injects an [Instance<S>] in memory. | 60 | /// Injects an [Instance<S>] in memory. |
| 57 | /// | 61 | /// |
| 58 | - /// No need to define the generic type <[S]> as it's inferred from the [dependency] | ||
| 59 | - /// parameter. | 62 | + /// No need to define the generic type <[S]> as it's inferred |
| 63 | + /// from the [dependency] parameter. | ||
| 60 | /// | 64 | /// |
| 61 | /// - [dependency] The Instance to be injected. | 65 | /// - [dependency] The Instance to be injected. |
| 62 | - /// - [tag] optionally, use a [tag] as an "id" to create multiple records of the same Type<[S]> | ||
| 63 | - /// the [tag] does **not** conflict with the same tags used by other [dependencies] Types. | ||
| 64 | - /// - [permanent] keeps the Instance in memory and persist it, not following [GetConfig.smartManagement] | ||
| 65 | - /// rules. Although, can be removed by [GetInstance.reset()] and [Get.delete()] | 66 | + /// - [tag] optionally, use a [tag] as an "id" to create multiple records |
| 67 | + /// of the same Type<[S]> the [tag] does **not** conflict with the same tags | ||
| 68 | + /// used by other [dependencies] Types. | ||
| 69 | + /// - [permanent] keeps the Instance in memory and persist it, | ||
| 70 | + /// not following [GetConfig.smartManagement] | ||
| 71 | + /// rules. Although, can be removed by [GetInstance.reset()] | ||
| 72 | + /// and [Get.delete()] | ||
| 66 | /// - [builder] If defined, the [dependency] must be returned from here | 73 | /// - [builder] If defined, the [dependency] must be returned from here |
| 67 | S put<S>(S dependency, | 74 | S put<S>(S dependency, |
| 68 | {String tag, | 75 | {String tag, |
| 1 | -import 'package:get/src/core/log.dart'; | ||
| 2 | -import 'package:get/src/navigation/root/smart_management.dart'; | ||
| 3 | -import 'package:get/src/state_manager/rx/rx_core/rx_interface.dart'; | ||
| 4 | -import 'package:get/src/utils/queue/get_queue.dart'; | 1 | +import '../core/log.dart'; |
| 2 | +import '../navigation/root/smart_management.dart'; | ||
| 3 | +import '../state_manager/rx/rx_core/rx_interface.dart'; | ||
| 4 | +import '../utils/queue/get_queue.dart'; | ||
| 5 | 5 | ||
| 6 | +// ignore: avoid_classes_with_only_static_members | ||
| 6 | class GetConfig { | 7 | class GetConfig { |
| 7 | static SmartManagement smartManagement = SmartManagement.full; | 8 | static SmartManagement smartManagement = SmartManagement.full; |
| 8 | static bool isLogEnable = true; | 9 | static bool isLogEnable = true; |
| @@ -19,59 +20,70 @@ class GetInstance { | @@ -19,59 +20,70 @@ class GetInstance { | ||
| 19 | 20 | ||
| 20 | /// Holds references to every registered Instance when using | 21 | /// Holds references to every registered Instance when using |
| 21 | /// [Get.put()] | 22 | /// [Get.put()] |
| 22 | - static Map<String, _InstanceBuilderFactory> _singl = {}; | 23 | + static final Map<String, _InstanceBuilderFactory> _singl = {}; |
| 23 | 24 | ||
| 24 | /// Holds a reference to every registered callback when using | 25 | /// Holds a reference to every registered callback when using |
| 25 | /// [Get.lazyPut()] | 26 | /// [Get.lazyPut()] |
| 26 | - static Map<String, _Lazy> _factory = {}; | 27 | + static final Map<String, _Lazy> _factory = {}; |
| 27 | 28 | ||
| 28 | /// Holds a reference to [GetConfig.currentRoute] when the Instance was | 29 | /// Holds a reference to [GetConfig.currentRoute] when the Instance was |
| 29 | /// created to manage the memory. | 30 | /// created to manage the memory. |
| 30 | - static Map<String, String> _routesKey = {}; | 31 | + static final Map<String, String> _routesKey = {}; |
| 31 | 32 | ||
| 32 | - static GetQueue _queue = GetQueue(); | 33 | + static final _queue = GetQueue(); |
| 33 | 34 | ||
| 34 | /// Creates a new Instance<S> lazily from the [<S>builder()] callback. | 35 | /// Creates a new Instance<S> lazily from the [<S>builder()] callback. |
| 35 | /// | 36 | /// |
| 36 | /// The first time you call [Get.find()], the [builder()] callback will create | 37 | /// The first time you call [Get.find()], the [builder()] callback will create |
| 37 | - /// the Instance and persisted as a Singleton (like you would use [Get.put()]). | 38 | + /// the Instance and persisted as a Singleton (like you would |
| 39 | + /// use [Get.put()]). | ||
| 38 | /// | 40 | /// |
| 39 | - /// Using [GetConfig.smartManagement] as [SmartManagement.keepFactory] has the same outcome | ||
| 40 | - /// as using [fenix:true] : | ||
| 41 | - /// The internal register of [builder()] will remain in memory to recreate the Instance | ||
| 42 | - /// if the Instance has been removed with [Get.delete()]. | 41 | + /// Using [GetConfig.smartManagement] as [SmartManagement.keepFactory] has |
| 42 | + /// the same outcome as using [fenix:true] : | ||
| 43 | + /// The internal register of [builder()] will remain in memory to recreate | ||
| 44 | + /// the Instance if the Instance has been removed with [Get.delete()]. | ||
| 43 | /// Therefore, future calls to [Get.find()] will return the same Instance. | 45 | /// Therefore, future calls to [Get.find()] will return the same Instance. |
| 44 | /// | 46 | /// |
| 45 | - /// If you need to make use of GetxController's life-cycle ([onInit(), onStart(), onClose()]) | ||
| 46 | - /// [fenix] is a great choice to mix with [GetBuilder()] and [GetX()] widgets, and/or [GetMaterialApp] Navigation. | 47 | + /// If you need to make use of GetxController's life-cycle |
| 48 | + /// ([onInit(), onStart(), onClose()]) [fenix] is a great choice to mix with | ||
| 49 | + /// [GetBuilder()] and [GetX()] widgets, and/or [GetMaterialApp] Navigation. | ||
| 47 | /// | 50 | /// |
| 48 | - /// You could use [Get.lazyPut(fenix:true)] in your app's [main()] instead of [Bindings()] for each [GetPage]. | 51 | + /// You could use [Get.lazyPut(fenix:true)] in your app's [main()] instead |
| 52 | + /// of [Bindings()] for each [GetPage]. | ||
| 49 | /// And the memory management will be similar. | 53 | /// And the memory management will be similar. |
| 50 | /// | 54 | /// |
| 51 | - /// Subsequent calls to [Get.lazyPut()] with the same parameters (<[S]> and optionally [tag] | ||
| 52 | - /// will **not** override the original). | ||
| 53 | - void lazyPut<S>(InstanceBuilderCallback<S> builder, | ||
| 54 | - {String tag, bool fenix = false}) { | ||
| 55 | - String key = _getKey(S, tag); | 55 | + /// Subsequent calls to [Get.lazyPut()] with the same parameters |
| 56 | + /// (<[S]> and optionally [tag] will **not** override the original). | ||
| 57 | + void lazyPut<S>( | ||
| 58 | + InstanceBuilderCallback<S> builder, { | ||
| 59 | + String tag, | ||
| 60 | + bool fenix = false, | ||
| 61 | + }) { | ||
| 62 | + final key = _getKey(S, tag); | ||
| 56 | _factory.putIfAbsent(key, () => _Lazy(builder, fenix)); | 63 | _factory.putIfAbsent(key, () => _Lazy(builder, fenix)); |
| 57 | } | 64 | } |
| 58 | 65 | ||
| 59 | /// async version of [Get.put()]. | 66 | /// async version of [Get.put()]. |
| 60 | /// Awaits for the resolution of the Future from [builder()] parameter and | 67 | /// Awaits for the resolution of the Future from [builder()] parameter and |
| 61 | /// stores the Instance returned. | 68 | /// stores the Instance returned. |
| 62 | - Future<S> putAsync<S>(AsyncInstanceBuilderCallback<S> builder, | ||
| 63 | - {String tag, bool permanent = false}) async { | 69 | + Future<S> putAsync<S>( |
| 70 | + AsyncInstanceBuilderCallback<S> builder, { | ||
| 71 | + String tag, | ||
| 72 | + bool permanent = false, | ||
| 73 | + }) async { | ||
| 64 | return put<S>(await builder(), tag: tag, permanent: permanent); | 74 | return put<S>(await builder(), tag: tag, permanent: permanent); |
| 65 | } | 75 | } |
| 66 | 76 | ||
| 67 | /// Injects an instance <[S]> in memory to be globally accessible. | 77 | /// Injects an instance <[S]> in memory to be globally accessible. |
| 68 | /// | 78 | /// |
| 69 | - /// No need to define the generic type <[S]> as it's inferred from the [dependency] | 79 | + /// No need to define the generic type <[S]> as it's inferred from |
| 80 | + /// the [dependency] | ||
| 70 | /// | 81 | /// |
| 71 | /// - [dependency] The Instance to be injected. | 82 | /// - [dependency] The Instance to be injected. |
| 72 | - /// - [tag] optionally, use a [tag] as an "id" to create multiple records of the same Type<[S]> | ||
| 73 | - /// - [permanent] keeps the Instance in memory, not following [GetConfig.smartManagement] | ||
| 74 | - /// rules. | 83 | + /// - [tag] optionally, use a [tag] as an "id" to create multiple records of |
| 84 | + /// the same Type<[S]> | ||
| 85 | + /// - [permanent] keeps the Instance in memory, not following | ||
| 86 | + /// [GetConfig.smartManagement] rules. | ||
| 75 | S put<S>( | 87 | S put<S>( |
| 76 | S dependency, { | 88 | S dependency, { |
| 77 | String tag, | 89 | String tag, |
| @@ -121,7 +133,8 @@ class GetInstance { | @@ -121,7 +133,8 @@ class GetInstance { | ||
| 121 | } | 133 | } |
| 122 | 134 | ||
| 123 | /// Clears from memory registered Instances associated with [routeName] when | 135 | /// Clears from memory registered Instances associated with [routeName] when |
| 124 | - /// using [GetConfig.smartManagement] as [SmartManagement.full] or [SmartManagement.keepFactory] | 136 | + /// using [GetConfig.smartManagement] as [SmartManagement.full] or |
| 137 | + /// [SmartManagement.keepFactory] | ||
| 125 | /// Meant for internal usage of [GetPageRoute] and [GetDialogRoute] | 138 | /// Meant for internal usage of [GetPageRoute] and [GetDialogRoute] |
| 126 | Future<void> removeDependencyByRoute(String routeName) async { | 139 | Future<void> removeDependencyByRoute(String routeName) async { |
| 127 | final keysToRemove = <String>[]; | 140 | final keysToRemove = <String>[]; |
| @@ -131,12 +144,15 @@ class GetInstance { | @@ -131,12 +144,15 @@ class GetInstance { | ||
| 131 | } | 144 | } |
| 132 | }); | 145 | }); |
| 133 | 146 | ||
| 147 | + // FIXME: this will not await sequentially as probably is expected | ||
| 148 | + // ignore: avoid_function_literals_in_foreach_calls | ||
| 134 | keysToRemove.forEach((element) async { | 149 | keysToRemove.forEach((element) async { |
| 135 | await delete(key: element); | 150 | await delete(key: element); |
| 136 | }); | 151 | }); |
| 137 | - keysToRemove.forEach((element) { | 152 | + |
| 153 | + for (final element in keysToRemove) { | ||
| 138 | _routesKey?.remove(element); | 154 | _routesKey?.remove(element); |
| 139 | - }); | 155 | + } |
| 140 | keysToRemove.clear(); | 156 | keysToRemove.clear(); |
| 141 | } | 157 | } |
| 142 | 158 | ||
| @@ -147,7 +163,7 @@ class GetInstance { | @@ -147,7 +163,7 @@ class GetInstance { | ||
| 147 | /// [GetConfig.keepFactory] | 163 | /// [GetConfig.keepFactory] |
| 148 | bool _initDependencies<S>({String name}) { | 164 | bool _initDependencies<S>({String name}) { |
| 149 | final key = _getKey(S, name); | 165 | final key = _getKey(S, name); |
| 150 | - bool isInit = _singl[key].isInit; | 166 | + final isInit = _singl[key].isInit; |
| 151 | if (!isInit) { | 167 | if (!isInit) { |
| 152 | _startController<S>(tag: name); | 168 | _startController<S>(tag: name); |
| 153 | _singl[key].isInit = true; | 169 | _singl[key].isInit = true; |
| @@ -166,7 +182,7 @@ class GetInstance { | @@ -166,7 +182,7 @@ class GetInstance { | ||
| 166 | 182 | ||
| 167 | /// Finds and returns a Instance<[S]> (or [tag]) without further processing. | 183 | /// Finds and returns a Instance<[S]> (or [tag]) without further processing. |
| 168 | S findByType<S>(Type type, {String tag}) { | 184 | S findByType<S>(Type type, {String tag}) { |
| 169 | - String key = _getKey(type, tag); | 185 | + final key = _getKey(type, tag); |
| 170 | return _singl[key].getDependency() as S; | 186 | return _singl[key].getDependency() as S; |
| 171 | } | 187 | } |
| 172 | 188 | ||
| @@ -204,12 +220,12 @@ class GetInstance { | @@ -204,12 +220,12 @@ class GetInstance { | ||
| 204 | // } | 220 | // } |
| 205 | 221 | ||
| 206 | /// Finds the registered type <[S]> (or [tag]) | 222 | /// Finds the registered type <[S]> (or [tag]) |
| 207 | - /// In case of using Get.[create] to register a type <[S]> or [tag], it will create an instance | ||
| 208 | - /// each time you call [find]. | ||
| 209 | - /// If the registered type <[S]> (or [tag]) is a Controller, it will initialize | ||
| 210 | - /// it's lifecycle. | 223 | + /// In case of using Get.[create] to register a type <[S]> or [tag], |
| 224 | + /// it will create an instance each time you call [find]. | ||
| 225 | + /// If the registered type <[S]> (or [tag]) is a Controller, | ||
| 226 | + /// it will initialize it's lifecycle. | ||
| 211 | S find<S>({String tag}) { | 227 | S find<S>({String tag}) { |
| 212 | - String key = _getKey(S, tag); | 228 | + final key = _getKey(S, tag); |
| 213 | if (isRegistered<S>(tag: tag)) { | 229 | if (isRegistered<S>(tag: tag)) { |
| 214 | if (_singl[key] == null) { | 230 | if (_singl[key] == null) { |
| 215 | if (tag == null) { | 231 | if (tag == null) { |
| @@ -221,12 +237,14 @@ class GetInstance { | @@ -221,12 +237,14 @@ class GetInstance { | ||
| 221 | _initDependencies<S>(name: tag); | 237 | _initDependencies<S>(name: tag); |
| 222 | return _singl[key].getDependency() as S; | 238 | return _singl[key].getDependency() as S; |
| 223 | } else { | 239 | } else { |
| 224 | - if (!_factory.containsKey(key)) | 240 | + if (!_factory.containsKey(key)) { |
| 241 | + // ignore: lines_longer_than_80_chars | ||
| 225 | throw '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"'; | 242 | throw '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"'; |
| 243 | + } | ||
| 226 | 244 | ||
| 227 | GetConfig.log('Lazy instance "$S" created'); | 245 | GetConfig.log('Lazy instance "$S" created'); |
| 228 | 246 | ||
| 229 | - S _value = put<S>(_factory[key].builder() as S); | 247 | + var _value = put<S>(_factory[key].builder() as S); |
| 230 | 248 | ||
| 231 | _initDependencies<S>(name: tag); | 249 | _initDependencies<S>(name: tag); |
| 232 | 250 | ||
| @@ -258,11 +276,15 @@ class GetInstance { | @@ -258,11 +276,15 @@ class GetInstance { | ||
| 258 | return true; | 276 | return true; |
| 259 | } | 277 | } |
| 260 | 278 | ||
| 261 | - // Future<bool> delete<S>({String tag, String key, bool force = false}) async { | ||
| 262 | - // final s = await queue | ||
| 263 | - // .add<bool>(() async => dele<S>(tag: tag, key: key, force: force)); | ||
| 264 | - // return s; | ||
| 265 | - // } | 279 | +// Future<bool> delete<S>({ |
| 280 | +// String tag, | ||
| 281 | +// String key, | ||
| 282 | +// bool force = false, | ||
| 283 | +// }) async { | ||
| 284 | +// final s = await queue | ||
| 285 | +// .add<bool>(() async => dele<S>(tag: tag, key: key, force: force)); | ||
| 286 | +// return s; | ||
| 287 | +// } | ||
| 266 | 288 | ||
| 267 | /// Delete registered Class Instance [S] (or [tag]) and, closes any open | 289 | /// Delete registered Class Instance [S] (or [tag]) and, closes any open |
| 268 | /// controllers [DisposableInterface], cleans up the memory | 290 | /// controllers [DisposableInterface], cleans up the memory |
| @@ -292,6 +314,7 @@ class GetInstance { | @@ -292,6 +314,7 @@ class GetInstance { | ||
| 292 | final builder = _singl[newKey]; | 314 | final builder = _singl[newKey]; |
| 293 | if (builder.permanent && !force) { | 315 | if (builder.permanent && !force) { |
| 294 | GetConfig.log( | 316 | GetConfig.log( |
| 317 | + // ignore: lines_longer_than_80_chars | ||
| 295 | '"$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.', | 318 | '"$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.', |
| 296 | isError: true, | 319 | isError: true, |
| 297 | ); | 320 | ); |
| @@ -352,7 +375,11 @@ class _InstanceBuilderFactory<S> { | @@ -352,7 +375,11 @@ class _InstanceBuilderFactory<S> { | ||
| 352 | bool isInit = false; | 375 | bool isInit = false; |
| 353 | 376 | ||
| 354 | _InstanceBuilderFactory( | 377 | _InstanceBuilderFactory( |
| 355 | - this.isSingleton, this.builderFunc, this.permanent, this.isInit); | 378 | + this.isSingleton, |
| 379 | + this.builderFunc, | ||
| 380 | + this.permanent, | ||
| 381 | + this.isInit, | ||
| 382 | + ); | ||
| 356 | 383 | ||
| 357 | /// Gets the actual instance by it's [builderFunc] or the persisted instance. | 384 | /// Gets the actual instance by it's [builderFunc] or the persisted instance. |
| 358 | S getDependency() { | 385 | S getDependency() { |
| @@ -365,5 +392,6 @@ class _InstanceBuilderFactory<S> { | @@ -365,5 +392,6 @@ class _InstanceBuilderFactory<S> { | ||
| 365 | class _Lazy { | 392 | class _Lazy { |
| 366 | bool fenix; | 393 | bool fenix; |
| 367 | InstanceBuilderCallback builder; | 394 | InstanceBuilderCallback builder; |
| 395 | + | ||
| 368 | _Lazy(this.builder, this.fenix); | 396 | _Lazy(this.builder, this.fenix); |
| 369 | } | 397 | } |
| @@ -61,7 +61,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -61,7 +61,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
| 61 | @override | 61 | @override |
| 62 | Widget buildPage(BuildContext context, Animation<double> animation, | 62 | Widget buildPage(BuildContext context, Animation<double> animation, |
| 63 | Animation<double> secondaryAnimation) { | 63 | Animation<double> secondaryAnimation) { |
| 64 | - final BottomSheetThemeData sheetTheme = | 64 | + final sheetTheme = |
| 65 | theme?.bottomSheetTheme ?? Theme.of(context).bottomSheetTheme; | 65 | theme?.bottomSheetTheme ?? Theme.of(context).bottomSheetTheme; |
| 66 | // By definition, the bottom sheet is aligned to the bottom of the page | 66 | // By definition, the bottom sheet is aligned to the bottom of the page |
| 67 | // and isn't exposed to the top padding of the MediaQuery. | 67 | // and isn't exposed to the top padding of the MediaQuery. |
| @@ -130,17 +130,16 @@ class _GetModalBottomSheetState<T> extends State<_GetModalBottomSheet<T>> { | @@ -130,17 +130,16 @@ class _GetModalBottomSheetState<T> extends State<_GetModalBottomSheet<T>> { | ||
| 130 | Widget build(BuildContext context) { | 130 | Widget build(BuildContext context) { |
| 131 | assert(debugCheckHasMediaQuery(context)); | 131 | assert(debugCheckHasMediaQuery(context)); |
| 132 | assert(debugCheckHasMaterialLocalizations(context)); | 132 | assert(debugCheckHasMaterialLocalizations(context)); |
| 133 | - final MediaQueryData mediaQuery = MediaQuery.of(context); | ||
| 134 | - final MaterialLocalizations localizations = | ||
| 135 | - MaterialLocalizations.of(context); | ||
| 136 | - final String routeLabel = _getRouteLabel(localizations); | 133 | + final mediaQuery = MediaQuery.of(context); |
| 134 | + final localizations = MaterialLocalizations.of(context); | ||
| 135 | + final routeLabel = _getRouteLabel(localizations); | ||
| 137 | 136 | ||
| 138 | return AnimatedBuilder( | 137 | return AnimatedBuilder( |
| 139 | animation: widget.route.animation, | 138 | animation: widget.route.animation, |
| 140 | - builder: (BuildContext context, Widget child) { | 139 | + builder: (context, child) { |
| 141 | // Disable the initial animation when accessible navigation is on so | 140 | // Disable the initial animation when accessible navigation is on so |
| 142 | // that the semantics are added to the tree at the correct time. | 141 | // that the semantics are added to the tree at the correct time. |
| 143 | - final double animationValue = mediaQuery.accessibleNavigation | 142 | + final animationValue = mediaQuery.accessibleNavigation |
| 144 | ? 1.0 | 143 | ? 1.0 |
| 145 | : widget.route.animation.value; | 144 | : widget.route.animation.value; |
| 146 | return Semantics( | 145 | return Semantics( |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/scheduler.dart'; | 2 | import 'package:flutter/scheduler.dart'; |
| 3 | -import 'package:get/instance_manager.dart'; | ||
| 4 | -import 'package:get/route_manager.dart'; | ||
| 5 | -import 'package:get/src/core/get_interface.dart'; | ||
| 6 | -import 'package:get/src/core/log.dart'; | ||
| 7 | 3 | ||
| 4 | +import '../../instance_manager.dart'; | ||
| 5 | +import '../../route_manager.dart'; | ||
| 6 | +import '../core/get_interface.dart'; | ||
| 7 | +import '../core/log.dart'; | ||
| 8 | import 'dialog/dialog_route.dart'; | 8 | import 'dialog/dialog_route.dart'; |
| 9 | import 'root/parse_route.dart'; | 9 | import 'root/parse_route.dart'; |
| 10 | import 'routes/bindings_interface.dart'; | 10 | import 'routes/bindings_interface.dart'; |
| 11 | 11 | ||
| 12 | /// It replaces the Flutter Navigator, but needs no context. | 12 | /// It replaces the Flutter Navigator, but needs no context. |
| 13 | -/// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute()); | 13 | +/// You can to use navigator.push(YourRoute()) rather |
| 14 | +/// Navigator.push(context, YourRoute()); | ||
| 14 | NavigatorState get navigator => Get.key.currentState; | 15 | NavigatorState get navigator => Get.key.currentState; |
| 15 | 16 | ||
| 16 | extension GetNavigation on GetInterface { | 17 | extension GetNavigation on GetInterface { |
| @@ -50,15 +51,15 @@ extension GetNavigation on GetInterface { | @@ -50,15 +51,15 @@ extension GetNavigation on GetInterface { | ||
| 50 | bool preventDuplicates = true, | 51 | bool preventDuplicates = true, |
| 51 | bool popGesture, | 52 | bool popGesture, |
| 52 | }) { | 53 | }) { |
| 53 | - String routename = "/${page.runtimeType.toString()}"; | ||
| 54 | - if (preventDuplicates && routename == currentRoute) { | 54 | + var routeName = "/${page.runtimeType.toString()}"; |
| 55 | + if (preventDuplicates && routeName == currentRoute) { | ||
| 55 | return null; | 56 | return null; |
| 56 | } | 57 | } |
| 57 | return global(id).currentState.push( | 58 | return global(id).currentState.push( |
| 58 | GetPageRoute( | 59 | GetPageRoute( |
| 59 | opaque: opaque ?? true, | 60 | opaque: opaque ?? true, |
| 60 | page: () => page, | 61 | page: () => page, |
| 61 | - routeName: routename, | 62 | + routeName: routeName, |
| 62 | settings: RouteSettings( | 63 | settings: RouteSettings( |
| 63 | // name: forceRouteName ? '${a.runtimeType}' : '', | 64 | // name: forceRouteName ? '${a.runtimeType}' : '', |
| 64 | arguments: arguments, | 65 | arguments: arguments, |
| @@ -141,7 +142,8 @@ extension GetNavigation on GetInterface { | @@ -141,7 +142,8 @@ extension GetNavigation on GetInterface { | ||
| 141 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | 142 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, |
| 142 | /// | 143 | /// |
| 143 | /// or also like this: | 144 | /// or also like this: |
| 144 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog is closed | 145 | + /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the |
| 146 | + /// dialog is closed | ||
| 145 | void until(RoutePredicate predicate, {int id}) { | 147 | void until(RoutePredicate predicate, {int id}) { |
| 146 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 148 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 147 | // when widget don't mounted | 149 | // when widget don't mounted |
| @@ -164,7 +166,8 @@ extension GetNavigation on GetInterface { | @@ -164,7 +166,8 @@ extension GetNavigation on GetInterface { | ||
| 164 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | 166 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, |
| 165 | /// | 167 | /// |
| 166 | /// or also like this: | 168 | /// or also like this: |
| 167 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog is closed | 169 | + /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog |
| 170 | + /// is closed | ||
| 168 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { | 171 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { |
| 169 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 172 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
| 170 | // when widget don't mounted | 173 | // when widget don't mounted |
| @@ -184,7 +187,8 @@ extension GetNavigation on GetInterface { | @@ -184,7 +187,8 @@ extension GetNavigation on GetInterface { | ||
| 184 | /// [predicate] can be used like this: | 187 | /// [predicate] can be used like this: |
| 185 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | 188 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, |
| 186 | /// or also like | 189 | /// or also like |
| 187 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog is closed | 190 | + /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog |
| 191 | + /// is closed | ||
| 188 | /// | 192 | /// |
| 189 | /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | 193 | /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors |
| 190 | Future<T> offNamedUntil<T>( | 194 | Future<T> offNamedUntil<T>( |
| @@ -200,14 +204,15 @@ extension GetNavigation on GetInterface { | @@ -200,14 +204,15 @@ extension GetNavigation on GetInterface { | ||
| 200 | 204 | ||
| 201 | /// **Navigation.popAndPushNamed()** shortcut.<br><br> | 205 | /// **Navigation.popAndPushNamed()** shortcut.<br><br> |
| 202 | /// | 206 | /// |
| 203 | - /// Pop the current named page and pushes a new [page] to the stack in its place | 207 | + /// Pop the current named page and pushes a new [page] to the stack |
| 208 | + /// in its place | ||
| 204 | /// | 209 | /// |
| 205 | /// You can send any type of value to the other route in the [arguments]. | 210 | /// You can send any type of value to the other route in the [arguments]. |
| 206 | /// It is very similar to `offNamed()` but use a different approach | 211 | /// It is very similar to `offNamed()` but use a different approach |
| 207 | /// | 212 | /// |
| 208 | - /// The `offNamed()` pop a page, and goes to the next. The `offAndToNamed()` goes | ||
| 209 | - /// to the next page, and removes the previous one. The route transition | ||
| 210 | - /// animation is different. | 213 | + /// The `offNamed()` pop a page, and goes to the next. The |
| 214 | + /// `offAndToNamed()` goes to the next page, and removes the previous one. | ||
| 215 | + /// The route transition animation is different. | ||
| 211 | Future<T> offAndToNamed<T>(String page, | 216 | Future<T> offAndToNamed<T>(String page, |
| 212 | {Object arguments, int id, dynamic result}) { | 217 | {Object arguments, int id, dynamic result}) { |
| 213 | return global(id) | 218 | return global(id) |
| @@ -238,19 +243,24 @@ extension GetNavigation on GetInterface { | @@ -238,19 +243,24 @@ extension GetNavigation on GetInterface { | ||
| 238 | /// [predicate] can be used like this: | 243 | /// [predicate] can be used like this: |
| 239 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | 244 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, |
| 240 | /// or also like | 245 | /// or also like |
| 241 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog is closed | 246 | + /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog |
| 247 | + /// is closed | ||
| 242 | /// | 248 | /// |
| 243 | /// [id] is for when you are using nested navigation, | 249 | /// [id] is for when you are using nested navigation, |
| 244 | /// as explained in documentation | 250 | /// as explained in documentation |
| 245 | /// | 251 | /// |
| 246 | /// Note: Always put a slash on the route ('/page1'), to avoid unexpected errors | 252 | /// Note: Always put a slash on the route ('/page1'), to avoid unexpected errors |
| 247 | - Future<T> offAllNamed<T>(String newRouteName, | ||
| 248 | - {RoutePredicate predicate, Object arguments, int id}) { | ||
| 249 | - var route = (Route<dynamic> rota) => false; | ||
| 250 | - | 253 | + Future<T> offAllNamed<T>( |
| 254 | + String newRouteName, { | ||
| 255 | + RoutePredicate predicate, | ||
| 256 | + Object arguments, | ||
| 257 | + int id, | ||
| 258 | + }) { | ||
| 251 | return global(id).currentState.pushNamedAndRemoveUntil( | 259 | return global(id).currentState.pushNamedAndRemoveUntil( |
| 252 | - newRouteName, predicate ?? route, | ||
| 253 | - arguments: arguments); | 260 | + newRouteName, |
| 261 | + predicate ?? (_) => false, | ||
| 262 | + arguments: arguments, | ||
| 263 | + ); | ||
| 254 | } | 264 | } |
| 255 | 265 | ||
| 256 | /// Returns true if a Snackbar, Dialog or BottomSheet is currently OPEN | 266 | /// Returns true if a Snackbar, Dialog or BottomSheet is currently OPEN |
| @@ -265,8 +275,8 @@ extension GetNavigation on GetInterface { | @@ -265,8 +275,8 @@ extension GetNavigation on GetInterface { | ||
| 265 | /// | 275 | /// |
| 266 | /// Pop the current page, snackbar, dialog or bottomsheet in the stack | 276 | /// Pop the current page, snackbar, dialog or bottomsheet in the stack |
| 267 | /// | 277 | /// |
| 268 | - /// if your set [closeOverlays] to true, Get.back() will close the currently open | ||
| 269 | - /// snackbar/dialog/bottomsheet AND the current page | 278 | + /// if your set [closeOverlays] to true, Get.back() will close the |
| 279 | + /// currently open snackbar/dialog/bottomsheet AND the current page | ||
| 270 | /// | 280 | /// |
| 271 | /// [id] is for when you are using nested navigation, | 281 | /// [id] is for when you are using nested navigation, |
| 272 | /// as explained in documentation | 282 | /// as explained in documentation |
| @@ -303,10 +313,9 @@ extension GetNavigation on GetInterface { | @@ -303,10 +313,9 @@ extension GetNavigation on GetInterface { | ||
| 303 | if ((times == null) || (times < 1)) { | 313 | if ((times == null) || (times < 1)) { |
| 304 | times = 1; | 314 | times = 1; |
| 305 | } | 315 | } |
| 306 | - int count = 0; | ||
| 307 | - void back = global(id).currentState.popUntil((route) { | ||
| 308 | - return count++ == times; | ||
| 309 | - }); | 316 | + var count = 0; |
| 317 | + var back = global(id).currentState.popUntil((route) => count++ == times); | ||
| 318 | + | ||
| 310 | return back; | 319 | return back; |
| 311 | } | 320 | } |
| 312 | 321 | ||
| @@ -346,8 +355,8 @@ extension GetNavigation on GetInterface { | @@ -346,8 +355,8 @@ extension GetNavigation on GetInterface { | ||
| 346 | bool preventDuplicates = true, | 355 | bool preventDuplicates = true, |
| 347 | Duration duration, | 356 | Duration duration, |
| 348 | }) { | 357 | }) { |
| 349 | - String routename = "/${page.runtimeType.toString()}"; | ||
| 350 | - if (preventDuplicates && routename == currentRoute) { | 358 | + var routeName = "/${page.runtimeType.toString()}"; |
| 359 | + if (preventDuplicates && routeName == currentRoute) { | ||
| 351 | return null; | 360 | return null; |
| 352 | } | 361 | } |
| 353 | return global(id).currentState.pushReplacement(GetPageRoute( | 362 | return global(id).currentState.pushReplacement(GetPageRoute( |
| @@ -355,7 +364,7 @@ extension GetNavigation on GetInterface { | @@ -355,7 +364,7 @@ extension GetNavigation on GetInterface { | ||
| 355 | page: () => page, | 364 | page: () => page, |
| 356 | binding: binding, | 365 | binding: binding, |
| 357 | settings: RouteSettings(arguments: arguments), | 366 | settings: RouteSettings(arguments: arguments), |
| 358 | - routeName: routename, | 367 | + routeName: routeName, |
| 359 | fullscreenDialog: fullscreenDialog, | 368 | fullscreenDialog: fullscreenDialog, |
| 360 | popGesture: popGesture ?? defaultPopGesture, | 369 | popGesture: popGesture ?? defaultPopGesture, |
| 361 | transition: transition ?? defaultTransition, | 370 | transition: transition ?? defaultTransition, |
| @@ -380,7 +389,8 @@ extension GetNavigation on GetInterface { | @@ -380,7 +389,8 @@ extension GetNavigation on GetInterface { | ||
| 380 | /// [predicate] can be used like this: | 389 | /// [predicate] can be used like this: |
| 381 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, | 390 | /// `Get.until((route) => Get.currentRoute == '/home')`so when you get to home page, |
| 382 | /// or also like | 391 | /// or also like |
| 383 | - /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog is closed | 392 | + /// `Get.until((route) => !Get.isDialogOpen())`, to make sure the dialog |
| 393 | + /// is closed | ||
| 384 | /// | 394 | /// |
| 385 | /// [id] is for when you are using nested navigation, | 395 | /// [id] is for when you are using nested navigation, |
| 386 | /// as explained in documentation | 396 | /// as explained in documentation |
| @@ -404,9 +414,7 @@ extension GetNavigation on GetInterface { | @@ -404,9 +414,7 @@ extension GetNavigation on GetInterface { | ||
| 404 | Duration duration, | 414 | Duration duration, |
| 405 | Transition transition, | 415 | Transition transition, |
| 406 | }) { | 416 | }) { |
| 407 | - var route = (Route<dynamic> rota) => false; | ||
| 408 | - | ||
| 409 | - String routename = "/${page.runtimeType.toString()}"; | 417 | + var routeName = "/${page.runtimeType.toString()}"; |
| 410 | 418 | ||
| 411 | return global(id).currentState.pushAndRemoveUntil( | 419 | return global(id).currentState.pushAndRemoveUntil( |
| 412 | GetPageRoute( | 420 | GetPageRoute( |
| @@ -416,11 +424,12 @@ extension GetNavigation on GetInterface { | @@ -416,11 +424,12 @@ extension GetNavigation on GetInterface { | ||
| 416 | binding: binding, | 424 | binding: binding, |
| 417 | settings: RouteSettings(arguments: arguments), | 425 | settings: RouteSettings(arguments: arguments), |
| 418 | fullscreenDialog: fullscreenDialog, | 426 | fullscreenDialog: fullscreenDialog, |
| 419 | - routeName: routename, | 427 | + routeName: routeName, |
| 420 | transition: transition ?? defaultTransition, | 428 | transition: transition ?? defaultTransition, |
| 421 | transitionDuration: duration ?? defaultDurationTransition, | 429 | transitionDuration: duration ?? defaultDurationTransition, |
| 422 | ), | 430 | ), |
| 423 | - predicate ?? route); | 431 | + predicate ?? (_) => false, |
| 432 | + ); | ||
| 424 | } | 433 | } |
| 425 | 434 | ||
| 426 | /// Show a dialog | 435 | /// Show a dialog |
| @@ -438,12 +447,11 @@ extension GetNavigation on GetInterface { | @@ -438,12 +447,11 @@ extension GetNavigation on GetInterface { | ||
| 438 | assert(useRootNavigator != null); | 447 | assert(useRootNavigator != null); |
| 439 | assert(debugCheckHasMaterialLocalizations(context)); | 448 | assert(debugCheckHasMaterialLocalizations(context)); |
| 440 | 449 | ||
| 441 | - final ThemeData theme = Theme.of(context, shadowThemeOnly: true); | 450 | + final theme = Theme.of(context, shadowThemeOnly: true); |
| 442 | return generalDialog( | 451 | return generalDialog( |
| 443 | - pageBuilder: (BuildContext buildContext, Animation<double> animation, | ||
| 444 | - Animation<double> secondaryAnimation) { | ||
| 445 | - final Widget pageChild = widget; | ||
| 446 | - Widget dialog = Builder(builder: (BuildContext context) { | 452 | + pageBuilder: (buildContext, animation, secondaryAnimation) { |
| 453 | + final pageChild = widget; | ||
| 454 | + Widget dialog = Builder(builder: (context) { | ||
| 447 | return theme != null | 455 | return theme != null |
| 448 | ? Theme(data: theme, child: pageChild) | 456 | ? Theme(data: theme, child: pageChild) |
| 449 | : pageChild; | 457 | : pageChild; |
| @@ -518,8 +526,8 @@ extension GetNavigation on GetInterface { | @@ -518,8 +526,8 @@ extension GetNavigation on GetInterface { | ||
| 518 | double radius = 20.0, | 526 | double radius = 20.0, |
| 519 | List<Widget> actions, | 527 | List<Widget> actions, |
| 520 | }) { | 528 | }) { |
| 521 | - bool leanCancel = onCancel != null || textCancel != null; | ||
| 522 | - bool leanConfirm = onConfirm != null || textConfirm != null; | 529 | + var leanCancel = onCancel != null || textCancel != null; |
| 530 | + var leanConfirm = onConfirm != null || textConfirm != null; | ||
| 523 | actions ??= []; | 531 | actions ??= []; |
| 524 | 532 | ||
| 525 | if (cancel != null) { | 533 | if (cancel != null) { |
| @@ -632,8 +640,8 @@ extension GetNavigation on GetInterface { | @@ -632,8 +640,8 @@ extension GetNavigation on GetInterface { | ||
| 632 | )); | 640 | )); |
| 633 | } | 641 | } |
| 634 | 642 | ||
| 635 | - void rawSnackbar( | ||
| 636 | - {String title, | 643 | + void rawSnackbar({ |
| 644 | + String title, | ||
| 637 | String message, | 645 | String message, |
| 638 | Widget titleText, | 646 | Widget titleText, |
| 639 | Widget messageText, | 647 | Widget messageText, |
| @@ -668,8 +676,9 @@ extension GetNavigation on GetInterface { | @@ -668,8 +676,9 @@ extension GetNavigation on GetInterface { | ||
| 668 | double barBlur = 0.0, | 676 | double barBlur = 0.0, |
| 669 | double overlayBlur = 0.0, | 677 | double overlayBlur = 0.0, |
| 670 | Color overlayColor, | 678 | Color overlayColor, |
| 671 | - Form userInputForm}) async { | ||
| 672 | - GetBar getBar = GetBar( | 679 | + Form userInputForm, |
| 680 | + }) async { | ||
| 681 | + final getBar = GetBar( | ||
| 673 | snackbarStatus: snackbarStatus, | 682 | snackbarStatus: snackbarStatus, |
| 674 | title: title, | 683 | title: title, |
| 675 | message: message, | 684 | message: message, |
| @@ -704,7 +713,8 @@ extension GetNavigation on GetInterface { | @@ -704,7 +713,8 @@ extension GetNavigation on GetInterface { | ||
| 704 | animationDuration: animationDuration, | 713 | animationDuration: animationDuration, |
| 705 | overlayBlur: overlayBlur, | 714 | overlayBlur: overlayBlur, |
| 706 | overlayColor: overlayColor, | 715 | overlayColor: overlayColor, |
| 707 | - userInputForm: userInputForm); | 716 | + userInputForm: userInputForm, |
| 717 | + ); | ||
| 708 | 718 | ||
| 709 | if (instantInit) { | 719 | if (instantInit) { |
| 710 | getBar.show(); | 720 | getBar.show(); |
| @@ -715,8 +725,10 @@ extension GetNavigation on GetInterface { | @@ -715,8 +725,10 @@ extension GetNavigation on GetInterface { | ||
| 715 | } | 725 | } |
| 716 | } | 726 | } |
| 717 | 727 | ||
| 718 | - void snackbar(String title, String message, | ||
| 719 | - {Color colorText, | 728 | + void snackbar( |
| 729 | + String title, | ||
| 730 | + String message, { | ||
| 731 | + Color colorText, | ||
| 720 | Duration duration, | 732 | Duration duration, |
| 721 | 733 | ||
| 722 | /// with instantInit = false you can put snackbar on initState | 734 | /// with instantInit = false you can put snackbar on initState |
| @@ -752,8 +764,9 @@ extension GetNavigation on GetInterface { | @@ -752,8 +764,9 @@ extension GetNavigation on GetInterface { | ||
| 752 | double overlayBlur, | 764 | double overlayBlur, |
| 753 | SnackbarStatusCallback snackbarStatus, | 765 | SnackbarStatusCallback snackbarStatus, |
| 754 | Color overlayColor, | 766 | Color overlayColor, |
| 755 | - Form userInputForm}) async { | ||
| 756 | - GetBar getBar = GetBar( | 767 | + Form userInputForm, |
| 768 | + }) async { | ||
| 769 | + final getBar = GetBar( | ||
| 757 | snackbarStatus: snackbarStatus, | 770 | snackbarStatus: snackbarStatus, |
| 758 | titleText: (title == null) | 771 | titleText: (title == null) |
| 759 | ? null | 772 | ? null |
| @@ -763,7 +776,8 @@ extension GetNavigation on GetInterface { | @@ -763,7 +776,8 @@ extension GetNavigation on GetInterface { | ||
| 763 | style: TextStyle( | 776 | style: TextStyle( |
| 764 | color: colorText ?? Colors.black, | 777 | color: colorText ?? Colors.black, |
| 765 | fontWeight: FontWeight.w800, | 778 | fontWeight: FontWeight.w800, |
| 766 | - fontSize: 16), | 779 | + fontSize: 16, |
| 780 | + ), | ||
| 767 | ), | 781 | ), |
| 768 | messageText: messageText ?? | 782 | messageText: messageText ?? |
| 769 | Text( | 783 | Text( |
| @@ -771,7 +785,8 @@ extension GetNavigation on GetInterface { | @@ -771,7 +785,8 @@ extension GetNavigation on GetInterface { | ||
| 771 | style: TextStyle( | 785 | style: TextStyle( |
| 772 | color: colorText ?? Colors.black, | 786 | color: colorText ?? Colors.black, |
| 773 | fontWeight: FontWeight.w300, | 787 | fontWeight: FontWeight.w300, |
| 774 | - fontSize: 14), | 788 | + fontSize: 14, |
| 789 | + ), | ||
| 775 | ), | 790 | ), |
| 776 | snackPosition: snackPosition ?? SnackPosition.TOP, | 791 | snackPosition: snackPosition ?? SnackPosition.TOP, |
| 777 | borderRadius: borderRadius ?? 15, | 792 | borderRadius: borderRadius ?? 15, |
| @@ -816,10 +831,13 @@ extension GetNavigation on GetInterface { | @@ -816,10 +831,13 @@ extension GetNavigation on GetInterface { | ||
| 816 | 831 | ||
| 817 | void addPages(List<GetPage> getPages) { | 832 | void addPages(List<GetPage> getPages) { |
| 818 | if (getPages != null) { | 833 | if (getPages != null) { |
| 819 | - if (routeTree == null) routeTree = ParseRouteTree(); | ||
| 820 | - getPages.forEach((element) { | 834 | + if (routeTree == null) { |
| 835 | + routeTree = ParseRouteTree(); | ||
| 836 | + } | ||
| 837 | + | ||
| 838 | + for (final element in getPages) { | ||
| 821 | routeTree.addRoute(element); | 839 | routeTree.addRoute(element); |
| 822 | - }); | 840 | + } |
| 823 | } | 841 | } |
| 824 | } | 842 | } |
| 825 | 843 | ||
| @@ -922,6 +940,8 @@ extension GetNavigation on GetInterface { | @@ -922,6 +940,8 @@ extension GetNavigation on GetInterface { | ||
| 922 | 940 | ||
| 923 | RouteSettings get routeSettings => settings; | 941 | RouteSettings get routeSettings => settings; |
| 924 | 942 | ||
| 943 | + // FIXME: wouldn't a direct set suffice here? | ||
| 944 | + // ignore: use_setters_to_change_properties | ||
| 925 | void setSettings(RouteSettings settings) { | 945 | void setSettings(RouteSettings settings) { |
| 926 | this.settings = settings; | 946 | this.settings = settings; |
| 927 | } | 947 | } |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/src/navigation/routes/get_route.dart'; | 2 | + |
| 3 | +import '../routes/get_route.dart'; | ||
| 3 | 4 | ||
| 4 | class ParseRouteTree { | 5 | class ParseRouteTree { |
| 5 | final List<_ParseRouteTreeNode> _nodes = <_ParseRouteTreeNode>[]; | 6 | final List<_ParseRouteTreeNode> _nodes = <_ParseRouteTreeNode>[]; |
| @@ -7,7 +8,7 @@ class ParseRouteTree { | @@ -7,7 +8,7 @@ class ParseRouteTree { | ||
| 7 | // bool _hasDefaultRoute = false; | 8 | // bool _hasDefaultRoute = false; |
| 8 | 9 | ||
| 9 | void addRoute(GetPage route) { | 10 | void addRoute(GetPage route) { |
| 10 | - String path = route.name; | 11 | + var path = route.name; |
| 11 | 12 | ||
| 12 | if (path == Navigator.defaultRouteName) { | 13 | if (path == Navigator.defaultRouteName) { |
| 13 | // if (_hasDefaultRoute) { | 14 | // if (_hasDefaultRoute) { |
| @@ -22,13 +23,13 @@ class ParseRouteTree { | @@ -22,13 +23,13 @@ class ParseRouteTree { | ||
| 22 | if (path.startsWith("/")) { | 23 | if (path.startsWith("/")) { |
| 23 | path = path.substring(1); | 24 | path = path.substring(1); |
| 24 | } | 25 | } |
| 25 | - List<String> pathComponents = path.split('/'); | 26 | + var pathComponents = path.split('/'); |
| 26 | _ParseRouteTreeNode parent; | 27 | _ParseRouteTreeNode parent; |
| 27 | - for (int i = 0; i < pathComponents.length; i++) { | ||
| 28 | - String component = pathComponents[i]; | ||
| 29 | - _ParseRouteTreeNode node = _nodeForComponent(component, parent); | 28 | + for (var i = 0; i < pathComponents.length; i++) { |
| 29 | + var component = pathComponents[i]; | ||
| 30 | + var node = _nodeForComponent(component, parent); | ||
| 30 | if (node == null) { | 31 | if (node == null) { |
| 31 | - _ParseRouteTreeNodeType type = _typeForComponent(component); | 32 | + var type = _typeForComponent(component); |
| 32 | node = _ParseRouteTreeNode(component, type); | 33 | node = _ParseRouteTreeNode(component, type); |
| 33 | node.parent = parent; | 34 | node.parent = parent; |
| 34 | if (parent == null) { | 35 | if (parent == null) { |
| @@ -49,7 +50,7 @@ class ParseRouteTree { | @@ -49,7 +50,7 @@ class ParseRouteTree { | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | _GetPageMatch matchRoute(String path) { | 52 | _GetPageMatch matchRoute(String path) { |
| 52 | - String usePath = path; | 53 | + var usePath = path; |
| 53 | if (usePath.startsWith("/")) { | 54 | if (usePath.startsWith("/")) { |
| 54 | usePath = path.substring(1); | 55 | usePath = path.substring(1); |
| 55 | } | 56 | } |
| @@ -57,20 +58,18 @@ class ParseRouteTree { | @@ -57,20 +58,18 @@ class ParseRouteTree { | ||
| 57 | // should take off url parameters first.. | 58 | // should take off url parameters first.. |
| 58 | final uri = Uri.tryParse(usePath); | 59 | final uri = Uri.tryParse(usePath); |
| 59 | // List<String> components = usePath.split("/"); | 60 | // List<String> components = usePath.split("/"); |
| 60 | - List<String> components = uri.pathSegments; | 61 | + var components = uri.pathSegments; |
| 61 | if (path == Navigator.defaultRouteName) { | 62 | if (path == Navigator.defaultRouteName) { |
| 62 | components = ["/"]; | 63 | components = ["/"]; |
| 63 | } | 64 | } |
| 64 | - Map<_ParseRouteTreeNode, _ParseRouteTreeNodeMatch> nodeMatches = | ||
| 65 | - <_ParseRouteTreeNode, _ParseRouteTreeNodeMatch>{}; | ||
| 66 | - List<_ParseRouteTreeNode> nodesToCheck = _nodes; | ||
| 67 | - for (String checkComponent in components) { | ||
| 68 | - Map<_ParseRouteTreeNode, _ParseRouteTreeNodeMatch> currentMatches = | ||
| 69 | - <_ParseRouteTreeNode, _ParseRouteTreeNodeMatch>{}; | ||
| 70 | - List<_ParseRouteTreeNode> nextNodes = <_ParseRouteTreeNode>[]; | ||
| 71 | - for (_ParseRouteTreeNode node in nodesToCheck) { | ||
| 72 | - String pathPart = checkComponent; | ||
| 73 | - Map<String, String> queryMap = {}; | 65 | + var nodeMatches = <_ParseRouteTreeNode, _ParseRouteTreeNodeMatch>{}; |
| 66 | + var nodesToCheck = _nodes; | ||
| 67 | + for (final checkComponent in components) { | ||
| 68 | + final currentMatches = <_ParseRouteTreeNode, _ParseRouteTreeNodeMatch>{}; | ||
| 69 | + final nextNodes = <_ParseRouteTreeNode>[]; | ||
| 70 | + for (final node in nodesToCheck) { | ||
| 71 | + var pathPart = checkComponent; | ||
| 72 | + var queryMap = <String, String>{}; | ||
| 74 | 73 | ||
| 75 | if (checkComponent.contains("?") && !checkComponent.contains("=")) { | 74 | if (checkComponent.contains("?") && !checkComponent.contains("=")) { |
| 76 | var splitParam = checkComponent.split("?"); | 75 | var splitParam = checkComponent.split("?"); |
| @@ -84,28 +83,27 @@ class ParseRouteTree { | @@ -84,28 +83,27 @@ class ParseRouteTree { | ||
| 84 | queryMap = {splitParam2[0]: splitParam2[1]}; | 83 | queryMap = {splitParam2[0]: splitParam2[1]}; |
| 85 | } else { | 84 | } else { |
| 86 | pathPart = splitParam[0]; | 85 | pathPart = splitParam[0]; |
| 87 | - final segunda = splitParam[1]; | ||
| 88 | - var other = segunda.split(RegExp(r"[&,=]")); | 86 | + final second = splitParam[1]; |
| 87 | + var other = second.split(RegExp(r"[&,=]")); | ||
| 89 | for (var i = 0; i < (other.length - 1); i++) { | 88 | for (var i = 0; i < (other.length - 1); i++) { |
| 90 | - bool impar = (i % 2 == 0); | ||
| 91 | - if (impar) { | 89 | + var isOdd = (i % 2 == 0); |
| 90 | + if (isOdd) { | ||
| 92 | queryMap.addAll({other[0 + i]: other[1 + i]}); | 91 | queryMap.addAll({other[0 + i]: other[1 + i]}); |
| 93 | } | 92 | } |
| 94 | } | 93 | } |
| 95 | } | 94 | } |
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | - bool isMatch = (node.part == pathPart || node.isParameter()); | 97 | + final isMatch = (node.part == pathPart || node.isParameter()); |
| 99 | if (isMatch) { | 98 | if (isMatch) { |
| 100 | - _ParseRouteTreeNodeMatch parentMatch = nodeMatches[node.parent]; | ||
| 101 | - _ParseRouteTreeNodeMatch match = | ||
| 102 | - _ParseRouteTreeNodeMatch.fromMatch(parentMatch, node); | 99 | + final parentMatch = nodeMatches[node.parent]; |
| 100 | + final match = _ParseRouteTreeNodeMatch.fromMatch(parentMatch, node); | ||
| 103 | 101 | ||
| 104 | // TODO: find a way to clean this implementation. | 102 | // TODO: find a way to clean this implementation. |
| 105 | match.parameters.addAll(uri.queryParameters); | 103 | match.parameters.addAll(uri.queryParameters); |
| 106 | 104 | ||
| 107 | if (node.isParameter()) { | 105 | if (node.isParameter()) { |
| 108 | - String paramKey = node.part.substring(1); | 106 | + final paramKey = node.part.substring(1); |
| 109 | match.parameters[paramKey] = pathPart; | 107 | match.parameters[paramKey] = pathPart; |
| 110 | } | 108 | } |
| 111 | if (queryMap != null) { | 109 | if (queryMap != null) { |
| @@ -124,16 +122,16 @@ class ParseRouteTree { | @@ -124,16 +122,16 @@ class ParseRouteTree { | ||
| 124 | return null; | 122 | return null; |
| 125 | } | 123 | } |
| 126 | } | 124 | } |
| 127 | - List<_ParseRouteTreeNodeMatch> matches = nodeMatches.values.toList(); | 125 | + var matches = nodeMatches.values.toList(); |
| 128 | if (matches.length > 0) { | 126 | if (matches.length > 0) { |
| 129 | - _ParseRouteTreeNodeMatch match = matches.first; | ||
| 130 | - _ParseRouteTreeNode nodeToUse = match.node; | 127 | + var match = matches.first; |
| 128 | + var nodeToUse = match.node; | ||
| 131 | 129 | ||
| 132 | if (nodeToUse != null && | 130 | if (nodeToUse != null && |
| 133 | nodeToUse.routes != null && | 131 | nodeToUse.routes != null && |
| 134 | nodeToUse.routes.length > 0) { | 132 | nodeToUse.routes.length > 0) { |
| 135 | - List<GetPage> routes = nodeToUse.routes; | ||
| 136 | - _GetPageMatch routeMatch = _GetPageMatch(routes[0]); | 133 | + var routes = nodeToUse.routes; |
| 134 | + var routeMatch = _GetPageMatch(routes[0]); | ||
| 137 | 135 | ||
| 138 | routeMatch.parameters = match.parameters; | 136 | routeMatch.parameters = match.parameters; |
| 139 | 137 | ||
| @@ -144,12 +142,14 @@ class ParseRouteTree { | @@ -144,12 +142,14 @@ class ParseRouteTree { | ||
| 144 | } | 142 | } |
| 145 | 143 | ||
| 146 | _ParseRouteTreeNode _nodeForComponent( | 144 | _ParseRouteTreeNode _nodeForComponent( |
| 147 | - String component, _ParseRouteTreeNode parent) { | ||
| 148 | - List<_ParseRouteTreeNode> nodes = _nodes; | 145 | + String component, |
| 146 | + _ParseRouteTreeNode parent, | ||
| 147 | + ) { | ||
| 148 | + var nodes = _nodes; | ||
| 149 | if (parent != null) { | 149 | if (parent != null) { |
| 150 | nodes = parent.nodes; | 150 | nodes = parent.nodes; |
| 151 | } | 151 | } |
| 152 | - for (_ParseRouteTreeNode node in nodes) { | 152 | + for (var node in nodes) { |
| 153 | if (node.part == component) { | 153 | if (node.part == component) { |
| 154 | return node; | 154 | return node; |
| 155 | } | 155 | } |
| @@ -158,7 +158,7 @@ class ParseRouteTree { | @@ -158,7 +158,7 @@ class ParseRouteTree { | ||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | _ParseRouteTreeNodeType _typeForComponent(String component) { | 160 | _ParseRouteTreeNodeType _typeForComponent(String component) { |
| 161 | - _ParseRouteTreeNodeType type = _ParseRouteTreeNodeType.component; | 161 | + var type = _ParseRouteTreeNodeType.component; |
| 162 | if (_isParameterComponent(component)) { | 162 | if (_isParameterComponent(component)) { |
| 163 | type = _ParseRouteTreeNodeType.parameter; | 163 | type = _ParseRouteTreeNodeType.parameter; |
| 164 | } | 164 | } |
| @@ -171,12 +171,13 @@ class ParseRouteTree { | @@ -171,12 +171,13 @@ class ParseRouteTree { | ||
| 171 | 171 | ||
| 172 | Map<String, String> parseQueryString(String query) { | 172 | Map<String, String> parseQueryString(String query) { |
| 173 | var search = RegExp('([^&=]+)=?([^&]*)'); | 173 | var search = RegExp('([^&=]+)=?([^&]*)'); |
| 174 | - var params = Map<String, String>(); | 174 | + var params = <String, String>{}; |
| 175 | if (query.startsWith('?')) query = query.substring(1); | 175 | if (query.startsWith('?')) query = query.substring(1); |
| 176 | decode(String s) => Uri.decodeComponent(s.replaceAll('+', ' ')); | 176 | decode(String s) => Uri.decodeComponent(s.replaceAll('+', ' ')); |
| 177 | + | ||
| 177 | for (Match match in search.allMatches(query)) { | 178 | for (Match match in search.allMatches(query)) { |
| 178 | - String key = decode(match.group(1)); | ||
| 179 | - String value = decode(match.group(2)); | 179 | + var key = decode(match.group(1)); |
| 180 | + final value = decode(match.group(2)); | ||
| 180 | params[key] = value; | 181 | params[key] = value; |
| 181 | } | 182 | } |
| 182 | return params; | 183 | return params; |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | -import 'package:get/src/state_manager/simple/get_state.dart'; | 2 | + |
| 3 | +import '../../state_manager/simple/get_state.dart'; | ||
| 3 | 4 | ||
| 4 | class GetMaterialController extends GetxController { | 5 | class GetMaterialController extends GetxController { |
| 5 | Key key; | 6 | Key key; |
| 1 | import 'package:flutter/foundation.dart'; | 1 | import 'package:flutter/foundation.dart'; |
| 2 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 3 | -import 'package:get/get.dart'; | ||
| 4 | -import 'package:get/src/core/log.dart'; | ||
| 5 | -import 'package:get/src/instance/get_instance.dart'; | ||
| 6 | -import 'package:get/src/navigation/routes/get_route.dart'; | 3 | + |
| 4 | +import '../../../get.dart'; | ||
| 5 | +import '../../core/log.dart'; | ||
| 6 | +import '../../instance/get_instance.dart'; | ||
| 7 | +import '../routes/get_route.dart'; | ||
| 7 | import 'root_controller.dart'; | 8 | import 'root_controller.dart'; |
| 8 | import 'smart_management.dart'; | 9 | import 'smart_management.dart'; |
| 9 | 10 | ||
| @@ -97,6 +98,7 @@ class GetMaterialApp extends StatelessWidget { | @@ -97,6 +98,7 @@ class GetMaterialApp extends StatelessWidget { | ||
| 97 | final bool showSemanticsDebugger; | 98 | final bool showSemanticsDebugger; |
| 98 | final bool debugShowCheckedModeBanner; | 99 | final bool debugShowCheckedModeBanner; |
| 99 | final Map<LogicalKeySet, Intent> shortcuts; | 100 | final Map<LogicalKeySet, Intent> shortcuts; |
| 101 | + | ||
| 100 | // final Map<LocalKey, ActionFactory> actions; | 102 | // final Map<LocalKey, ActionFactory> actions; |
| 101 | final bool debugShowMaterialGrid; | 103 | final bool debugShowMaterialGrid; |
| 102 | final Function(Routing) routingCallback; | 104 | final Function(Routing) routingCallback; |
| @@ -266,7 +268,8 @@ extension Trans on String { | @@ -266,7 +268,8 @@ extension Trans on String { | ||
| 266 | // Returns the key if locale is null. | 268 | // Returns the key if locale is null. |
| 267 | if (Get.locale?.languageCode == null) return this; | 269 | if (Get.locale?.languageCode == null) return this; |
| 268 | 270 | ||
| 269 | - // Checks whether the language code and country code are present, and whether the key is also present. | 271 | + // Checks whether the language code and country code are present, and |
| 272 | + // whether the key is also present. | ||
| 270 | if (Get.translations.containsKey( | 273 | if (Get.translations.containsKey( |
| 271 | "${Get.locale.languageCode}_${Get.locale.countryCode}") && | 274 | "${Get.locale.languageCode}_${Get.locale.countryCode}") && |
| 272 | Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"] | 275 | Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"] |
| @@ -274,24 +277,24 @@ extension Trans on String { | @@ -274,24 +277,24 @@ extension Trans on String { | ||
| 274 | return Get.translations[ | 277 | return Get.translations[ |
| 275 | "${Get.locale.languageCode}_${Get.locale.countryCode}"][this]; | 278 | "${Get.locale.languageCode}_${Get.locale.countryCode}"][this]; |
| 276 | 279 | ||
| 277 | - // Checks if there is a callback language in the absence of the specific country, and if it contains that key. | 280 | + // Checks if there is a callback language in the absence of the specific |
| 281 | + // country, and if it contains that key. | ||
| 278 | } else if (Get.translations.containsKey(Get.locale.languageCode) && | 282 | } else if (Get.translations.containsKey(Get.locale.languageCode) && |
| 279 | Get.translations[Get.locale.languageCode].containsKey(this)) { | 283 | Get.translations[Get.locale.languageCode].containsKey(this)) { |
| 280 | return Get.translations[Get.locale.languageCode][this]; | 284 | return Get.translations[Get.locale.languageCode][this]; |
| 281 | - // If there is no corresponding language or corresponding key, return the key. | 285 | + // If there is no corresponding language or corresponding key, return |
| 286 | + // the key. | ||
| 282 | } else if (Get.fallbackLocale != null) { | 287 | } else if (Get.fallbackLocale != null) { |
| 283 | - if (Get.translations.containsKey( | ||
| 284 | - "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}") && | ||
| 285 | - Get.translations[ | ||
| 286 | - "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | ||
| 287 | - .containsKey(this)) { | ||
| 288 | - return Get.translations[ | ||
| 289 | - "${Get.fallbackLocale.languageCode}_${Get.fallbackLocale.countryCode}"] | ||
| 290 | - [this]; | 288 | + final fallback = Get.fallbackLocale; |
| 289 | + final key = "${fallback.languageCode}_${fallback.countryCode}"; | ||
| 290 | + | ||
| 291 | + if (Get.translations.containsKey(key) && | ||
| 292 | + Get.translations[key].containsKey(this)) { | ||
| 293 | + return Get.translations[key][this]; | ||
| 291 | } | 294 | } |
| 292 | - if (Get.translations.containsKey(Get.fallbackLocale.languageCode) && | ||
| 293 | - Get.translations[Get.fallbackLocale.languageCode].containsKey(this)) { | ||
| 294 | - return Get.translations[Get.fallbackLocale.languageCode][this]; | 295 | + if (Get.translations.containsKey(fallback.languageCode) && |
| 296 | + Get.translations[fallback.languageCode].containsKey(this)) { | ||
| 297 | + return Get.translations[fallback.languageCode][this]; | ||
| 295 | } | 298 | } |
| 296 | return this; | 299 | return this; |
| 297 | } else { | 300 | } else { |
| @@ -300,11 +303,11 @@ extension Trans on String { | @@ -300,11 +303,11 @@ extension Trans on String { | ||
| 300 | } | 303 | } |
| 301 | 304 | ||
| 302 | String trArgs([List<String> args]) { | 305 | String trArgs([List<String> args]) { |
| 303 | - String key = tr; | 306 | + var key = tr; |
| 304 | if (args != null) { | 307 | if (args != null) { |
| 305 | - args.forEach((arg) { | 308 | + for (final arg in args) { |
| 306 | key = key.replaceFirst(RegExp(r'%s'), arg.toString()); | 309 | key = key.replaceFirst(RegExp(r'%s'), arg.toString()); |
| 307 | - }); | 310 | + } |
| 308 | } | 311 | } |
| 309 | return key; | 312 | return key; |
| 310 | } | 313 | } |
| 1 | -import 'package:get/get.dart'; | 1 | +import '../../../get.dart'; |
| 2 | 2 | ||
| 3 | /// [Bindings] should be extended or implemented. | 3 | /// [Bindings] should be extended or implemented. |
| 4 | -/// When using [GetMaterialApp], all [GetPage]s and navigation methods (like Get.to()) | ||
| 5 | -/// have a [binding] property that takes an instance of Bindings to manage the | 4 | +/// When using [GetMaterialApp], all [GetPage]s and navigation |
| 5 | +/// methods (like Get.to()) have a [binding] property that takes an | ||
| 6 | +/// instance of Bindings to manage the | ||
| 6 | /// dependencies() (via [Get.put()]) for the Route you are opening. | 7 | /// dependencies() (via [Get.put()]) for the Route you are opening. |
| 8 | +// ignore: one_member_abstracts | ||
| 7 | abstract class Bindings { | 9 | abstract class Bindings { |
| 8 | void dependencies(); | 10 | void dependencies(); |
| 9 | } | 11 | } |
| 1 | import 'dart:math'; | 1 | import 'dart:math'; |
| 2 | import 'dart:ui' show lerpDouble; | 2 | import 'dart:ui' show lerpDouble; |
| 3 | + | ||
| 3 | import 'package:flutter/cupertino.dart'; | 4 | import 'package:flutter/cupertino.dart'; |
| 4 | import 'package:flutter/gestures.dart'; | 5 | import 'package:flutter/gestures.dart'; |
| 5 | import 'package:flutter/material.dart'; | 6 | import 'package:flutter/material.dart'; |
| 6 | -import 'package:get/route_manager.dart'; | ||
| 7 | -import 'package:get/src/core/get_main.dart'; | ||
| 8 | -import 'package:get/src/instance/get_instance.dart'; | ||
| 9 | -import 'package:get/utils.dart'; | 7 | + |
| 8 | +import '../../../route_manager.dart'; | ||
| 9 | +import '../../../utils.dart'; | ||
| 10 | +import '../../core/get_main.dart'; | ||
| 11 | +import '../../instance/get_instance.dart'; | ||
| 10 | import 'bindings_interface.dart'; | 12 | import 'bindings_interface.dart'; |
| 11 | import 'custom_transition.dart'; | 13 | import 'custom_transition.dart'; |
| 12 | import 'default_transitions.dart'; | 14 | import 'default_transitions.dart'; |
| @@ -78,7 +80,8 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -78,7 +80,8 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 78 | 80 | ||
| 79 | @override | 81 | @override |
| 80 | bool canTransitionTo(TransitionRoute<dynamic> nextRoute) { | 82 | bool canTransitionTo(TransitionRoute<dynamic> nextRoute) { |
| 81 | - // Don't perform outgoing animation if the next route is a fullscreen dialog. | 83 | + // Don't perform outgoing animation if the next route is a |
| 84 | + // fullscreen dialog. | ||
| 82 | return nextRoute is PageRoute && !nextRoute.fullscreenDialog; | 85 | return nextRoute is PageRoute && !nextRoute.fullscreenDialog; |
| 83 | } | 86 | } |
| 84 | 87 | ||
| @@ -93,8 +96,9 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -93,8 +96,9 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 93 | 96 | ||
| 94 | if (route.animation.status != AnimationStatus.completed) return false; | 97 | if (route.animation.status != AnimationStatus.completed) return false; |
| 95 | 98 | ||
| 96 | - if (route.secondaryAnimation.status != AnimationStatus.dismissed) | 99 | + if (route.secondaryAnimation.status != AnimationStatus.dismissed) { |
| 97 | return false; | 100 | return false; |
| 101 | + } | ||
| 98 | 102 | ||
| 99 | if (isPopGestureInProgress(route)) return false; | 103 | if (isPopGestureInProgress(route)) return false; |
| 100 | 104 | ||
| @@ -112,14 +116,17 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -112,14 +116,17 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 112 | } | 116 | } |
| 113 | 117 | ||
| 114 | @override | 118 | @override |
| 115 | - Widget buildPage(BuildContext context, Animation<double> animation, | ||
| 116 | - Animation<double> secondaryAnimation) { | 119 | + Widget buildPage( |
| 120 | + BuildContext context, | ||
| 121 | + Animation<double> animation, | ||
| 122 | + Animation<double> secondaryAnimation, | ||
| 123 | + ) { | ||
| 117 | if (binding != null) { | 124 | if (binding != null) { |
| 118 | binding.dependencies(); | 125 | binding.dependencies(); |
| 119 | } | 126 | } |
| 120 | if (bindings != null) { | 127 | if (bindings != null) { |
| 121 | - for (Bindings element in bindings) { | ||
| 122 | - element.dependencies(); | 128 | + for (final binding in bindings) { |
| 129 | + binding.dependencies(); | ||
| 123 | } | 130 | } |
| 124 | } | 131 | } |
| 125 | final pageWidget = page(); | 132 | final pageWidget = page(); |
| @@ -144,8 +151,8 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -144,8 +151,8 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 144 | linearTransition: true); | 151 | linearTransition: true); |
| 145 | } | 152 | } |
| 146 | 153 | ||
| 147 | - if (this.customTransition != null) { | ||
| 148 | - return this.customTransition.buildTransition( | 154 | + if (customTransition != null) { |
| 155 | + return customTransition.buildTransition( | ||
| 149 | context, | 156 | context, |
| 150 | curve, | 157 | curve, |
| 151 | alignment, | 158 | alignment, |
| @@ -156,7 +163,8 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -156,7 +163,8 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 156 | enabledCallback: () => _isPopGestureEnabled<T>(this), | 163 | enabledCallback: () => _isPopGestureEnabled<T>(this), |
| 157 | onStartPopGesture: () => _startPopGesture<T>(this), | 164 | onStartPopGesture: () => _startPopGesture<T>(this), |
| 158 | child: child) | 165 | child: child) |
| 159 | - : child); | 166 | + : child, |
| 167 | + ); | ||
| 160 | } | 168 | } |
| 161 | 169 | ||
| 162 | switch (transition ?? Get.defaultTransition) { | 170 | switch (transition ?? Get.defaultTransition) { |
| @@ -335,7 +343,7 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -335,7 +343,7 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 335 | : child); | 343 | : child); |
| 336 | 344 | ||
| 337 | case Transition.native: | 345 | case Transition.native: |
| 338 | - if (GetPlatform.isIOS) | 346 | + if (GetPlatform.isIOS) { |
| 339 | return CupertinoTransitions().buildTransitions( | 347 | return CupertinoTransitions().buildTransitions( |
| 340 | context, | 348 | context, |
| 341 | curve, | 349 | curve, |
| @@ -348,6 +356,7 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -348,6 +356,7 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 348 | onStartPopGesture: () => _startPopGesture<T>(this), | 356 | onStartPopGesture: () => _startPopGesture<T>(this), |
| 349 | child: child) | 357 | child: child) |
| 350 | : child); | 358 | : child); |
| 359 | + } | ||
| 351 | 360 | ||
| 352 | return FadeUpwardsPageTransitionsBuilder().buildTransitions( | 361 | return FadeUpwardsPageTransitionsBuilder().buildTransitions( |
| 353 | this, | 362 | this, |
| @@ -362,7 +371,7 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -362,7 +371,7 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 362 | : child); | 371 | : child); |
| 363 | 372 | ||
| 364 | default: | 373 | default: |
| 365 | - if (GetPlatform.isIOS) | 374 | + if (GetPlatform.isIOS) { |
| 366 | return CupertinoTransitions().buildTransitions( | 375 | return CupertinoTransitions().buildTransitions( |
| 367 | context, | 376 | context, |
| 368 | curve, | 377 | curve, |
| @@ -375,6 +384,7 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -375,6 +384,7 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
| 375 | onStartPopGesture: () => _startPopGesture<T>(this), | 384 | onStartPopGesture: () => _startPopGesture<T>(this), |
| 376 | child: child) | 385 | child: child) |
| 377 | : child); | 386 | : child); |
| 387 | + } | ||
| 378 | 388 | ||
| 379 | return FadeUpwardsPageTransitionsBuilder().buildTransitions( | 389 | return FadeUpwardsPageTransitionsBuilder().buildTransitions( |
| 380 | this, | 390 | this, |
| @@ -475,8 +485,8 @@ class _CupertinoBackGestureDetectorState<T> | @@ -475,8 +485,8 @@ class _CupertinoBackGestureDetectorState<T> | ||
| 475 | 485 | ||
| 476 | void _handleDragCancel() { | 486 | void _handleDragCancel() { |
| 477 | assert(mounted); | 487 | assert(mounted); |
| 478 | - // This can be called even if start is not called, paired with the "down" event | ||
| 479 | - // that we don't consider here. | 488 | + // This can be called even if start is not called, paired with |
| 489 | + // the "down" event that we don't consider here. | ||
| 480 | _backGestureController?.dragEnd(0.0); | 490 | _backGestureController?.dragEnd(0.0); |
| 481 | _backGestureController = null; | 491 | _backGestureController = null; |
| 482 | } | 492 | } |
| @@ -492,6 +502,8 @@ class _CupertinoBackGestureDetectorState<T> | @@ -492,6 +502,8 @@ class _CupertinoBackGestureDetectorState<T> | ||
| 492 | case TextDirection.ltr: | 502 | case TextDirection.ltr: |
| 493 | return value; | 503 | return value; |
| 494 | } | 504 | } |
| 505 | + // FIXME: shouldn't we return a default here? | ||
| 506 | + // or perhaps throw error | ||
| 495 | return null; | 507 | return null; |
| 496 | } | 508 | } |
| 497 | 509 | ||
| @@ -500,7 +512,7 @@ class _CupertinoBackGestureDetectorState<T> | @@ -500,7 +512,7 @@ class _CupertinoBackGestureDetectorState<T> | ||
| 500 | assert(debugCheckHasDirectionality(context)); | 512 | assert(debugCheckHasDirectionality(context)); |
| 501 | // For devices with notches, the drag area needs to be larger on the side | 513 | // For devices with notches, the drag area needs to be larger on the side |
| 502 | // that has the notch. | 514 | // that has the notch. |
| 503 | - double dragAreaWidth = Directionality.of(context) == TextDirection.ltr | 515 | + var dragAreaWidth = Directionality.of(context) == TextDirection.ltr |
| 504 | ? MediaQuery.of(context).padding.left | 516 | ? MediaQuery.of(context).padding.left |
| 505 | : MediaQuery.of(context).padding.right; | 517 | : MediaQuery.of(context).padding.right; |
| 506 | dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth); | 518 | dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth); |
| @@ -569,10 +581,12 @@ class _CupertinoBackGestureController<T> { | @@ -569,10 +581,12 @@ class _CupertinoBackGestureController<T> { | ||
| 569 | // The closer the panel is to dismissing, the shorter the animation is. | 581 | // The closer the panel is to dismissing, the shorter the animation is. |
| 570 | // We want to cap the animation time, but we want to use a linear curve | 582 | // We want to cap the animation time, but we want to use a linear curve |
| 571 | // to determine it. | 583 | // to determine it. |
| 572 | - final int droppedPageForwardAnimationTime = min( | 584 | + final droppedPageForwardAnimationTime = min( |
| 573 | lerpDouble( | 585 | lerpDouble( |
| 574 | - _kMaxDroppedSwipePageForwardAnimationTime, 0, controller.value) | ||
| 575 | - .floor(), | 586 | + _kMaxDroppedSwipePageForwardAnimationTime, |
| 587 | + 0, | ||
| 588 | + controller.value, | ||
| 589 | + ).floor(), | ||
| 576 | _kMaxPageBackAnimationTime, | 590 | _kMaxPageBackAnimationTime, |
| 577 | ); | 591 | ); |
| 578 | controller.animateTo(1.0, | 592 | controller.animateTo(1.0, |
| @@ -582,15 +596,20 @@ class _CupertinoBackGestureController<T> { | @@ -582,15 +596,20 @@ class _CupertinoBackGestureController<T> { | ||
| 582 | // This route is destined to pop at this point. Reuse navigator's pop. | 596 | // This route is destined to pop at this point. Reuse navigator's pop. |
| 583 | navigator.pop(); | 597 | navigator.pop(); |
| 584 | 598 | ||
| 585 | - // The popping may have finished inline if already at the target destination. | 599 | + // The popping may have finished inline if already at the target |
| 600 | + // destination. | ||
| 586 | if (controller.isAnimating) { | 601 | if (controller.isAnimating) { |
| 587 | // Otherwise, use a custom popping animation duration and curve. | 602 | // Otherwise, use a custom popping animation duration and curve. |
| 588 | - final int droppedPageBackAnimationTime = lerpDouble( | ||
| 589 | - 0, _kMaxDroppedSwipePageForwardAnimationTime, controller.value) | ||
| 590 | - .floor(); | ||
| 591 | - controller.animateBack(0.0, | 603 | + final droppedPageBackAnimationTime = lerpDouble( |
| 604 | + 0, | ||
| 605 | + _kMaxDroppedSwipePageForwardAnimationTime, | ||
| 606 | + controller.value, | ||
| 607 | + ).floor(); | ||
| 608 | + controller.animateBack( | ||
| 609 | + 0.0, | ||
| 592 | duration: Duration(milliseconds: droppedPageBackAnimationTime), | 610 | duration: Duration(milliseconds: droppedPageBackAnimationTime), |
| 593 | - curve: animationCurve); | 611 | + curve: animationCurve, |
| 612 | + ); | ||
| 594 | } | 613 | } |
| 595 | } | 614 | } |
| 596 | 615 | ||
| @@ -599,7 +618,7 @@ class _CupertinoBackGestureController<T> { | @@ -599,7 +618,7 @@ class _CupertinoBackGestureController<T> { | ||
| 599 | // curve of the page transition mid-flight since CupertinoPageTransition | 618 | // curve of the page transition mid-flight since CupertinoPageTransition |
| 600 | // depends on userGestureInProgress. | 619 | // depends on userGestureInProgress. |
| 601 | AnimationStatusListener animationStatusCallback; | 620 | AnimationStatusListener animationStatusCallback; |
| 602 | - animationStatusCallback = (AnimationStatus status) { | 621 | + animationStatusCallback = (status) { |
| 603 | navigator.didStopUserGesture(); | 622 | navigator.didStopUserGesture(); |
| 604 | controller.removeStatusListener(animationStatusCallback); | 623 | controller.removeStatusListener(animationStatusCallback); |
| 605 | }; | 624 | }; |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/src/navigation/routes/bindings_interface.dart'; | 2 | + |
| 3 | +import 'bindings_interface.dart'; | ||
| 3 | import 'custom_transition.dart'; | 4 | import 'custom_transition.dart'; |
| 4 | import 'transitions_type.dart'; | 5 | import 'transitions_type.dart'; |
| 5 | 6 |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/route_manager.dart'; | ||
| 3 | -import 'package:get/src/instance/get_instance.dart'; | ||
| 4 | -import 'package:get/src/navigation/dialog/dialog_route.dart'; | ||
| 5 | -import 'package:get/src/navigation/routes/default_route.dart'; | ||
| 6 | -import 'package:get/src/navigation/snackbar/snack_route.dart'; | 2 | + |
| 3 | +import '../../../../route_manager.dart'; | ||
| 4 | +import '../../../instance/get_instance.dart'; | ||
| 5 | +import '../../dialog/dialog_route.dart'; | ||
| 6 | +import '../../snackbar/snack_route.dart'; | ||
| 7 | +import '../default_route.dart'; | ||
| 7 | 8 | ||
| 8 | class Routing { | 9 | class Routing { |
| 9 | String current; | 10 | String current; |
| @@ -15,6 +16,7 @@ class Routing { | @@ -15,6 +16,7 @@ class Routing { | ||
| 15 | bool isSnackbar; | 16 | bool isSnackbar; |
| 16 | bool isBottomSheet; | 17 | bool isBottomSheet; |
| 17 | bool isDialog; | 18 | bool isDialog; |
| 19 | + | ||
| 18 | Routing({ | 20 | Routing({ |
| 19 | this.current = '', | 21 | this.current = '', |
| 20 | this.previous = '', | 22 | this.previous = '', |
| @@ -36,6 +38,7 @@ class GetObserver extends NavigatorObserver { | @@ -36,6 +38,7 @@ class GetObserver extends NavigatorObserver { | ||
| 36 | final Function(Routing) routing; | 38 | final Function(Routing) routing; |
| 37 | 39 | ||
| 38 | GetObserver([this.routing, this._routeSend]); | 40 | GetObserver([this.routing, this._routeSend]); |
| 41 | + | ||
| 39 | final Routing _routeSend; | 42 | final Routing _routeSend; |
| 40 | 43 | ||
| 41 | Route<dynamic> route; | 44 | Route<dynamic> route; |
| @@ -46,6 +49,7 @@ class GetObserver extends NavigatorObserver { | @@ -46,6 +49,7 @@ class GetObserver extends NavigatorObserver { | ||
| 46 | String current; | 49 | String current; |
| 47 | String previous; | 50 | String previous; |
| 48 | Object args; | 51 | Object args; |
| 52 | + | ||
| 49 | // String previousArgs; | 53 | // String previousArgs; |
| 50 | String removed; | 54 | String removed; |
| 51 | 55 | ||
| @@ -65,11 +69,11 @@ class GetObserver extends NavigatorObserver { | @@ -65,11 +69,11 @@ class GetObserver extends NavigatorObserver { | ||
| 65 | 69 | ||
| 66 | @override | 70 | @override |
| 67 | void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { | 71 | void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { |
| 68 | - bool isGetPageRoute = route is GetPageRoute; | ||
| 69 | - bool isSnackbar = route is SnackRoute; | ||
| 70 | - bool isDialog = route is GetDialogRoute; | ||
| 71 | - bool isBottomSheet = route is GetModalBottomSheetRoute; | ||
| 72 | - String routeName = name(route); | 72 | + var isGetPageRoute = route is GetPageRoute; |
| 73 | + var isSnackbar = route is SnackRoute; | ||
| 74 | + var isDialog = route is GetDialogRoute; | ||
| 75 | + var isBottomSheet = route is GetModalBottomSheetRoute; | ||
| 76 | + var routeName = name(route); | ||
| 73 | 77 | ||
| 74 | if (isSnackbar) { | 78 | if (isSnackbar) { |
| 75 | GetConfig.log("OPEN SNACKBAR $routeName"); | 79 | GetConfig.log("OPEN SNACKBAR $routeName"); |
| @@ -100,11 +104,11 @@ class GetObserver extends NavigatorObserver { | @@ -100,11 +104,11 @@ class GetObserver extends NavigatorObserver { | ||
| 100 | void didPop(Route route, Route previousRoute) { | 104 | void didPop(Route route, Route previousRoute) { |
| 101 | super.didPop(route, previousRoute); | 105 | super.didPop(route, previousRoute); |
| 102 | 106 | ||
| 103 | - bool isGetPageRoute = route is GetPageRoute; | ||
| 104 | - bool isSnackbar = route is SnackRoute; | ||
| 105 | - bool isDialog = route is GetDialogRoute; | ||
| 106 | - bool isBottomSheet = route is GetModalBottomSheetRoute; | ||
| 107 | - String routeName = name(route); | 107 | + var isGetPageRoute = route is GetPageRoute; |
| 108 | + var isSnackbar = route is SnackRoute; | ||
| 109 | + var isDialog = route is GetDialogRoute; | ||
| 110 | + var isBottomSheet = route is GetModalBottomSheetRoute; | ||
| 111 | + var routeName = name(route); | ||
| 108 | 112 | ||
| 109 | if (isSnackbar) { | 113 | if (isSnackbar) { |
| 110 | GetConfig.log("CLOSE SNACKBAR $routeName"); | 114 | GetConfig.log("CLOSE SNACKBAR $routeName"); |
| @@ -118,8 +122,9 @@ class GetObserver extends NavigatorObserver { | @@ -118,8 +122,9 @@ class GetObserver extends NavigatorObserver { | ||
| 118 | GetConfig.currentRoute = routeName; | 122 | GetConfig.currentRoute = routeName; |
| 119 | 123 | ||
| 120 | _routeSend.update((value) { | 124 | _routeSend.update((value) { |
| 121 | - if (previousRoute is PageRoute) | 125 | + if (previousRoute is PageRoute) { |
| 122 | value.current = previousRoute?.settings?.name ?? ''; | 126 | value.current = previousRoute?.settings?.name ?? ''; |
| 127 | + } | ||
| 123 | value.args = route?.settings?.arguments; | 128 | value.args = route?.settings?.arguments; |
| 124 | value.route = previousRoute; | 129 | value.route = previousRoute; |
| 125 | value.isBack = true; | 130 | value.isBack = true; |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | import 'dart:ui'; | 2 | import 'dart:ui'; |
| 3 | + | ||
| 3 | import 'package:flutter/material.dart'; | 4 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter/scheduler.dart'; | 5 | import 'package:flutter/scheduler.dart'; |
| 5 | -import 'package:get/get.dart'; | 6 | + |
| 7 | +import '../../../get.dart'; | ||
| 6 | import 'snack_route.dart'; | 8 | import 'snack_route.dart'; |
| 7 | 9 | ||
| 8 | -typedef void SnackbarStatusCallback(SnackbarStatus status); | ||
| 9 | -typedef void OnTap(GetBar snack); | 10 | +typedef SnackbarStatusCallback = void Function(SnackbarStatus status); |
| 11 | +typedef OnTap = void Function(GetBar snack); | ||
| 10 | 12 | ||
| 11 | // ignore: must_be_immutable | 13 | // ignore: must_be_immutable |
| 12 | class GetBar<T extends Object> extends StatefulWidget { | 14 | class GetBar<T extends Object> extends StatefulWidget { |
| 13 | - GetBar( | ||
| 14 | - {Key key, | ||
| 15 | - String title, | ||
| 16 | - String message, | ||
| 17 | - Widget titleText, | ||
| 18 | - Widget messageText, | ||
| 19 | - Widget icon, | ||
| 20 | - bool shouldIconPulse = true, | ||
| 21 | - double maxWidth, | ||
| 22 | - EdgeInsets margin = const EdgeInsets.all(0.0), | ||
| 23 | - EdgeInsets padding = const EdgeInsets.all(16), | ||
| 24 | - double borderRadius = 0.0, | ||
| 25 | - Color borderColor, | ||
| 26 | - double borderWidth = 1.0, | ||
| 27 | - Color backgroundColor = const Color(0xFF303030), | ||
| 28 | - Color leftBarIndicatorColor, | ||
| 29 | - List<BoxShadow> boxShadows, | ||
| 30 | - Gradient backgroundGradient, | ||
| 31 | - FlatButton mainButton, | ||
| 32 | - OnTap onTap, | ||
| 33 | - Duration duration, | ||
| 34 | - bool isDismissible = true, | ||
| 35 | - SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL, | ||
| 36 | - bool showProgressIndicator = false, | ||
| 37 | - AnimationController progressIndicatorController, | ||
| 38 | - Color progressIndicatorBackgroundColor, | ||
| 39 | - Animation<Color> progressIndicatorValueColor, | ||
| 40 | - SnackPosition snackPosition = SnackPosition.BOTTOM, | ||
| 41 | - SnackStyle snackStyle = SnackStyle.FLOATING, | ||
| 42 | - Curve forwardAnimationCurve = Curves.easeOutCirc, | ||
| 43 | - Curve reverseAnimationCurve = Curves.easeOutCirc, | ||
| 44 | - Duration animationDuration = const Duration(seconds: 1), | 15 | + GetBar({ |
| 16 | + Key key, | ||
| 17 | + this.title, | ||
| 18 | + this.message, | ||
| 19 | + this.titleText, | ||
| 20 | + this.messageText, | ||
| 21 | + this.icon, | ||
| 22 | + this.shouldIconPulse = true, | ||
| 23 | + this.maxWidth, | ||
| 24 | + this.margin = const EdgeInsets.all(0.0), | ||
| 25 | + this.padding = const EdgeInsets.all(16), | ||
| 26 | + this.borderRadius = 0.0, | ||
| 27 | + this.borderColor, | ||
| 28 | + this.borderWidth = 1.0, | ||
| 29 | + this.backgroundColor = const Color(0xFF303030), | ||
| 30 | + this.leftBarIndicatorColor, | ||
| 31 | + this.boxShadows, | ||
| 32 | + this.backgroundGradient, | ||
| 33 | + this.mainButton, | ||
| 34 | + this.onTap, | ||
| 35 | + this.duration, | ||
| 36 | + this.isDismissible = true, | ||
| 37 | + this.dismissDirection = SnackDismissDirection.VERTICAL, | ||
| 38 | + this.showProgressIndicator = false, | ||
| 39 | + this.progressIndicatorController, | ||
| 40 | + this.progressIndicatorBackgroundColor, | ||
| 41 | + this.progressIndicatorValueColor, | ||
| 42 | + this.snackPosition = SnackPosition.BOTTOM, | ||
| 43 | + this.snackStyle = SnackStyle.FLOATING, | ||
| 44 | + this.forwardAnimationCurve = Curves.easeOutCirc, | ||
| 45 | + this.reverseAnimationCurve = Curves.easeOutCirc, | ||
| 46 | + this.animationDuration = const Duration(seconds: 1), | ||
| 47 | + this.barBlur = 0.0, | ||
| 48 | + this.overlayBlur = 0.0, | ||
| 49 | + this.overlayColor = Colors.transparent, | ||
| 50 | + this.userInputForm, | ||
| 45 | SnackbarStatusCallback snackbarStatus, | 51 | SnackbarStatusCallback snackbarStatus, |
| 46 | - double barBlur = 0.0, | ||
| 47 | - double overlayBlur = 0.0, | ||
| 48 | - Color overlayColor = Colors.transparent, | ||
| 49 | - Form userInputForm}) | ||
| 50 | - : this.title = title, | ||
| 51 | - this.message = message, | ||
| 52 | - this.titleText = titleText, | ||
| 53 | - this.messageText = messageText, | ||
| 54 | - this.icon = icon, | ||
| 55 | - this.shouldIconPulse = shouldIconPulse, | ||
| 56 | - this.maxWidth = maxWidth, | ||
| 57 | - this.margin = margin, | ||
| 58 | - this.padding = padding, | ||
| 59 | - this.borderRadius = borderRadius, | ||
| 60 | - this.borderColor = borderColor, | ||
| 61 | - this.borderWidth = borderWidth, | ||
| 62 | - this.backgroundColor = backgroundColor, | ||
| 63 | - this.leftBarIndicatorColor = leftBarIndicatorColor, | ||
| 64 | - this.boxShadows = boxShadows, | ||
| 65 | - this.backgroundGradient = backgroundGradient, | ||
| 66 | - this.mainButton = mainButton, | ||
| 67 | - this.onTap = onTap, | ||
| 68 | - this.duration = duration, | ||
| 69 | - this.isDismissible = isDismissible, | ||
| 70 | - this.dismissDirection = dismissDirection, | ||
| 71 | - this.showProgressIndicator = showProgressIndicator, | ||
| 72 | - this.progressIndicatorController = progressIndicatorController, | ||
| 73 | - this.progressIndicatorBackgroundColor = | ||
| 74 | - progressIndicatorBackgroundColor, | ||
| 75 | - this.progressIndicatorValueColor = progressIndicatorValueColor, | ||
| 76 | - this.snackPosition = snackPosition, | ||
| 77 | - this.snackStyle = snackStyle, | ||
| 78 | - this.forwardAnimationCurve = forwardAnimationCurve, | ||
| 79 | - this.reverseAnimationCurve = reverseAnimationCurve, | ||
| 80 | - this.animationDuration = animationDuration, | ||
| 81 | - this.barBlur = barBlur, | ||
| 82 | - this.overlayBlur = overlayBlur, | ||
| 83 | - this.overlayColor = overlayColor, | ||
| 84 | - this.userInputForm = userInputForm, | ||
| 85 | - super(key: key) { | 52 | + }) : super(key: key) { |
| 86 | this.snackbarStatus = snackbarStatus ?? (status) {}; | 53 | this.snackbarStatus = snackbarStatus ?? (status) {}; |
| 87 | } | 54 | } |
| 88 | 55 | ||
| @@ -95,20 +62,24 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -95,20 +62,24 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 95 | /// The message displayed to the user. | 62 | /// The message displayed to the user. |
| 96 | final String message; | 63 | final String message; |
| 97 | 64 | ||
| 98 | - /// Replaces [title]. Although this accepts a [Widget], it is meant to receive [Text] or [RichText] | 65 | + /// Replaces [title]. Although this accepts a [Widget], it is meant |
| 66 | + /// to receive [Text] or [RichText] | ||
| 99 | final Widget titleText; | 67 | final Widget titleText; |
| 100 | 68 | ||
| 101 | - /// Replaces [message]. Although this accepts a [Widget], it is meant to receive [Text] or [RichText] | 69 | + /// Replaces [message]. Although this accepts a [Widget], it is meant |
| 70 | + /// to receive [Text] or [RichText] | ||
| 102 | final Widget messageText; | 71 | final Widget messageText; |
| 103 | 72 | ||
| 104 | /// Will be ignored if [backgroundGradient] is not null | 73 | /// Will be ignored if [backgroundGradient] is not null |
| 105 | final Color backgroundColor; | 74 | final Color backgroundColor; |
| 106 | 75 | ||
| 107 | /// If not null, shows a left vertical colored bar on notification. | 76 | /// If not null, shows a left vertical colored bar on notification. |
| 108 | - /// It is not possible to use it with a [Form] and I do not recommend using it with [LinearProgressIndicator] | 77 | + /// It is not possible to use it with a [Form] and I do not recommend |
| 78 | + /// using it with [LinearProgressIndicator] | ||
| 109 | final Color leftBarIndicatorColor; | 79 | final Color leftBarIndicatorColor; |
| 110 | 80 | ||
| 111 | - /// [boxShadows] The shadows generated by Snack. Leave it null if you don't want a shadow. | 81 | + /// [boxShadows] The shadows generated by Snack. Leave it null |
| 82 | + /// if you don't want a shadow. | ||
| 112 | /// You can use more than one if you feel the need. | 83 | /// You can use more than one if you feel the need. |
| 113 | /// Check (this example)[https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/shadows.dart] | 84 | /// Check (this example)[https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/shadows.dart] |
| 114 | final List<BoxShadow> boxShadows; | 85 | final List<BoxShadow> boxShadows; |
| @@ -116,7 +87,8 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -116,7 +87,8 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 116 | /// Makes [backgroundColor] be ignored. | 87 | /// Makes [backgroundColor] be ignored. |
| 117 | final Gradient backgroundGradient; | 88 | final Gradient backgroundGradient; |
| 118 | 89 | ||
| 119 | - /// You can use any widget here, but I recommend [Icon] or [Image] as indication of what kind | 90 | + /// You can use any widget here, but I recommend [Icon] or [Image] as |
| 91 | + /// indication of what kind | ||
| 120 | /// of message you are displaying. Other widgets may break the layout | 92 | /// of message you are displaying. Other widgets may break the layout |
| 121 | final Widget icon; | 93 | final Widget icon; |
| 122 | 94 | ||
| @@ -126,16 +98,19 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -126,16 +98,19 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 126 | /// A [FlatButton] widget if you need an action from the user. | 98 | /// A [FlatButton] widget if you need an action from the user. |
| 127 | final FlatButton mainButton; | 99 | final FlatButton mainButton; |
| 128 | 100 | ||
| 129 | - /// A callback that registers the user's click anywhere. An alternative to [mainButton] | 101 | + /// A callback that registers the user's click anywhere. |
| 102 | + /// An alternative to [mainButton] | ||
| 130 | final OnTap onTap; | 103 | final OnTap onTap; |
| 131 | 104 | ||
| 132 | - /// How long until Snack will hide itself (be dismissed). To make it indefinite, leave it null. | 105 | + /// How long until Snack will hide itself (be dismissed). |
| 106 | + /// To make it indefinite, leave it null. | ||
| 133 | final Duration duration; | 107 | final Duration duration; |
| 134 | 108 | ||
| 135 | /// True if you want to show a [LinearProgressIndicator]. | 109 | /// True if you want to show a [LinearProgressIndicator]. |
| 136 | final bool showProgressIndicator; | 110 | final bool showProgressIndicator; |
| 137 | 111 | ||
| 138 | - /// An optional [AnimationController] when you want to control the progress of your [LinearProgressIndicator]. | 112 | + /// An optional [AnimationController] when you want to control the |
| 113 | + /// progress of your [LinearProgressIndicator]. | ||
| 139 | final AnimationController progressIndicatorController; | 114 | final AnimationController progressIndicatorController; |
| 140 | 115 | ||
| 141 | /// A [LinearProgressIndicator] configuration parameter. | 116 | /// A [LinearProgressIndicator] configuration parameter. |
| @@ -144,9 +119,11 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -144,9 +119,11 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 144 | /// A [LinearProgressIndicator] configuration parameter. | 119 | /// A [LinearProgressIndicator] configuration parameter. |
| 145 | final Animation<Color> progressIndicatorValueColor; | 120 | final Animation<Color> progressIndicatorValueColor; |
| 146 | 121 | ||
| 147 | - /// Determines if the user can swipe or click the overlay (if [overlayBlur] > 0) to dismiss. | 122 | + /// Determines if the user can swipe or click the overlay |
| 123 | + /// (if [overlayBlur] > 0) to dismiss. | ||
| 148 | /// It is recommended that you set [duration] != null if this is false. | 124 | /// It is recommended that you set [duration] != null if this is false. |
| 149 | - /// If the user swipes to dismiss or clicks the overlay, no value will be returned. | 125 | + /// If the user swipes to dismiss or clicks the overlay, no value |
| 126 | + /// will be returned. | ||
| 150 | final bool isDismissible; | 127 | final bool isDismissible; |
| 151 | 128 | ||
| 152 | /// Used to limit Snack width (usually on large screens) | 129 | /// Used to limit Snack width (usually on large screens) |
| @@ -160,33 +137,41 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -160,33 +137,41 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 160 | final EdgeInsets padding; | 137 | final EdgeInsets padding; |
| 161 | 138 | ||
| 162 | /// Adds a radius to all corners of Snack. Best combined with [margin]. | 139 | /// Adds a radius to all corners of Snack. Best combined with [margin]. |
| 163 | - /// I do not recommend using it with [showProgressIndicator] or [leftBarIndicatorColor]. | 140 | + /// I do not recommend using it with [showProgressIndicator] |
| 141 | + /// or [leftBarIndicatorColor]. | ||
| 164 | final double borderRadius; | 142 | final double borderRadius; |
| 165 | 143 | ||
| 166 | /// Adds a border to every side of Snack | 144 | /// Adds a border to every side of Snack |
| 167 | - /// I do not recommend using it with [showProgressIndicator] or [leftBarIndicatorColor]. | 145 | + /// I do not recommend using it with [showProgressIndicator] |
| 146 | + /// or [leftBarIndicatorColor]. | ||
| 168 | final Color borderColor; | 147 | final Color borderColor; |
| 169 | 148 | ||
| 170 | /// Changes the width of the border if [borderColor] is specified | 149 | /// Changes the width of the border if [borderColor] is specified |
| 171 | final double borderWidth; | 150 | final double borderWidth; |
| 172 | 151 | ||
| 173 | - /// Snack can be based on [SnackPosition.TOP] or on [SnackPosition.BOTTOM] of your screen. | 152 | + /// Snack can be based on [SnackPosition.TOP] or on [SnackPosition.BOTTOM] |
| 153 | + /// of your screen. | ||
| 174 | /// [SnackPosition.BOTTOM] is the default. | 154 | /// [SnackPosition.BOTTOM] is the default. |
| 175 | final SnackPosition snackPosition; | 155 | final SnackPosition snackPosition; |
| 176 | 156 | ||
| 177 | /// [SnackDismissDirection.VERTICAL] by default. | 157 | /// [SnackDismissDirection.VERTICAL] by default. |
| 178 | - /// Can also be [SnackDismissDirection.HORIZONTAL] in which case both left and right dismiss are allowed. | 158 | + /// Can also be [SnackDismissDirection.HORIZONTAL] in which case both left |
| 159 | + /// and right dismiss are allowed. | ||
| 179 | final SnackDismissDirection dismissDirection; | 160 | final SnackDismissDirection dismissDirection; |
| 180 | 161 | ||
| 181 | /// Snack can be floating or be grounded to the edge of the screen. | 162 | /// Snack can be floating or be grounded to the edge of the screen. |
| 182 | - /// If grounded, I do not recommend using [margin] or [borderRadius]. [SnackStyle.FLOATING] is the default | ||
| 183 | - /// If grounded, I do not recommend using a [backgroundColor] with transparency or [barBlur] | 163 | + /// If grounded, I do not recommend using [margin] or [borderRadius]. |
| 164 | + /// [SnackStyle.FLOATING] is the default | ||
| 165 | + /// If grounded, I do not recommend using a [backgroundColor] with | ||
| 166 | + /// transparency or [barBlur] | ||
| 184 | final SnackStyle snackStyle; | 167 | final SnackStyle snackStyle; |
| 185 | 168 | ||
| 186 | - /// The [Curve] animation used when show() is called. [Curves.easeOut] is default | 169 | + /// The [Curve] animation used when show() is called. |
| 170 | + /// [Curves.easeOut] is default | ||
| 187 | final Curve forwardAnimationCurve; | 171 | final Curve forwardAnimationCurve; |
| 188 | 172 | ||
| 189 | - /// The [Curve] animation used when dismiss() is called. [Curves.fastOutSlowIn] is default | 173 | + /// The [Curve] animation used when dismiss() is called. |
| 174 | + /// [Curves.fastOutSlowIn] is default | ||
| 190 | final Curve reverseAnimationCurve; | 175 | final Curve reverseAnimationCurve; |
| 191 | 176 | ||
| 192 | /// Use it to speed up or slow down the animation duration | 177 | /// Use it to speed up or slow down the animation duration |
| @@ -203,15 +188,18 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -203,15 +188,18 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 203 | final double overlayBlur; | 188 | final double overlayBlur; |
| 204 | 189 | ||
| 205 | /// Default is [Colors.transparent]. Only takes effect if [overlayBlur] > 0.0. | 190 | /// Default is [Colors.transparent]. Only takes effect if [overlayBlur] > 0.0. |
| 206 | - /// Make sure you use a color with transparency here e.g. Colors.grey[600].withOpacity(0.2). | 191 | + /// Make sure you use a color with transparency here e.g. |
| 192 | + /// Colors.grey[600].withOpacity(0.2). | ||
| 207 | final Color overlayColor; | 193 | final Color overlayColor; |
| 208 | 194 | ||
| 209 | - /// A [TextFormField] in case you want a simple user input. Every other widget is ignored if this is not null. | 195 | + /// A [TextFormField] in case you want a simple user input. |
| 196 | + /// Every other widget is ignored if this is not null. | ||
| 210 | final Form userInputForm; | 197 | final Form userInputForm; |
| 211 | 198 | ||
| 212 | SnackRoute<T> _snackRoute; | 199 | SnackRoute<T> _snackRoute; |
| 213 | 200 | ||
| 214 | - /// Show the snack. Kicks in [SnackbarStatus.OPENING] state followed by [SnackbarStatus.OPEN] | 201 | + /// Show the snack. Kicks in [SnackbarStatus.OPENING] state |
| 202 | + /// followed by [SnackbarStatus.OPEN] | ||
| 215 | Future<T> show() async { | 203 | Future<T> show() async { |
| 216 | _snackRoute = showSnack<T>( | 204 | _snackRoute = showSnack<T>( |
| 217 | snack: this, | 205 | snack: this, |
| @@ -231,9 +219,12 @@ class GetBar<T extends Object> extends StatefulWidget { | @@ -231,9 +219,12 @@ class GetBar<T extends Object> extends StatefulWidget { | ||
| 231 | _snackRoute.navigator.pop(result); | 219 | _snackRoute.navigator.pop(result); |
| 232 | return _snackRoute.completed; | 220 | return _snackRoute.completed; |
| 233 | } else if (_snackRoute.isActive) { | 221 | } else if (_snackRoute.isActive) { |
| 234 | - // removeRoute is called every time you dismiss a Snack that is not the top route. | ||
| 235 | - // It will not animate back and listeners will not detect SnackbarStatus.CLOSING or SnackbarStatus.CLOSED | ||
| 236 | - // To avoid this, always make sure that Snack is the top route when it is being dismissed | 222 | + // removeRoute is called every time you dismiss a Snack that is not |
| 223 | + // the top route. | ||
| 224 | + // It will not animate back and listeners will not detect | ||
| 225 | + // SnackbarStatus.CLOSING or SnackbarStatus.CLOSED | ||
| 226 | + // To avoid this, always make sure that Snack is the top | ||
| 227 | + // route when it is being dismissed | ||
| 237 | _snackRoute.navigator.removeRoute(_snackRoute); | 228 | _snackRoute.navigator.removeRoute(_snackRoute); |
| 238 | } | 229 | } |
| 239 | 230 | ||
| @@ -283,6 +274,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -283,6 +274,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 283 | ((widget.userInputForm != null || | 274 | ((widget.userInputForm != null || |
| 284 | ((widget.message != null && widget.message.isNotEmpty) || | 275 | ((widget.message != null && widget.message.isNotEmpty) || |
| 285 | widget.messageText != null))), | 276 | widget.messageText != null))), |
| 277 | + // ignore: lines_longer_than_80_chars | ||
| 286 | "A message is mandatory if you are not using userInputForm. Set either a message or messageText"); | 278 | "A message is mandatory if you are not using userInputForm. Set either a message or messageText"); |
| 287 | 279 | ||
| 288 | _isTitlePresent = (widget.title != null || widget.titleText != null); | 280 | _isTitlePresent = (widget.title != null || widget.titleText != null); |
| @@ -320,7 +312,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -320,7 +312,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 320 | final keyContext = backgroundBoxKey.currentContext; | 312 | final keyContext = backgroundBoxKey.currentContext; |
| 321 | 313 | ||
| 322 | if (keyContext != null) { | 314 | if (keyContext != null) { |
| 323 | - final RenderBox box = keyContext.findRenderObject(); | 315 | + final box = keyContext.findRenderObject() as RenderBox; |
| 324 | _boxHeightCompleter.complete(box.size); | 316 | _boxHeightCompleter.complete(box.size); |
| 325 | } | 317 | } |
| 326 | }, | 318 | }, |
| @@ -349,7 +341,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -349,7 +341,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 349 | _fadeController.forward(); | 341 | _fadeController.forward(); |
| 350 | } | 342 | } |
| 351 | 343 | ||
| 352 | - Function _progressListener; | 344 | + VoidCallback _progressListener; |
| 353 | 345 | ||
| 354 | void _configureProgressIndicatorAnimation() { | 346 | void _configureProgressIndicatorAnimation() { |
| 355 | if (widget.showProgressIndicator && | 347 | if (widget.showProgressIndicator && |
| @@ -403,9 +395,9 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -403,9 +395,9 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 403 | 395 | ||
| 404 | return Stack( | 396 | return Stack( |
| 405 | children: [ | 397 | children: [ |
| 406 | - FutureBuilder( | 398 | + FutureBuilder<Size>( |
| 407 | future: _boxHeightCompleter.future, | 399 | future: _boxHeightCompleter.future, |
| 408 | - builder: (context, AsyncSnapshot<Size> snapshot) { | 400 | + builder: (context, snapshot) { |
| 409 | if (snapshot.hasData) { | 401 | if (snapshot.hasData) { |
| 410 | return ClipRRect( | 402 | return ClipRRect( |
| 411 | borderRadius: BorderRadius.circular(widget.borderRadius), | 403 | borderRadius: BorderRadius.circular(widget.borderRadius), |
| @@ -500,7 +492,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -500,7 +492,7 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 500 | 492 | ||
| 501 | List<Widget> _getAppropriateRowLayout() { | 493 | List<Widget> _getAppropriateRowLayout() { |
| 502 | double buttonRightPadding; | 494 | double buttonRightPadding; |
| 503 | - double iconPadding = 0; | 495 | + var iconPadding = 0.0; |
| 504 | if (widget.padding.right - 12 < 0) { | 496 | if (widget.padding.right - 12 < 0) { |
| 505 | buttonRightPadding = 4; | 497 | buttonRightPadding = 4; |
| 506 | } else { | 498 | } else { |
| @@ -661,9 +653,9 @@ class _GetBarState<K extends Object> extends State<GetBar> | @@ -661,9 +653,9 @@ class _GetBarState<K extends Object> extends State<GetBar> | ||
| 661 | 653 | ||
| 662 | Widget _buildLeftBarIndicator() { | 654 | Widget _buildLeftBarIndicator() { |
| 663 | if (widget.leftBarIndicatorColor != null) { | 655 | if (widget.leftBarIndicatorColor != null) { |
| 664 | - return FutureBuilder( | 656 | + return FutureBuilder<Size>( |
| 665 | future: _boxHeightCompleter.future, | 657 | future: _boxHeightCompleter.future, |
| 666 | - builder: (BuildContext buildContext, AsyncSnapshot<Size> snapshot) { | 658 | + builder: (buildContext, snapshot) { |
| 667 | if (snapshot.hasData) { | 659 | if (snapshot.hasData) { |
| 668 | return Container( | 660 | return Container( |
| 669 | color: widget.leftBarIndicatorColor, | 661 | color: widget.leftBarIndicatorColor, |
| @@ -733,8 +725,11 @@ enum SnackStyle { FLOATING, GROUNDED } | @@ -733,8 +725,11 @@ enum SnackStyle { FLOATING, GROUNDED } | ||
| 733 | enum SnackDismissDirection { HORIZONTAL, VERTICAL } | 725 | enum SnackDismissDirection { HORIZONTAL, VERTICAL } |
| 734 | 726 | ||
| 735 | /// Indicates Status of snackbar | 727 | /// Indicates Status of snackbar |
| 736 | -/// [SnackbarStatus.OPEN] Snack is fully open, [SnackbarStatus.CLOSED] Snackbar has closed, | ||
| 737 | -/// [SnackbarStatus.OPENING] Starts with the opening animation and ends with the full | ||
| 738 | -/// snackbar display, [SnackbarStatus.CLOSING] Starts with the closing animation and ends | 728 | +/// [SnackbarStatus.OPEN] Snack is fully open, [SnackbarStatus.CLOSED] Snackbar |
| 729 | +/// has closed, | ||
| 730 | +/// [SnackbarStatus.OPENING] Starts with the opening animation and ends | ||
| 731 | +/// with the full | ||
| 732 | +/// snackbar display, [SnackbarStatus.CLOSING] Starts with the closing animation | ||
| 733 | +/// and ends | ||
| 739 | /// with the full snackbar dispose | 734 | /// with the full snackbar dispose |
| 740 | enum SnackbarStatus { OPEN, CLOSED, OPENING, CLOSING } | 735 | enum SnackbarStatus { OPEN, CLOSED, OPENING, CLOSING } |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | import 'dart:ui'; | 2 | import 'dart:ui'; |
| 3 | + | ||
| 3 | import 'package:flutter/widgets.dart'; | 4 | import 'package:flutter/widgets.dart'; |
| 5 | + | ||
| 4 | import 'snack.dart'; | 6 | import 'snack.dart'; |
| 5 | 7 | ||
| 6 | class SnackRoute<T> extends OverlayRoute<T> { | 8 | class SnackRoute<T> extends OverlayRoute<T> { |
| @@ -11,14 +13,14 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -11,14 +13,14 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 11 | @required this.snack, | 13 | @required this.snack, |
| 12 | RouteSettings settings, | 14 | RouteSettings settings, |
| 13 | }) : super(settings: settings) { | 15 | }) : super(settings: settings) { |
| 14 | - this._builder = Builder(builder: (BuildContext innerContext) { | 16 | + _builder = Builder(builder: (innerContext) { |
| 15 | return GestureDetector( | 17 | return GestureDetector( |
| 16 | child: snack, | 18 | child: snack, |
| 17 | onTap: snack.onTap != null ? () => snack.onTap(snack) : null, | 19 | onTap: snack.onTap != null ? () => snack.onTap(snack) : null, |
| 18 | ); | 20 | ); |
| 19 | }); | 21 | }); |
| 20 | 22 | ||
| 21 | - _configureAlignment(this.snack.snackPosition); | 23 | + _configureAlignment(snack.snackPosition); |
| 22 | _snackbarStatus = snack.snackbarStatus; | 24 | _snackbarStatus = snack.snackbarStatus; |
| 23 | } | 25 | } |
| 24 | 26 | ||
| @@ -56,12 +58,12 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -56,12 +58,12 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 56 | 58 | ||
| 57 | @override | 59 | @override |
| 58 | Iterable<OverlayEntry> createOverlayEntries() { | 60 | Iterable<OverlayEntry> createOverlayEntries() { |
| 59 | - List<OverlayEntry> overlays = []; | 61 | + var overlays = <OverlayEntry>[]; |
| 60 | 62 | ||
| 61 | if (snack.overlayBlur > 0.0) { | 63 | if (snack.overlayBlur > 0.0) { |
| 62 | overlays.add( | 64 | overlays.add( |
| 63 | OverlayEntry( | 65 | OverlayEntry( |
| 64 | - builder: (BuildContext context) { | 66 | + builder: (context) { |
| 65 | return GestureDetector( | 67 | return GestureDetector( |
| 66 | onTap: snack.isDismissible ? () => snack.dismiss() : null, | 68 | onTap: snack.isDismissible ? () => snack.dismiss() : null, |
| 67 | child: AnimatedBuilder( | 69 | child: AnimatedBuilder( |
| @@ -81,13 +83,14 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -81,13 +83,14 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 81 | ); | 83 | ); |
| 82 | }, | 84 | }, |
| 83 | maintainState: false, | 85 | maintainState: false, |
| 84 | - opaque: opaque), | 86 | + opaque: opaque, |
| 87 | + ), | ||
| 85 | ); | 88 | ); |
| 86 | } | 89 | } |
| 87 | 90 | ||
| 88 | overlays.add( | 91 | overlays.add( |
| 89 | OverlayEntry( | 92 | OverlayEntry( |
| 90 | - builder: (BuildContext context) { | 93 | + builder: (context) { |
| 91 | final Widget annotatedChild = Semantics( | 94 | final Widget annotatedChild = Semantics( |
| 92 | child: AlignTransition( | 95 | child: AlignTransition( |
| 93 | alignment: _animation, | 96 | alignment: _animation, |
| @@ -102,7 +105,8 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -102,7 +105,8 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 102 | return annotatedChild; | 105 | return annotatedChild; |
| 103 | }, | 106 | }, |
| 104 | maintainState: false, | 107 | maintainState: false, |
| 105 | - opaque: opaque), | 108 | + opaque: opaque, |
| 109 | + ), | ||
| 106 | ); | 110 | ); |
| 107 | 111 | ||
| 108 | return overlays; | 112 | return overlays; |
| @@ -172,9 +176,9 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -172,9 +176,9 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 172 | AnimationController get controller => _controller; | 176 | AnimationController get controller => _controller; |
| 173 | AnimationController _controller; | 177 | AnimationController _controller; |
| 174 | 178 | ||
| 175 | - /// Called to create the animation controller that will drive the transitions to | ||
| 176 | - /// this route from the previous one, and back to the previous route from this | ||
| 177 | - /// one. | 179 | + /// Called to create the animation controller that will drive the transitions |
| 180 | + /// to this route from the previous one, and back to the previous route | ||
| 181 | + /// from this one. | ||
| 178 | AnimationController createAnimationController() { | 182 | AnimationController createAnimationController() { |
| 179 | assert(!_transitionCompleter.isCompleted, | 183 | assert(!_transitionCompleter.isCompleted, |
| 180 | 'Cannot reuse a $runtimeType after disposing it.'); | 184 | 'Cannot reuse a $runtimeType after disposing it.'); |
| @@ -286,10 +290,15 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -286,10 +290,15 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 286 | @override | 290 | @override |
| 287 | TickerFuture didPush() { | 291 | TickerFuture didPush() { |
| 288 | super.didPush(); | 292 | super.didPush(); |
| 289 | - assert(_controller != null, | ||
| 290 | - '$runtimeType.didPush called before calling install() or after calling dispose().'); | ||
| 291 | - assert(!_transitionCompleter.isCompleted, | ||
| 292 | - 'Cannot reuse a $runtimeType after disposing it.'); | 293 | + assert( |
| 294 | + _controller != null, | ||
| 295 | + // ignore: lines_longer_than_80_chars | ||
| 296 | + '$runtimeType.didPush called before calling install() or after calling dispose().', | ||
| 297 | + ); | ||
| 298 | + assert( | ||
| 299 | + !_transitionCompleter.isCompleted, | ||
| 300 | + 'Cannot reuse a $runtimeType after disposing it.', | ||
| 301 | + ); | ||
| 293 | _animation.addStatusListener(_handleStatusChanged); | 302 | _animation.addStatusListener(_handleStatusChanged); |
| 294 | _configureTimer(); | 303 | _configureTimer(); |
| 295 | return _controller.forward(); | 304 | return _controller.forward(); |
| @@ -297,21 +306,34 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -297,21 +306,34 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 297 | 306 | ||
| 298 | @override | 307 | @override |
| 299 | void didReplace(Route<dynamic> oldRoute) { | 308 | void didReplace(Route<dynamic> oldRoute) { |
| 300 | - assert(_controller != null, | ||
| 301 | - '$runtimeType.didReplace called before calling install() or after calling dispose().'); | ||
| 302 | - assert(!_transitionCompleter.isCompleted, | ||
| 303 | - 'Cannot reuse a $runtimeType after disposing it.'); | ||
| 304 | - if (oldRoute is SnackRoute) _controller.value = oldRoute._controller.value; | 309 | + assert( |
| 310 | + _controller != null, | ||
| 311 | + // ignore: lines_longer_than_80_chars | ||
| 312 | + '$runtimeType.didReplace called before calling install() or after calling dispose().', | ||
| 313 | + ); | ||
| 314 | + assert( | ||
| 315 | + !_transitionCompleter.isCompleted, | ||
| 316 | + 'Cannot reuse a $runtimeType after disposing it.', | ||
| 317 | + ); | ||
| 318 | + | ||
| 319 | + if (oldRoute is SnackRoute) { | ||
| 320 | + _controller.value = oldRoute._controller.value; | ||
| 321 | + } | ||
| 305 | _animation.addStatusListener(_handleStatusChanged); | 322 | _animation.addStatusListener(_handleStatusChanged); |
| 306 | super.didReplace(oldRoute); | 323 | super.didReplace(oldRoute); |
| 307 | } | 324 | } |
| 308 | 325 | ||
| 309 | @override | 326 | @override |
| 310 | bool didPop(T result) { | 327 | bool didPop(T result) { |
| 311 | - assert(_controller != null, | ||
| 312 | - '$runtimeType.didPop called before calling install() or after calling dispose().'); | ||
| 313 | - assert(!_transitionCompleter.isCompleted, | ||
| 314 | - 'Cannot reuse a $runtimeType after disposing it.'); | 328 | + assert( |
| 329 | + _controller != null, | ||
| 330 | + // ignore: lines_longer_than_80_chars | ||
| 331 | + '$runtimeType.didPop called before calling install() or after calling dispose().', | ||
| 332 | + ); | ||
| 333 | + assert( | ||
| 334 | + !_transitionCompleter.isCompleted, | ||
| 335 | + 'Cannot reuse a $runtimeType after disposing it.', | ||
| 336 | + ); | ||
| 315 | 337 | ||
| 316 | _result = result; | 338 | _result = result; |
| 317 | _cancelTimer(); | 339 | _cancelTimer(); |
| @@ -335,9 +357,9 @@ class SnackRoute<T> extends OverlayRoute<T> { | @@ -335,9 +357,9 @@ class SnackRoute<T> extends OverlayRoute<T> { | ||
| 335 | _timer.cancel(); | 357 | _timer.cancel(); |
| 336 | } | 358 | } |
| 337 | _timer = Timer(snack.duration, () { | 359 | _timer = Timer(snack.duration, () { |
| 338 | - if (this.isCurrent) { | 360 | + if (isCurrent) { |
| 339 | navigator.pop(); | 361 | navigator.pop(); |
| 340 | - } else if (this.isActive) { | 362 | + } else if (isActive) { |
| 341 | navigator.removeRoute(this); | 363 | navigator.removeRoute(this); |
| 342 | } | 364 | } |
| 343 | }); | 365 | }); |
| @@ -7,8 +7,7 @@ RxInterface getObs; | @@ -7,8 +7,7 @@ RxInterface getObs; | ||
| 7 | 7 | ||
| 8 | class _RxImpl<T> implements RxInterface<T> { | 8 | class _RxImpl<T> implements RxInterface<T> { |
| 9 | StreamController<T> subject = StreamController<T>.broadcast(); | 9 | StreamController<T> subject = StreamController<T>.broadcast(); |
| 10 | - HashMap<Stream<T>, StreamSubscription> _subscriptions = | ||
| 11 | - HashMap<Stream<T>, StreamSubscription>(); | 10 | + final _subscriptions = HashMap<Stream<T>, StreamSubscription>(); |
| 12 | 11 | ||
| 13 | T _value; | 12 | T _value; |
| 14 | 13 | ||
| @@ -47,8 +46,10 @@ class _RxImpl<T> implements RxInterface<T> { | @@ -47,8 +46,10 @@ class _RxImpl<T> implements RxInterface<T> { | ||
| 47 | // ), | 46 | // ), |
| 48 | ///``` | 47 | ///``` |
| 49 | T call([T v]) { | 48 | T call([T v]) { |
| 50 | - if (v != null) this.value = v; | ||
| 51 | - return this.value; | 49 | + if (v != null) { |
| 50 | + value = v; | ||
| 51 | + } | ||
| 52 | + return value; | ||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | /// Makes a direct update of [value] adding it to the Stream | 55 | /// Makes a direct update of [value] adding it to the Stream |
| @@ -73,8 +74,8 @@ class _RxImpl<T> implements RxInterface<T> { | @@ -73,8 +74,8 @@ class _RxImpl<T> implements RxInterface<T> { | ||
| 73 | subject.add(value); | 74 | subject.add(value); |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | - /// Uses a callback to update [value] internally, similar to [refresh], but provides | ||
| 77 | - /// the current value as the argument. | 77 | + /// Uses a callback to update [value] internally, similar to [refresh], |
| 78 | + /// but provides the current value as the argument. | ||
| 78 | /// Makes sense for custom Rx types (like Models). | 79 | /// Makes sense for custom Rx types (like Models). |
| 79 | /// | 80 | /// |
| 80 | /// Sample: | 81 | /// Sample: |
| @@ -105,8 +106,10 @@ class _RxImpl<T> implements RxInterface<T> { | @@ -105,8 +106,10 @@ class _RxImpl<T> implements RxInterface<T> { | ||
| 105 | 106 | ||
| 106 | dynamic toJson() => value; | 107 | dynamic toJson() => value; |
| 107 | 108 | ||
| 108 | - /// This equality override works for _RxImpl instances and the internal values. | 109 | + /// This equality override works for _RxImpl instances and the internal |
| 110 | + /// values. | ||
| 109 | @override | 111 | @override |
| 112 | + // ignore: avoid_equals_and_hash_code_on_mutable_classes | ||
| 110 | bool operator ==(dynamic o) { | 113 | bool operator ==(dynamic o) { |
| 111 | // Todo, find a common implementation for the hashCode of different Types. | 114 | // Todo, find a common implementation for the hashCode of different Types. |
| 112 | if (o is T) return _value == o; | 115 | if (o is T) return _value == o; |
| @@ -115,6 +118,7 @@ class _RxImpl<T> implements RxInterface<T> { | @@ -115,6 +118,7 @@ class _RxImpl<T> implements RxInterface<T> { | ||
| 115 | } | 118 | } |
| 116 | 119 | ||
| 117 | @override | 120 | @override |
| 121 | + // ignore: avoid_equals_and_hash_code_on_mutable_classes | ||
| 118 | int get hashCode => _value.hashCode; | 122 | int get hashCode => _value.hashCode; |
| 119 | 123 | ||
| 120 | void close() { | 124 | void close() { |
| @@ -23,6 +23,7 @@ abstract class RxInterface<T> { | @@ -23,6 +23,7 @@ abstract class RxInterface<T> { | ||
| 23 | T get value; | 23 | T get value; |
| 24 | 24 | ||
| 25 | /// Closes the stream | 25 | /// Closes the stream |
| 26 | + // FIXME: shouldn't we expose the returned future? | ||
| 26 | void close() => subject?.close(); | 27 | void close() => subject?.close(); |
| 27 | 28 | ||
| 28 | /// Calls [callback] with current value, when the value changes. | 29 | /// Calls [callback] with current value, when the value changes. |
| @@ -30,26 +31,31 @@ abstract class RxInterface<T> { | @@ -30,26 +31,31 @@ abstract class RxInterface<T> { | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | /// Unlike GetxController, which serves to control events on each of its pages, | 33 | /// Unlike GetxController, which serves to control events on each of its pages, |
| 33 | -/// GetxService is not automatically disposed (nor can be removed with Get.delete()). | ||
| 34 | -/// It is ideal for situations where, once started, that service will remain in memory, | ||
| 35 | -/// such as Auth control for example. Only way to remove it is Get.reset(). | 34 | +/// GetxService is not automatically disposed (nor can be removed with |
| 35 | +/// Get.delete()). | ||
| 36 | +/// It is ideal for situations where, once started, that service will | ||
| 37 | +/// remain in memory, such as Auth control for example. Only way to remove | ||
| 38 | +/// it is Get.reset(). | ||
| 36 | abstract class GetxService extends DisposableInterface {} | 39 | abstract class GetxService extends DisposableInterface {} |
| 37 | 40 | ||
| 38 | /// Special callable class to keep the contract of a regular method, and avoid | 41 | /// Special callable class to keep the contract of a regular method, and avoid |
| 39 | -/// overrides if you extend the class that uses it, as Dart has no final methods. | 42 | +/// overrides if you extend the class that uses it, as Dart has no final |
| 43 | +/// methods. | ||
| 40 | /// Used in [DisposableInterface] to avoid the danger of overriding onStart. | 44 | /// Used in [DisposableInterface] to avoid the danger of overriding onStart. |
| 41 | /// | 45 | /// |
| 42 | class _InternalFinalCallback<T> { | 46 | class _InternalFinalCallback<T> { |
| 43 | T Function() callback; | 47 | T Function() callback; |
| 48 | + | ||
| 44 | _InternalFinalCallback(); | 49 | _InternalFinalCallback(); |
| 50 | + | ||
| 45 | T call() => callback.call(); | 51 | T call() => callback.call(); |
| 46 | } | 52 | } |
| 47 | 53 | ||
| 48 | abstract class DisposableInterface { | 54 | abstract class DisposableInterface { |
| 49 | /// Called at the exact moment the widget is allocated in memory. | 55 | /// Called at the exact moment the widget is allocated in memory. |
| 50 | /// It uses an internal "callable" type, to avoid any @overrides in subclases. | 56 | /// It uses an internal "callable" type, to avoid any @overrides in subclases. |
| 51 | - /// This method should be internal and is required to define the lifetime cycle | ||
| 52 | - /// of the subclass. | 57 | + /// This method should be internal and is required to define the |
| 58 | + /// lifetime cycle of the subclass. | ||
| 53 | final onStart = _InternalFinalCallback<void>(); | 59 | final onStart = _InternalFinalCallback<void>(); |
| 54 | 60 | ||
| 55 | bool _initialized = false; | 61 | bool _initialized = false; |
| @@ -72,16 +78,18 @@ abstract class DisposableInterface { | @@ -72,16 +78,18 @@ abstract class DisposableInterface { | ||
| 72 | /// You might use this to initialize something for the controller. | 78 | /// You might use this to initialize something for the controller. |
| 73 | void onInit() {} | 79 | void onInit() {} |
| 74 | 80 | ||
| 75 | - /// Called 1 frame after onInit(). It is the perfect place to enter navigation events, | ||
| 76 | - /// like snackbar, dialogs, or a new route, or async request. | 81 | + /// Called 1 frame after onInit(). It is the perfect place to enter |
| 82 | + /// navigation events, like snackbar, dialogs, or a new route, or | ||
| 83 | + /// async request. | ||
| 77 | void onReady() async {} | 84 | void onReady() async {} |
| 78 | 85 | ||
| 79 | - /// Called before [onDelete] method. [onClose] might be used to dispose resources | ||
| 80 | - /// used by the controller. Like closing events, or streams before the controller is destroyed. | 86 | + /// Called before [onDelete] method. [onClose] might be used to |
| 87 | + /// dispose resources used by the controller. Like closing events, | ||
| 88 | + /// or streams before the controller is destroyed. | ||
| 81 | /// Or dispose objects that can potentially create some memory leaks, | 89 | /// Or dispose objects that can potentially create some memory leaks, |
| 82 | /// like TextEditingControllers, AnimationControllers. | 90 | /// like TextEditingControllers, AnimationControllers. |
| 83 | /// Might be useful as well to persist some data on disk. | 91 | /// Might be useful as well to persist some data on disk. |
| 84 | - void onClose() async {} | 92 | + Future onClose() async {} |
| 85 | } | 93 | } |
| 86 | 94 | ||
| 87 | /// Used like [SingleTickerProviderMixin] but only with Get Controllers. | 95 | /// Used like [SingleTickerProviderMixin] but only with Get Controllers. |
| @@ -89,7 +97,8 @@ abstract class DisposableInterface { | @@ -89,7 +97,8 @@ abstract class DisposableInterface { | ||
| 89 | /// | 97 | /// |
| 90 | /// Example: | 98 | /// Example: |
| 91 | ///``` | 99 | ///``` |
| 92 | -///class SplashController extends GetxController with SingleGetTickerProviderMixin { | 100 | +///class SplashController extends GetxController with |
| 101 | +/// SingleGetTickerProviderMixin { | ||
| 93 | /// AnimationController _ac; | 102 | /// AnimationController _ac; |
| 94 | /// | 103 | /// |
| 95 | /// @override | 104 | /// @override |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | import 'dart:math'; | 2 | import 'dart:math'; |
| 3 | + | ||
| 3 | import 'package:flutter/foundation.dart'; | 4 | import 'package:flutter/foundation.dart'; |
| 4 | 5 | ||
| 5 | import '../rx_core/rx_impl.dart'; | 6 | import '../rx_core/rx_impl.dart'; |
| @@ -28,9 +29,9 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -28,9 +29,9 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 28 | bool get isNotEmpty => value.isNotEmpty; | 29 | bool get isNotEmpty => value.isNotEmpty; |
| 29 | 30 | ||
| 30 | StreamController<List<E>> subject = StreamController<List<E>>.broadcast(); | 31 | StreamController<List<E>> subject = StreamController<List<E>>.broadcast(); |
| 31 | - Map<Stream<List<E>>, StreamSubscription> _subscriptions = Map(); | 32 | + final Map<Stream<List<E>>, StreamSubscription> _subscriptions = {}; |
| 32 | 33 | ||
| 33 | - operator []=(int index, E val) { | 34 | + void operator []=(int index, E val) { |
| 34 | _list[index] = val; | 35 | _list[index] = val; |
| 35 | subject.add(_list); | 36 | subject.add(_list); |
| 36 | } | 37 | } |
| @@ -102,7 +103,7 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -102,7 +103,7 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 102 | /// Returns whether the item was present in the list. | 103 | /// Returns whether the item was present in the list. |
| 103 | @override | 104 | @override |
| 104 | bool remove(Object item) { | 105 | bool remove(Object item) { |
| 105 | - bool hasRemoved = _list.remove(item); | 106 | + final hasRemoved = _list.remove(item); |
| 106 | if (hasRemoved) { | 107 | if (hasRemoved) { |
| 107 | subject.add(_list); | 108 | subject.add(_list); |
| 108 | } | 109 | } |
| @@ -111,14 +112,14 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -111,14 +112,14 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 111 | 112 | ||
| 112 | @override | 113 | @override |
| 113 | E removeAt(int index) { | 114 | E removeAt(int index) { |
| 114 | - E item = _list.removeAt(index); | 115 | + final item = _list.removeAt(index); |
| 115 | subject.add(_list); | 116 | subject.add(_list); |
| 116 | return item; | 117 | return item; |
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | @override | 120 | @override |
| 120 | E removeLast() { | 121 | E removeLast() { |
| 121 | - E item = _list.removeLast(); | 122 | + final item = _list.removeLast(); |
| 122 | subject.add(_list); | 123 | subject.add(_list); |
| 123 | return item; | 124 | return item; |
| 124 | } | 125 | } |
| @@ -148,7 +149,7 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -148,7 +149,7 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 148 | } | 149 | } |
| 149 | 150 | ||
| 150 | @override | 151 | @override |
| 151 | - close() { | 152 | + void close() { |
| 152 | _subscriptions.forEach((observable, subscription) { | 153 | _subscriptions.forEach((observable, subscription) { |
| 153 | subscription.cancel(); | 154 | subscription.cancel(); |
| 154 | }); | 155 | }); |
| @@ -183,16 +184,16 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -183,16 +184,16 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 183 | 184 | ||
| 184 | String get string => value.toString(); | 185 | String get string => value.toString(); |
| 185 | 186 | ||
| 186 | - addListener(Stream<List<E>> rxGetx) { | ||
| 187 | - if (_subscriptions.containsKey(rxGetx)) { | 187 | + void addListener(Stream<List<E>> rxGetX) { |
| 188 | + if (_subscriptions.containsKey(rxGetX)) { | ||
| 188 | return; | 189 | return; |
| 189 | } | 190 | } |
| 190 | - _subscriptions[rxGetx] = rxGetx.listen((data) { | 191 | + _subscriptions[rxGetX] = rxGetX.listen((data) { |
| 191 | subject.add(data); | 192 | subject.add(data); |
| 192 | }); | 193 | }); |
| 193 | } | 194 | } |
| 194 | 195 | ||
| 195 | - set value(Iterable<E> val) { | 196 | + set value(List<E> val) { |
| 196 | if (_list == val) return; | 197 | if (_list == val) return; |
| 197 | _list = val; | 198 | _list = val; |
| 198 | subject.add(_list); | 199 | subject.add(_list); |
| @@ -200,12 +201,15 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -200,12 +201,15 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 200 | 201 | ||
| 201 | Stream<List<E>> get stream => subject.stream; | 202 | Stream<List<E>> get stream => subject.stream; |
| 202 | 203 | ||
| 203 | - StreamSubscription<List<E>> listen(void Function(List<E>) onData, | ||
| 204 | - {Function onError, void Function() onDone, bool cancelOnError}) => | 204 | + StreamSubscription<List<E>> listen( |
| 205 | + void Function(List<E>) onData, { | ||
| 206 | + Function onError, | ||
| 207 | + void Function() onDone, | ||
| 208 | + bool cancelOnError, | ||
| 209 | + }) => | ||
| 205 | stream.listen(onData, onError: onError, onDone: onDone); | 210 | stream.listen(onData, onError: onError, onDone: onDone); |
| 206 | 211 | ||
| 207 | - void bindStream(Stream<Iterable<E>> stream) => | ||
| 208 | - stream.listen((va) => value = va); | 212 | + void bindStream(Stream<List<E>> stream) => stream.listen((va) => value = va); |
| 209 | 213 | ||
| 210 | @override | 214 | @override |
| 211 | E get first => value.first; | 215 | E get first => value.first; |
| @@ -426,9 +430,10 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | @@ -426,9 +430,10 @@ class RxList<E> implements List<E>, RxInterface<List<E>> { | ||
| 426 | 430 | ||
| 427 | extension ListExtension<E> on List<E> { | 431 | extension ListExtension<E> on List<E> { |
| 428 | RxList<E> get obs { | 432 | RxList<E> get obs { |
| 429 | - if (this != null) | 433 | + if (this != null) { |
| 430 | return RxList<E>(<E>[])..addAllNonNull(this); | 434 | return RxList<E>(<E>[])..addAllNonNull(this); |
| 431 | - else | 435 | + } else { |
| 432 | return RxList<E>(null); | 436 | return RxList<E>(null); |
| 433 | } | 437 | } |
| 438 | + } | ||
| 434 | } | 439 | } |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | + | ||
| 2 | import 'package:flutter/foundation.dart'; | 3 | import 'package:flutter/foundation.dart'; |
| 4 | + | ||
| 3 | import '../../../../get.dart'; | 5 | import '../../../../get.dart'; |
| 4 | import '../rx_core/rx_interface.dart'; | 6 | import '../rx_core/rx_interface.dart'; |
| 5 | import '../rx_typedefs/rx_typedefs.dart'; | 7 | import '../rx_typedefs/rx_typedefs.dart'; |
| @@ -39,11 +41,11 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | @@ -39,11 +41,11 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | ||
| 39 | } | 41 | } |
| 40 | 42 | ||
| 41 | @override | 43 | @override |
| 42 | - void addListener(Stream rxGetx) { | ||
| 43 | - if (_subscriptions.containsKey(rxGetx)) { | 44 | + void addListener(Stream<Map<K, V>> rxGetX) { |
| 45 | + if (_subscriptions.containsKey(rxGetX)) { | ||
| 44 | return; | 46 | return; |
| 45 | } | 47 | } |
| 46 | - _subscriptions[rxGetx] = rxGetx.listen((data) { | 48 | + _subscriptions[rxGetX] = rxGetX.listen((data) { |
| 47 | subject.add(data); | 49 | subject.add(data); |
| 48 | }); | 50 | }); |
| 49 | } | 51 | } |
| @@ -68,7 +70,7 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | @@ -68,7 +70,7 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | ||
| 68 | subject.add(_value); | 70 | subject.add(_value); |
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | - void addIf(condition, K key, V value) { | 73 | + void addIf(dynamic condition, K key, V value) { |
| 72 | if (condition is Condition) condition = condition(); | 74 | if (condition is Condition) condition = condition(); |
| 73 | if (condition is bool && condition) { | 75 | if (condition is bool && condition) { |
| 74 | _value[key] = value; | 76 | _value[key] = value; |
| @@ -76,7 +78,7 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | @@ -76,7 +78,7 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | ||
| 76 | } | 78 | } |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | - void addAllIf(condition, Map<K, V> values) { | 81 | + void addAllIf(dynamic condition, Map<K, V> values) { |
| 80 | if (condition is Condition) condition = condition(); | 82 | if (condition is Condition) condition = condition(); |
| 81 | if (condition is bool && condition) addAll(values); | 83 | if (condition is bool && condition) addAll(values); |
| 82 | } | 84 | } |
| @@ -185,9 +187,10 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | @@ -185,9 +187,10 @@ class RxMap<K, V> implements RxInterface<Map<K, V>>, Map<K, V> { | ||
| 185 | 187 | ||
| 186 | extension MapExtension<K, V> on Map<K, V> { | 188 | extension MapExtension<K, V> on Map<K, V> { |
| 187 | RxMap<K, V> get obs { | 189 | RxMap<K, V> get obs { |
| 188 | - if (this != null) | 190 | + if (this != null) { |
| 189 | return RxMap<K, V>(<K, V>{})..addAll(this); | 191 | return RxMap<K, V>(<K, V>{})..addAll(this); |
| 190 | - else | 192 | + } else { |
| 191 | return RxMap<K, V>(null); | 193 | return RxMap<K, V>(null); |
| 192 | } | 194 | } |
| 195 | + } | ||
| 193 | } | 196 | } |
| @@ -11,7 +11,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -11,7 +11,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 11 | _set = initial; | 11 | _set = initial; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | - RxSet<E> _set = Set<E>(); | 14 | + Set<E> _set = <E>{}; |
| 15 | 15 | ||
| 16 | @override | 16 | @override |
| 17 | Iterator<E> get iterator => value.iterator; | 17 | Iterator<E> get iterator => value.iterator; |
| @@ -27,28 +27,23 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -27,28 +27,23 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 27 | bool get isNotEmpty => value.isNotEmpty; | 27 | bool get isNotEmpty => value.isNotEmpty; |
| 28 | 28 | ||
| 29 | StreamController<Set<E>> subject = StreamController<Set<E>>.broadcast(); | 29 | StreamController<Set<E>> subject = StreamController<Set<E>>.broadcast(); |
| 30 | - Map<Stream<Set<E>>, StreamSubscription> _subscriptions = Map(); | 30 | + final Map<Stream<Set<E>>, StreamSubscription> _subscriptions = {}; |
| 31 | 31 | ||
| 32 | /// Adds [item] only if [condition] resolves to true. | 32 | /// Adds [item] only if [condition] resolves to true. |
| 33 | - void addIf(condition, E item) { | 33 | + void addIf(dynamic condition, E item) { |
| 34 | if (condition is Condition) condition = condition(); | 34 | if (condition is Condition) condition = condition(); |
| 35 | if (condition is bool && condition) add(item); | 35 | if (condition is bool && condition) add(item); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /// Adds all [items] only if [condition] resolves to true. | 38 | /// Adds all [items] only if [condition] resolves to true. |
| 39 | - void addAllIf(condition, Iterable<E> items) { | 39 | + void addAllIf(dynamic condition, Iterable<E> items) { |
| 40 | if (condition is Condition) condition = condition(); | 40 | if (condition is Condition) condition = condition(); |
| 41 | if (condition is bool && condition) addAll(items); | 41 | if (condition is bool && condition) addAll(items); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | - operator []=(int index, E val) { | ||
| 45 | - _set[index] = val; | ||
| 46 | - subject.add(_set); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | /// Special override to push() element(s) in a reactive way | 44 | /// Special override to push() element(s) in a reactive way |
| 50 | /// inside the List, | 45 | /// inside the List, |
| 51 | - RxSet<E> operator +(Iterable<E> val) { | 46 | + RxSet<E> operator +(Set<E> val) { |
| 52 | addAll(val); | 47 | addAll(val); |
| 53 | subject.add(_set); | 48 | subject.add(_set); |
| 54 | return this; | 49 | return this; |
| @@ -76,16 +71,6 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -76,16 +71,6 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 76 | if (item != null) addAll(item); | 71 | if (item != null) addAll(item); |
| 77 | } | 72 | } |
| 78 | 73 | ||
| 79 | - void insert(int index, E item) { | ||
| 80 | - _set.insert(index, item); | ||
| 81 | - subject.add(_set); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - void insertAll(int index, Iterable<E> iterable) { | ||
| 85 | - _set.insertAll(index, iterable); | ||
| 86 | - subject.add(_set); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | int get length => value.length; | 74 | int get length => value.length; |
| 90 | 75 | ||
| 91 | /// Removes an item from the list. | 76 | /// Removes an item from the list. |
| @@ -94,30 +79,13 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -94,30 +79,13 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 94 | /// | 79 | /// |
| 95 | /// Returns whether the item was present in the list. | 80 | /// Returns whether the item was present in the list. |
| 96 | bool remove(Object item) { | 81 | bool remove(Object item) { |
| 97 | - bool hasRemoved = _set.remove(item); | 82 | + var hasRemoved = _set.remove(item); |
| 98 | if (hasRemoved) { | 83 | if (hasRemoved) { |
| 99 | subject.add(_set); | 84 | subject.add(_set); |
| 100 | } | 85 | } |
| 101 | return hasRemoved; | 86 | return hasRemoved; |
| 102 | } | 87 | } |
| 103 | 88 | ||
| 104 | - E removeAt(int index) { | ||
| 105 | - E item = _set.removeAt(index); | ||
| 106 | - subject.add(_set); | ||
| 107 | - return item; | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - E removeLast() { | ||
| 111 | - E item = _set.removeLast(); | ||
| 112 | - subject.add(_set); | ||
| 113 | - return item; | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - void removeRange(int start, int end) { | ||
| 117 | - _set.removeRange(start, end); | ||
| 118 | - subject.add(_set); | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | void removeWhere(bool Function(E) test) { | 89 | void removeWhere(bool Function(E) test) { |
| 122 | _set.removeWhere(test); | 90 | _set.removeWhere(test); |
| 123 | subject.add(_set); | 91 | subject.add(_set); |
| @@ -128,12 +96,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -128,12 +96,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 128 | subject.add(_set); | 96 | subject.add(_set); |
| 129 | } | 97 | } |
| 130 | 98 | ||
| 131 | - void sort([int compare(E a, E b)]) { | ||
| 132 | - _set.sort(); | ||
| 133 | - subject.add(_set); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - close() { | 99 | + void close() { |
| 137 | _subscriptions.forEach((observable, subscription) { | 100 | _subscriptions.forEach((observable, subscription) { |
| 138 | subscription.cancel(); | 101 | subscription.cancel(); |
| 139 | }); | 102 | }); |
| @@ -168,16 +131,16 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -168,16 +131,16 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 168 | 131 | ||
| 169 | String get string => value.toString(); | 132 | String get string => value.toString(); |
| 170 | 133 | ||
| 171 | - addListener(Stream<Set<E>> rxGetx) { | ||
| 172 | - if (_subscriptions.containsKey(rxGetx)) { | 134 | + void addListener(Stream<Set<E>> rxGetX) { |
| 135 | + if (_subscriptions.containsKey(rxGetX)) { | ||
| 173 | return; | 136 | return; |
| 174 | } | 137 | } |
| 175 | - _subscriptions[rxGetx] = rxGetx.listen((data) { | 138 | + _subscriptions[rxGetX] = rxGetX.listen((data) { |
| 176 | subject.add(data); | 139 | subject.add(data); |
| 177 | }); | 140 | }); |
| 178 | } | 141 | } |
| 179 | 142 | ||
| 180 | - set value(Iterable<E> val) { | 143 | + set value(Set<E> val) { |
| 181 | if (_set == val) return; | 144 | if (_set == val) return; |
| 182 | _set = val; | 145 | _set = val; |
| 183 | subject.add(_set); | 146 | subject.add(_set); |
| @@ -189,8 +152,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -189,8 +152,7 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 189 | {Function onError, void Function() onDone, bool cancelOnError}) => | 152 | {Function onError, void Function() onDone, bool cancelOnError}) => |
| 190 | stream.listen(onData, onError: onError, onDone: onDone); | 153 | stream.listen(onData, onError: onError, onDone: onDone); |
| 191 | 154 | ||
| 192 | - void bindStream(Stream<Iterable<E>> stream) => | ||
| 193 | - stream.listen((va) => value = va); | 155 | + void bindStream(Stream<Set<E>> stream) => stream.listen((va) => value = va); |
| 194 | 156 | ||
| 195 | @override | 157 | @override |
| 196 | E get first => value.first; | 158 | E get first => value.first; |
| @@ -362,9 +324,10 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | @@ -362,9 +324,10 @@ class RxSet<E> implements Set<E>, RxInterface<Set<E>> { | ||
| 362 | 324 | ||
| 363 | extension SetExtension<E> on Set<E> { | 325 | extension SetExtension<E> on Set<E> { |
| 364 | RxSet<E> get obs { | 326 | RxSet<E> get obs { |
| 365 | - if (this != null) | 327 | + if (this != null) { |
| 366 | return RxSet<E>(<E>{})..addAllNonNull(this); | 328 | return RxSet<E>(<E>{})..addAllNonNull(this); |
| 367 | - else | 329 | + } else { |
| 368 | return RxSet<E>(null); | 330 | return RxSet<E>(null); |
| 369 | } | 331 | } |
| 332 | + } | ||
| 370 | } | 333 | } |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | 2 | ||
| 3 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
| 4 | -import 'package:get/src/instance/get_instance.dart'; | ||
| 5 | -import 'package:get/src/navigation/root/smart_management.dart'; | 4 | + |
| 5 | +import '../../../instance/get_instance.dart'; | ||
| 6 | +import '../../../navigation/root/smart_management.dart'; | ||
| 6 | import '../rx_core/rx_impl.dart'; | 7 | import '../rx_core/rx_impl.dart'; |
| 7 | import '../rx_core/rx_interface.dart'; | 8 | import '../rx_core/rx_interface.dart'; |
| 8 | 9 | ||
| 9 | class GetX<T extends DisposableInterface> extends StatefulWidget { | 10 | class GetX<T extends DisposableInterface> extends StatefulWidget { |
| 10 | final Widget Function(T) builder; | 11 | final Widget Function(T) builder; |
| 11 | final bool global; | 12 | final bool global; |
| 13 | + | ||
| 12 | // final Stream Function(T) stream; | 14 | // final Stream Function(T) stream; |
| 13 | // final StreamController Function(T) streamController; | 15 | // final StreamController Function(T) streamController; |
| 14 | final bool autoRemove; | 16 | final bool autoRemove; |
| @@ -16,6 +18,7 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -16,6 +18,7 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
| 16 | final void Function(State state) initState, dispose, didChangeDependencies; | 18 | final void Function(State state) initState, dispose, didChangeDependencies; |
| 17 | final void Function(GetX oldWidget, State state) didUpdateWidget; | 19 | final void Function(GetX oldWidget, State state) didUpdateWidget; |
| 18 | final T init; | 20 | final T init; |
| 21 | + | ||
| 19 | const GetX({ | 22 | const GetX({ |
| 20 | this.builder, | 23 | this.builder, |
| 21 | this.global = true, | 24 | this.global = true, |
| @@ -29,6 +32,7 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -29,6 +32,7 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
| 29 | this.init, | 32 | this.init, |
| 30 | // this.streamController | 33 | // this.streamController |
| 31 | }); | 34 | }); |
| 35 | + | ||
| 32 | GetImplXState<T> createState() => GetImplXState<T>(); | 36 | GetImplXState<T> createState() => GetImplXState<T>(); |
| 33 | } | 37 | } |
| 34 | 38 | ||
| @@ -41,8 +45,9 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -41,8 +45,9 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
| 41 | @override | 45 | @override |
| 42 | void initState() { | 46 | void initState() { |
| 43 | _observer = Rx(); | 47 | _observer = Rx(); |
| 44 | - bool isPrepared = GetInstance().isPrepared<T>(); | ||
| 45 | - bool isRegistered = GetInstance().isRegistered<T>(); | 48 | + var isPrepared = GetInstance().isPrepared<T>(); |
| 49 | + var isRegistered = GetInstance().isRegistered<T>(); | ||
| 50 | + | ||
| 46 | if (widget.global) { | 51 | if (widget.global) { |
| 47 | if (isPrepared) { | 52 | if (isPrepared) { |
| 48 | if (GetConfig.smartManagement != SmartManagement.keepFactory) { | 53 | if (GetConfig.smartManagement != SmartManagement.keepFactory) { |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | + | ||
| 2 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
| 3 | -import 'package:get/src/state_manager/rx/rx_core/rx_interface.dart'; | 4 | + |
| 4 | import '../rx_core/rx_impl.dart'; | 5 | import '../rx_core/rx_impl.dart'; |
| 6 | +import '../rx_core/rx_interface.dart'; | ||
| 5 | 7 | ||
| 6 | typedef WidgetCallback = Widget Function(); | 8 | typedef WidgetCallback = Widget Function(); |
| 7 | 9 | ||
| @@ -16,6 +18,7 @@ class Obx extends StatefulWidget { | @@ -16,6 +18,7 @@ class Obx extends StatefulWidget { | ||
| 16 | final WidgetCallback builder; | 18 | final WidgetCallback builder; |
| 17 | 19 | ||
| 18 | const Obx(this.builder); | 20 | const Obx(this.builder); |
| 21 | + | ||
| 19 | _ObxState createState() => _ObxState(); | 22 | _ObxState createState() => _ObxState(); |
| 20 | } | 23 | } |
| 21 | 24 | ||
| @@ -74,7 +77,8 @@ class _ObxState extends State<Obx> { | @@ -74,7 +77,8 @@ class _ObxState extends State<Obx> { | ||
| 74 | /// false.obs, | 77 | /// false.obs, |
| 75 | /// ), | 78 | /// ), |
| 76 | 79 | ||
| 77 | -// TODO: change T to a proper Rx interface, that includes the accessor for ::value | 80 | +// TODO: change T to a proper Rx interface, that includes the accessor |
| 81 | +// for ::value | ||
| 78 | class ObxValue<T extends RxInterface> extends StatefulWidget { | 82 | class ObxValue<T extends RxInterface> extends StatefulWidget { |
| 79 | final Widget Function(T) builder; | 83 | final Widget Function(T) builder; |
| 80 | final T data; | 84 | final T data; |
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | -import 'package:get/get.dart'; | 2 | + |
| 3 | +import '../../../../get.dart'; | ||
| 3 | import '../rx_core/rx_interface.dart'; | 4 | import '../rx_core/rx_interface.dart'; |
| 4 | import 'utils/debouncer.dart'; | 5 | import 'utils/debouncer.dart'; |
| 5 | 6 | ||
| @@ -16,13 +17,15 @@ Worker ever<T>(RxInterface<T> listener, Function(T) callback, | @@ -16,13 +17,15 @@ Worker ever<T>(RxInterface<T> listener, Function(T) callback, | ||
| 16 | return Worker(cancel, '[ever]'); | 17 | return Worker(cancel, '[ever]'); |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | -Worker everAll(List<RxInterface> listener, Function(dynamic) callback, | 20 | +Worker everAll(List<RxInterface> listeners, Function(dynamic) callback, |
| 20 | {bool condition = true}) { | 21 | {bool condition = true}) { |
| 21 | - List<StreamSubscription> evers = <StreamSubscription>[]; | 22 | + var evers = <StreamSubscription>[]; |
| 22 | 23 | ||
| 23 | - for (var i in listener) { | ||
| 24 | - StreamSubscription sub = i.subject.stream.listen((event) { | ||
| 25 | - if (condition) callback(event); | 24 | + for (final listener in listeners) { |
| 25 | + final sub = listener.subject.stream.listen((event) { | ||
| 26 | + if (condition) { | ||
| 27 | + callback(event); | ||
| 28 | + } | ||
| 26 | }); | 29 | }); |
| 27 | evers.add(sub); | 30 | evers.add(sub); |
| 28 | } | 31 | } |
| @@ -37,23 +40,26 @@ Worker everAll(List<RxInterface> listener, Function(dynamic) callback, | @@ -37,23 +40,26 @@ Worker everAll(List<RxInterface> listener, Function(dynamic) callback, | ||
| 37 | return Worker(cancel, '[everAll]'); | 40 | return Worker(cancel, '[everAll]'); |
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | -Worker once<T>(RxInterface<T> listener, Function(T) callback, | ||
| 41 | - {bool condition = true}) { | ||
| 42 | - StreamSubscription sub; | ||
| 43 | - int times = 0; | 43 | +Worker once<T>( |
| 44 | + RxInterface<T> listener, | ||
| 45 | + Function(T) callback, { | ||
| 46 | + bool condition = true, | ||
| 47 | +}) { | ||
| 48 | + StreamSubscription subscription; | ||
| 49 | + var times = 0; | ||
| 44 | 50 | ||
| 45 | - sub = listener.subject.stream.listen((event) { | 51 | + subscription = listener.subject.stream.listen((event) { |
| 46 | if (!condition) return null; | 52 | if (!condition) return null; |
| 47 | times++; | 53 | times++; |
| 48 | if (times < 2) { | 54 | if (times < 2) { |
| 49 | callback(event); | 55 | callback(event); |
| 50 | } else { | 56 | } else { |
| 51 | - sub.cancel(); | 57 | + subscription.cancel(); |
| 52 | } | 58 | } |
| 53 | }); | 59 | }); |
| 54 | 60 | ||
| 55 | Future<void> cancel() { | 61 | Future<void> cancel() { |
| 56 | - return sub.cancel(); | 62 | + return subscription.cancel(); |
| 57 | } | 63 | } |
| 58 | 64 | ||
| 59 | return Worker(cancel, '[once]'); | 65 | return Worker(cancel, '[once]'); |
| @@ -61,7 +67,7 @@ Worker once<T>(RxInterface<T> listener, Function(T) callback, | @@ -61,7 +67,7 @@ Worker once<T>(RxInterface<T> listener, Function(T) callback, | ||
| 61 | 67 | ||
| 62 | Worker interval<T>(RxInterface<T> listener, Function(T) callback, | 68 | Worker interval<T>(RxInterface<T> listener, Function(T) callback, |
| 63 | {Duration time, bool condition = true}) { | 69 | {Duration time, bool condition = true}) { |
| 64 | - bool debounceActive = false; | 70 | + var debounceActive = false; |
| 65 | StreamSubscription sub = listener.subject.stream.listen((event) async { | 71 | StreamSubscription sub = listener.subject.stream.listen((event) async { |
| 66 | if (debounceActive || !condition) return null; | 72 | if (debounceActive || !condition) return null; |
| 67 | debounceActive = true; | 73 | debounceActive = true; |
| 1 | import 'dart:collection'; | 1 | import 'dart:collection'; |
| 2 | 2 | ||
| 3 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
| 4 | -import 'package:get/src/instance/get_instance.dart'; | ||
| 5 | -import 'package:get/src/navigation/root/smart_management.dart'; | ||
| 6 | -import 'package:get/src/state_manager/rx/rx_core/rx_interface.dart'; | ||
| 7 | -import 'package:get/state_manager.dart'; | ||
| 8 | 4 | ||
| 5 | +import '../../../state_manager.dart'; | ||
| 6 | +import '../../instance/get_instance.dart'; | ||
| 7 | +import '../../navigation/root/smart_management.dart'; | ||
| 8 | +import '../rx/rx_core/rx_interface.dart'; | ||
| 9 | import 'simple_builder.dart'; | 9 | import 'simple_builder.dart'; |
| 10 | 10 | ||
| 11 | typedef Disposer = void Function(); | 11 | typedef Disposer = void Function(); |
| @@ -18,12 +18,19 @@ class GetxController extends DisposableInterface { | @@ -18,12 +18,19 @@ class GetxController extends DisposableInterface { | ||
| 18 | 18 | ||
| 19 | /// Update GetBuilder with update(); | 19 | /// Update GetBuilder with update(); |
| 20 | void update([List<String> ids, bool condition = true]) { | 20 | void update([List<String> ids, bool condition = true]) { |
| 21 | - if (!condition) return; | ||
| 22 | - (ids == null) | ||
| 23 | - ? _updaters.forEach((rs) => rs(() {})) | ||
| 24 | - : ids.forEach((element) { | ||
| 25 | - _updatersIds[element]?.call(() {}); | ||
| 26 | - }); | 21 | + if (!condition) { |
| 22 | + return; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + if (ids == null) { | ||
| 26 | + for (final updater in _updaters) { | ||
| 27 | + updater(() {}); | ||
| 28 | + } | ||
| 29 | + } else { | ||
| 30 | + for (final id in ids) { | ||
| 31 | + _updatersIds[id]?.call(() {}); | ||
| 32 | + } | ||
| 33 | + } | ||
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | Disposer addListener(StateSetter listener) { | 36 | Disposer addListener(StateSetter listener) { |
| @@ -53,6 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | @@ -53,6 +60,7 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | ||
| 53 | final void Function(State state) initState, dispose, didChangeDependencies; | 60 | final void Function(State state) initState, dispose, didChangeDependencies; |
| 54 | final void Function(GetBuilder oldWidget, State state) didUpdateWidget; | 61 | final void Function(GetBuilder oldWidget, State state) didUpdateWidget; |
| 55 | final T init; | 62 | final T init; |
| 63 | + | ||
| 56 | const GetBuilder({ | 64 | const GetBuilder({ |
| 57 | Key key, | 65 | Key key, |
| 58 | this.init, | 66 | this.init, |
| @@ -68,12 +76,13 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | @@ -68,12 +76,13 @@ class GetBuilder<T extends GetxController> extends StatefulWidget { | ||
| 68 | this.didUpdateWidget, | 76 | this.didUpdateWidget, |
| 69 | }) : assert(builder != null), | 77 | }) : assert(builder != null), |
| 70 | super(key: key); | 78 | super(key: key); |
| 79 | + | ||
| 71 | @override | 80 | @override |
| 72 | _GetBuilderState<T> createState() => _GetBuilderState<T>(); | 81 | _GetBuilderState<T> createState() => _GetBuilderState<T>(); |
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | 84 | class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { |
| 76 | - GetxController controller; | 85 | + T controller; |
| 77 | bool isCreator = false; | 86 | bool isCreator = false; |
| 78 | final HashSet<Disposer> disposers = HashSet<Disposer>(); | 87 | final HashSet<Disposer> disposers = HashSet<Disposer>(); |
| 79 | Disposer remove; | 88 | Disposer remove; |
| @@ -129,9 +138,9 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -129,9 +138,9 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 129 | if (remove != null) remove(); | 138 | if (remove != null) remove(); |
| 130 | } | 139 | } |
| 131 | 140 | ||
| 132 | - disposers.forEach((element) { | ||
| 133 | - element(); | ||
| 134 | - }); | 141 | + for (final disposer in disposers) { |
| 142 | + disposer(); | ||
| 143 | + } | ||
| 135 | } | 144 | } |
| 136 | 145 | ||
| 137 | @override | 146 | @override |
| @@ -157,6 +166,7 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | @@ -157,6 +166,7 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> { | ||
| 157 | /// like Rx() does with Obx(). | 166 | /// like Rx() does with Obx(). |
| 158 | class Value<T> extends GetxController { | 167 | class Value<T> extends GetxController { |
| 159 | Value([this._value]); | 168 | Value([this._value]); |
| 169 | + | ||
| 160 | T _value; | 170 | T _value; |
| 161 | 171 | ||
| 162 | T get value { | 172 | T get value { |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/src/instance/get_instance.dart'; | 2 | + |
| 3 | +import '../../instance/get_instance.dart'; | ||
| 3 | 4 | ||
| 4 | /// GetView is a great way of quickly access your Controller | 5 | /// GetView is a great way of quickly access your Controller |
| 5 | /// without having to call Get.find<AwesomeController>() yourself. | 6 | /// without having to call Get.find<AwesomeController>() yourself. |
| @@ -22,6 +23,7 @@ import 'package:get/src/instance/get_instance.dart'; | @@ -22,6 +23,7 @@ import 'package:get/src/instance/get_instance.dart'; | ||
| 22 | ///`` | 23 | ///`` |
| 23 | abstract class GetView<T> extends StatelessWidget { | 24 | abstract class GetView<T> extends StatelessWidget { |
| 24 | const GetView({Key key}) : super(key: key); | 25 | const GetView({Key key}) : super(key: key); |
| 26 | + | ||
| 25 | T get controller => GetInstance().find<T>(); | 27 | T get controller => GetInstance().find<T>(); |
| 26 | 28 | ||
| 27 | @override | 29 | @override |
| @@ -31,7 +33,7 @@ abstract class GetView<T> extends StatelessWidget { | @@ -31,7 +33,7 @@ abstract class GetView<T> extends StatelessWidget { | ||
| 31 | abstract class GetWidget<T> extends StatelessWidget { | 33 | abstract class GetWidget<T> extends StatelessWidget { |
| 32 | GetWidget({Key key}) : super(key: key); | 34 | GetWidget({Key key}) : super(key: key); |
| 33 | 35 | ||
| 34 | - final Set<T> _value = Set<T>(); | 36 | + final Set<T> _value = <T>{}; |
| 35 | 37 | ||
| 36 | T get controller { | 38 | T get controller { |
| 37 | if (_value.isEmpty) _value.add(GetInstance().find<T>()); | 39 | if (_value.isEmpty) _value.add(GetInstance().find<T>()); |
| 1 | -// import 'package:flutter/foundation.dart'; | ||
| 2 | -// import 'package:flutter/material.dart'; | ||
| 3 | -// import 'package:get/src/instance/get_instance.dart'; | ||
| 4 | -// import 'package:get/state_manager.dart'; | ||
| 5 | - | ||
| 6 | -// abstract class GetState<T> extends DisposableInterface { | 1 | +//import 'package:flutter/foundation.dart'; |
| 2 | +//import 'package:flutter/material.dart'; | ||
| 3 | +//import 'package:get/state_manager.dart'; | ||
| 4 | +// | ||
| 5 | +//import '../../instance/get_instance.dart'; | ||
| 6 | +// | ||
| 7 | +//abstract class GetState<T> extends DisposableInterface { | ||
| 7 | // GetState(this.initialValue) { | 8 | // GetState(this.initialValue) { |
| 8 | // _state = initialValue; | 9 | // _state = initialValue; |
| 9 | // } | 10 | // } |
| 10 | - | ||
| 11 | -// final Set<StateSetter> _updaters = Set<StateSetter>(); | ||
| 12 | - | 11 | +// |
| 12 | +// final Set<StateSetter> _updaters = <StateSetter>{}; | ||
| 13 | +// | ||
| 13 | // @protected | 14 | // @protected |
| 14 | // void update(T value, [bool condition = true]) { | 15 | // void update(T value, [bool condition = true]) { |
| 15 | // if (!condition) return; | 16 | // if (!condition) return; |
| 16 | // _state = value; | 17 | // _state = value; |
| 17 | // _updaters.forEach((rs) => rs(() {})); | 18 | // _updaters.forEach((rs) => rs(() {})); |
| 18 | // } | 19 | // } |
| 19 | - | 20 | +// |
| 20 | // T _state; | 21 | // T _state; |
| 21 | - | 22 | +// |
| 22 | // final T initialValue; | 23 | // final T initialValue; |
| 23 | - | 24 | +// |
| 24 | // void addListener(StateSetter value) { | 25 | // void addListener(StateSetter value) { |
| 25 | // _updaters.add(value); | 26 | // _updaters.add(value); |
| 26 | // } | 27 | // } |
| 27 | - | 28 | +// |
| 28 | // void removeListener(StateSetter value) { | 29 | // void removeListener(StateSetter value) { |
| 29 | // _updaters.add(value); | 30 | // _updaters.add(value); |
| 30 | // } | 31 | // } |
| 31 | - | 32 | +// |
| 32 | // // @protected | 33 | // // @protected |
| 33 | // T get state => _state; | 34 | // T get state => _state; |
| 34 | - | 35 | +// |
| 35 | // @protected | 36 | // @protected |
| 36 | // void updater(void fn(T value)) { | 37 | // void updater(void fn(T value)) { |
| 37 | // fn(_state); | 38 | // fn(_state); |
| 38 | // update(_state); | 39 | // update(_state); |
| 39 | // } | 40 | // } |
| 40 | -// } | ||
| 41 | - | ||
| 42 | -// class StateBuilder<T extends GetState> extends StatefulWidget { | 41 | +//} |
| 42 | +// | ||
| 43 | +//class StateBuilder<T extends GetState> extends StatefulWidget { | ||
| 43 | // final Widget Function(dynamic) builder; | 44 | // final Widget Function(dynamic) builder; |
| 44 | // final bool global; | 45 | // final bool global; |
| 45 | // final String tag; | 46 | // final String tag; |
| @@ -48,6 +49,7 @@ | @@ -48,6 +49,7 @@ | ||
| 48 | // final void Function(State state) initState, dispose, didChangeDependencies; | 49 | // final void Function(State state) initState, dispose, didChangeDependencies; |
| 49 | // final void Function(StateBuilder oldWidget, State state) didUpdateWidget; | 50 | // final void Function(StateBuilder oldWidget, State state) didUpdateWidget; |
| 50 | // final T Function() state; | 51 | // final T Function() state; |
| 52 | +// | ||
| 51 | // const StateBuilder({ | 53 | // const StateBuilder({ |
| 52 | // Key key, | 54 | // Key key, |
| 53 | // this.state, | 55 | // this.state, |
| @@ -62,14 +64,16 @@ | @@ -62,14 +64,16 @@ | ||
| 62 | // this.didUpdateWidget, | 64 | // this.didUpdateWidget, |
| 63 | // }) : assert(builder != null), | 65 | // }) : assert(builder != null), |
| 64 | // super(key: key); | 66 | // super(key: key); |
| 67 | +// | ||
| 65 | // @override | 68 | // @override |
| 66 | // _StateBuilderState<T> createState() => _StateBuilderState<T>(); | 69 | // _StateBuilderState<T> createState() => _StateBuilderState<T>(); |
| 67 | -// } | ||
| 68 | - | ||
| 69 | -// class _StateBuilderState<T extends GetState> extends State<StateBuilder<T>> { | 70 | +//} |
| 71 | +// | ||
| 72 | +//class _StateBuilderState<T extends GetState> extends State<StateBuilder<T>> { | ||
| 70 | // T controller; | 73 | // T controller; |
| 71 | - | 74 | +// |
| 72 | // bool isCreator = false; | 75 | // bool isCreator = false; |
| 76 | +// | ||
| 73 | // @override | 77 | // @override |
| 74 | // void initState() { | 78 | // void initState() { |
| 75 | // super.initState(); | 79 | // super.initState(); |
| @@ -77,7 +81,7 @@ | @@ -77,7 +81,7 @@ | ||
| 77 | // if (widget.global) { | 81 | // if (widget.global) { |
| 78 | // final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); | 82 | // final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag); |
| 79 | // final isRegistred = GetInstance().isRegistred<T>(tag: widget.tag); | 83 | // final isRegistred = GetInstance().isRegistred<T>(tag: widget.tag); |
| 80 | - | 84 | +// |
| 81 | // if (isPrepared) { | 85 | // if (isPrepared) { |
| 82 | // isCreator = true; | 86 | // isCreator = true; |
| 83 | // } else if (isRegistred) { | 87 | // } else if (isRegistred) { |
| @@ -85,12 +89,15 @@ | @@ -85,12 +89,15 @@ | ||
| 85 | // } else { | 89 | // } else { |
| 86 | // isCreator = true; | 90 | // isCreator = true; |
| 87 | // } | 91 | // } |
| 88 | - | 92 | +// |
| 89 | // if (isCreator) { | 93 | // if (isCreator) { |
| 90 | // controller?.onStart(); | 94 | // controller?.onStart(); |
| 91 | // } | 95 | // } |
| 92 | - | ||
| 93 | -// final instance = GetInstance().putOrFind(widget.state, tag: widget.tag); | 96 | +// |
| 97 | +// final instance = GetInstance().putOrFind( | ||
| 98 | +// widget.state, | ||
| 99 | +// tag: widget.tag, | ||
| 100 | +// ); | ||
| 94 | // controller = instance; | 101 | // controller = instance; |
| 95 | // controller._updaters.add(setState); | 102 | // controller._updaters.add(setState); |
| 96 | // } else { | 103 | // } else { |
| @@ -100,13 +107,16 @@ | @@ -100,13 +107,16 @@ | ||
| 100 | // controller?.onStart(); | 107 | // controller?.onStart(); |
| 101 | // } | 108 | // } |
| 102 | // } | 109 | // } |
| 103 | - | 110 | +// |
| 104 | // @override | 111 | // @override |
| 105 | // void dispose() { | 112 | // void dispose() { |
| 106 | // super.dispose(); | 113 | // super.dispose(); |
| 107 | // if (widget.dispose != null) widget.dispose(this); | 114 | // if (widget.dispose != null) widget.dispose(this); |
| 108 | // if (isCreator || widget.assignId) { | 115 | // if (isCreator || widget.assignId) { |
| 109 | -// if (widget.autoRemove && GetInstance().isRegistred<T>(tag: widget.tag)) { | 116 | +// if (widget.autoRemove && |
| 117 | +// GetInstance().isRegistred<T>( | ||
| 118 | +// tag: widget.tag, | ||
| 119 | +// )) { | ||
| 110 | // controller._updaters.remove(setState); | 120 | // controller._updaters.remove(setState); |
| 111 | // GetInstance().delete<T>(tag: widget.tag); | 121 | // GetInstance().delete<T>(tag: widget.tag); |
| 112 | // } | 122 | // } |
| @@ -114,7 +124,7 @@ | @@ -114,7 +124,7 @@ | ||
| 114 | // controller._updaters.remove(setState); | 124 | // controller._updaters.remove(setState); |
| 115 | // } | 125 | // } |
| 116 | // } | 126 | // } |
| 117 | - | 127 | +// |
| 118 | // @override | 128 | // @override |
| 119 | // void didChangeDependencies() { | 129 | // void didChangeDependencies() { |
| 120 | // super.didChangeDependencies(); | 130 | // super.didChangeDependencies(); |
| @@ -122,15 +132,17 @@ | @@ -122,15 +132,17 @@ | ||
| 122 | // widget.didChangeDependencies(this); | 132 | // widget.didChangeDependencies(this); |
| 123 | // } | 133 | // } |
| 124 | // } | 134 | // } |
| 125 | - | 135 | +// |
| 126 | // @override | 136 | // @override |
| 127 | // void didUpdateWidget(StateBuilder oldWidget) { | 137 | // void didUpdateWidget(StateBuilder oldWidget) { |
| 128 | // super.didUpdateWidget(oldWidget as StateBuilder<T>); | 138 | // super.didUpdateWidget(oldWidget as StateBuilder<T>); |
| 129 | -// if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | 139 | +// if (widget.didUpdateWidget != null) { |
| 140 | +// widget.didUpdateWidget(oldWidget, this); | ||
| 130 | // } | 141 | // } |
| 131 | - | 142 | +// } |
| 143 | +// | ||
| 132 | // @override | 144 | // @override |
| 133 | // Widget build(BuildContext context) { | 145 | // Widget build(BuildContext context) { |
| 134 | // return widget.builder(controller.state); | 146 | // return widget.builder(controller.state); |
| 135 | // } | 147 | // } |
| 136 | -// } | 148 | +//} |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | -import 'package:get/src/state_manager/rx/rx_widgets/rx_obx_widget.dart'; | 2 | + |
| 3 | +import '../rx/rx_widgets/rx_obx_widget.dart'; | ||
| 3 | import 'get_state.dart'; | 4 | import 'get_state.dart'; |
| 4 | 5 | ||
| 5 | class MixinBuilder<T extends GetxController> extends StatelessWidget { | 6 | class MixinBuilder<T extends GetxController> extends StatelessWidget { |
| @@ -11,6 +12,7 @@ class MixinBuilder<T extends GetxController> extends StatelessWidget { | @@ -11,6 +12,7 @@ class MixinBuilder<T extends GetxController> extends StatelessWidget { | ||
| 11 | final void Function(State state) initState, dispose, didChangeDependencies; | 12 | final void Function(State state) initState, dispose, didChangeDependencies; |
| 12 | final void Function(GetBuilder oldWidget, State state) didUpdateWidget; | 13 | final void Function(GetBuilder oldWidget, State state) didUpdateWidget; |
| 13 | final T init; | 14 | final T init; |
| 15 | + | ||
| 14 | const MixinBuilder({ | 16 | const MixinBuilder({ |
| 15 | Key key, | 17 | Key key, |
| 16 | this.init, | 18 | this.init, |
| @@ -9,7 +9,8 @@ typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot); | @@ -9,7 +9,8 @@ typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot); | ||
| 9 | typedef ValueBuilderBuilder<T> = Widget Function( | 9 | typedef ValueBuilderBuilder<T> = Widget Function( |
| 10 | T snapshot, ValueBuilderUpdateCallback<T> updater); | 10 | T snapshot, ValueBuilderUpdateCallback<T> updater); |
| 11 | 11 | ||
| 12 | -/// Manages a local state like ObxValue, but uses a callback instead of a Rx value. | 12 | +/// Manages a local state like ObxValue, but uses a callback instead of |
| 13 | +/// a Rx value. | ||
| 13 | /// | 14 | /// |
| 14 | /// Example: | 15 | /// Example: |
| 15 | /// ``` | 16 | /// ``` |
| @@ -25,7 +26,7 @@ typedef ValueBuilderBuilder<T> = Widget Function( | @@ -25,7 +26,7 @@ typedef ValueBuilderBuilder<T> = Widget Function( | ||
| 25 | /// ``` | 26 | /// ``` |
| 26 | class ValueBuilder<T> extends StatefulWidget { | 27 | class ValueBuilder<T> extends StatefulWidget { |
| 27 | final T initialValue; | 28 | final T initialValue; |
| 28 | - final ValueBuilderBuilder builder; | 29 | + final ValueBuilderBuilder<T> builder; |
| 29 | final void Function() onDispose; | 30 | final void Function() onDispose; |
| 30 | final void Function(T) onUpdate; | 31 | final void Function(T) onUpdate; |
| 31 | 32 | ||
| @@ -78,9 +79,11 @@ class _ValueBuilderState<T> extends State<ValueBuilder<T>> { | @@ -78,9 +79,11 @@ class _ValueBuilderState<T> extends State<ValueBuilder<T>> { | ||
| 78 | // It's a experimental feature | 79 | // It's a experimental feature |
| 79 | class SimpleBuilder extends StatefulWidget { | 80 | class SimpleBuilder extends StatefulWidget { |
| 80 | final Widget Function(BuildContext) builder; | 81 | final Widget Function(BuildContext) builder; |
| 82 | + | ||
| 81 | const SimpleBuilder({Key key, @required this.builder}) | 83 | const SimpleBuilder({Key key, @required this.builder}) |
| 82 | : assert(builder != null), | 84 | : assert(builder != null), |
| 83 | super(key: key); | 85 | super(key: key); |
| 86 | + | ||
| 84 | @override | 87 | @override |
| 85 | _SimpleBuilderState createState() => _SimpleBuilderState(); | 88 | _SimpleBuilderState createState() => _SimpleBuilderState(); |
| 86 | } | 89 | } |
| @@ -91,25 +94,33 @@ class _SimpleBuilderState extends State<SimpleBuilder> { | @@ -91,25 +94,33 @@ class _SimpleBuilderState extends State<SimpleBuilder> { | ||
| 91 | @override | 94 | @override |
| 92 | void dispose() { | 95 | void dispose() { |
| 93 | super.dispose(); | 96 | super.dispose(); |
| 94 | - disposers.forEach((element) => element()); | 97 | + for (final disposer in disposers) { |
| 98 | + disposer(); | ||
| 99 | + } | ||
| 95 | } | 100 | } |
| 96 | 101 | ||
| 97 | @override | 102 | @override |
| 98 | Widget build(BuildContext context) { | 103 | Widget build(BuildContext context) { |
| 99 | - return TaskManager.instance | ||
| 100 | - .exchange(disposers, setState, widget.builder, context); | 104 | + return TaskManager.instance.exchange( |
| 105 | + disposers, | ||
| 106 | + setState, | ||
| 107 | + widget.builder, | ||
| 108 | + context, | ||
| 109 | + ); | ||
| 101 | } | 110 | } |
| 102 | } | 111 | } |
| 103 | 112 | ||
| 104 | class TaskManager { | 113 | class TaskManager { |
| 105 | TaskManager._(); | 114 | TaskManager._(); |
| 115 | + | ||
| 106 | static TaskManager _instance; | 116 | static TaskManager _instance; |
| 117 | + | ||
| 107 | static TaskManager get instance => _instance ??= TaskManager._(); | 118 | static TaskManager get instance => _instance ??= TaskManager._(); |
| 108 | 119 | ||
| 109 | StateSetter _setter; | 120 | StateSetter _setter; |
| 110 | HashSet<Disposer> _remove; | 121 | HashSet<Disposer> _remove; |
| 111 | 122 | ||
| 112 | - notify(HashSet<StateSetter> _updaters) { | 123 | + void notify(HashSet<StateSetter> _updaters) { |
| 113 | if (_setter != null) { | 124 | if (_setter != null) { |
| 114 | if (!_updaters.contains(_setter)) { | 125 | if (!_updaters.contains(_setter)) { |
| 115 | _updaters.add(_setter); | 126 | _updaters.add(_setter); |
| 1 | +import 'package:flutter/foundation.dart'; | ||
| 1 | import 'package:flutter/material.dart'; | 2 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
| 3 | -import 'package:flutter/foundation.dart'; | ||
| 4 | 4 | ||
| 5 | extension ContextExtensionss on BuildContext { | 5 | extension ContextExtensionss on BuildContext { |
| 6 | /// The same of [MediaQuery.of(context).size] | 6 | /// The same of [MediaQuery.of(context).size] |
| 7 | Size get mediaQuerySize => MediaQuery.of(this).size; | 7 | Size get mediaQuerySize => MediaQuery.of(this).size; |
| 8 | 8 | ||
| 9 | /// The same of [MediaQuery.of(context).size.height] | 9 | /// The same of [MediaQuery.of(context).size.height] |
| 10 | - /// Note: updates when you rezise your screen (like on a browser or desktop window) | 10 | + /// Note: updates when you rezise your screen (like on a browser or |
| 11 | + /// desktop window) | ||
| 11 | double get height => mediaQuerySize.height; | 12 | double get height => mediaQuerySize.height; |
| 12 | 13 | ||
| 13 | /// The same of [MediaQuery.of(context).size.width] | 14 | /// The same of [MediaQuery.of(context).size.width] |
| 14 | - /// Note: updates when you rezise your screen (like on a browser or desktop window) | 15 | + /// Note: updates when you rezise your screen (like on a browser or |
| 16 | + /// desktop window) | ||
| 15 | double get width => mediaQuerySize.width; | 17 | double get width => mediaQuerySize.width; |
| 16 | 18 | ||
| 17 | /// Gives you the power to get a portion of the height. | 19 | /// Gives you the power to get a portion of the height. |
| 18 | /// Useful for responsive applications. | 20 | /// Useful for responsive applications. |
| 19 | /// | 21 | /// |
| 20 | - /// [dividedBy] is for when you want to have a portion of the value you would get | ||
| 21 | - /// like for example: if you want a value that represents a third of the screen | ||
| 22 | - /// you can set it to 3, and you will get a third of the height | 22 | + /// [dividedBy] is for when you want to have a portion of the value you |
| 23 | + /// would get like for example: if you want a value that represents a third | ||
| 24 | + /// of the screen you can set it to 3, and you will get a third of the height | ||
| 23 | /// | 25 | /// |
| 24 | /// [reducedBy] is a percentage value of how much of the height you want | 26 | /// [reducedBy] is a percentage value of how much of the height you want |
| 25 | /// if you for example want 46% of the height, then you reduce it by 56%. | 27 | /// if you for example want 46% of the height, then you reduce it by 56%. |
| @@ -32,9 +34,9 @@ extension ContextExtensionss on BuildContext { | @@ -32,9 +34,9 @@ extension ContextExtensionss on BuildContext { | ||
| 32 | /// Gives you the power to get a portion of the width. | 34 | /// Gives you the power to get a portion of the width. |
| 33 | /// Useful for responsive applications. | 35 | /// Useful for responsive applications. |
| 34 | /// | 36 | /// |
| 35 | - /// [dividedBy] is for when you want to have a portion of the value you would get | ||
| 36 | - /// like for example: if you want a value that represents a third of the screen | ||
| 37 | - /// you can set it to 3, and you will get a third of the width | 37 | + /// [dividedBy] is for when you want to have a portion of the value you |
| 38 | + /// would get like for example: if you want a value that represents a third | ||
| 39 | + /// of the screen you can set it to 3, and you will get a third of the width | ||
| 38 | /// | 40 | /// |
| 39 | /// [reducedBy] is a percentage value of how much of the width you want | 41 | /// [reducedBy] is a percentage value of how much of the width you want |
| 40 | /// if you for example want 46% of the width, then you reduce it by 56%. | 42 | /// if you for example want 46% of the width, then you reduce it by 56%. |
| @@ -105,7 +107,8 @@ extension ContextExtensionss on BuildContext { | @@ -105,7 +107,8 @@ extension ContextExtensionss on BuildContext { | ||
| 105 | bool get isTablet => isSmallTablet || isLargeTablet; | 107 | bool get isTablet => isSmallTablet || isLargeTablet; |
| 106 | 108 | ||
| 107 | /// Returns a specific value according to the screen size | 109 | /// Returns a specific value according to the screen size |
| 108 | - /// if the device width is higher than or equal to 1200 return [desktop] value. | 110 | + /// if the device width is higher than or equal to 1200 return [desktop] |
| 111 | + /// value. | ||
| 109 | /// if the device width is higher than or equal to 600 and less than 1200 | 112 | /// if the device width is higher than or equal to 600 and less than 1200 |
| 110 | /// return [tablet] value. | 113 | /// return [tablet] value. |
| 111 | /// if the device width is less than 300 return [watch] value. | 114 | /// if the device width is less than 300 return [watch] value. |
| @@ -116,7 +119,7 @@ extension ContextExtensionss on BuildContext { | @@ -116,7 +119,7 @@ extension ContextExtensionss on BuildContext { | ||
| 116 | T desktop, | 119 | T desktop, |
| 117 | T watch, | 120 | T watch, |
| 118 | }) { | 121 | }) { |
| 119 | - double deviceWidth = mediaQuerySize.shortestSide; | 122 | + var deviceWidth = mediaQuerySize.shortestSide; |
| 120 | 123 | ||
| 121 | if (kIsWeb) { | 124 | if (kIsWeb) { |
| 122 | deviceWidth = mediaQuerySize.width; | 125 | deviceWidth = mediaQuerySize.width; |
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
| 3 | -import 'package:get/get.dart'; | 3 | + |
| 4 | +import '../../../get.dart'; | ||
| 4 | 5 | ||
| 5 | extension ContextExtensionss on BuildContext { | 6 | extension ContextExtensionss on BuildContext { |
| 6 | /// The same of [MediaQuery.of(context).size] | 7 | /// The same of [MediaQuery.of(context).size] |
| 7 | Size get mediaQuerySize => MediaQuery.of(this).size; | 8 | Size get mediaQuerySize => MediaQuery.of(this).size; |
| 8 | 9 | ||
| 9 | /// The same of [MediaQuery.of(context).size.height] | 10 | /// The same of [MediaQuery.of(context).size.height] |
| 10 | - /// Note: updates when you rezise your screen (like on a browser or desktop window) | 11 | + /// Note: updates when you rezise your screen (like on a browser or |
| 12 | + /// desktop window) | ||
| 11 | double get height => mediaQuerySize.height; | 13 | double get height => mediaQuerySize.height; |
| 12 | 14 | ||
| 13 | /// The same of [MediaQuery.of(context).size.width] | 15 | /// The same of [MediaQuery.of(context).size.width] |
| 14 | - /// Note: updates when you rezise your screen (like on a browser or desktop window) | 16 | + /// Note: updates when you rezise your screen (like on a browser or |
| 17 | + /// desktop window) | ||
| 15 | double get width => mediaQuerySize.width; | 18 | double get width => mediaQuerySize.width; |
| 16 | 19 | ||
| 17 | /// Gives you the power to get a portion of the height. | 20 | /// Gives you the power to get a portion of the height. |
| 18 | /// Useful for responsive applications. | 21 | /// Useful for responsive applications. |
| 19 | /// | 22 | /// |
| 20 | - /// [dividedBy] is for when you want to have a portion of the value you would get | ||
| 21 | - /// like for example: if you want a value that represents a third of the screen | ||
| 22 | - /// you can set it to 3, and you will get a third of the height | 23 | + /// [dividedBy] is for when you want to have a portion of the value you |
| 24 | + /// would get like for example: if you want a value that represents a third | ||
| 25 | + /// of the screen you can set it to 3, and you will get a third of the height | ||
| 23 | /// | 26 | /// |
| 24 | /// [reducedBy] is a percentage value of how much of the height you want | 27 | /// [reducedBy] is a percentage value of how much of the height you want |
| 25 | /// if you for example want 46% of the height, then you reduce it by 56%. | 28 | /// if you for example want 46% of the height, then you reduce it by 56%. |
| @@ -32,9 +35,9 @@ extension ContextExtensionss on BuildContext { | @@ -32,9 +35,9 @@ extension ContextExtensionss on BuildContext { | ||
| 32 | /// Gives you the power to get a portion of the width. | 35 | /// Gives you the power to get a portion of the width. |
| 33 | /// Useful for responsive applications. | 36 | /// Useful for responsive applications. |
| 34 | /// | 37 | /// |
| 35 | - /// [dividedBy] is for when you want to have a portion of the value you would get | ||
| 36 | - /// like for example: if you want a value that represents a third of the screen | ||
| 37 | - /// you can set it to 3, and you will get a third of the width | 38 | + /// [dividedBy] is for when you want to have a portion of the value you |
| 39 | + /// would get like for example: if you want a value that represents a third | ||
| 40 | + /// of the screen you can set it to 3, and you will get a third of the width | ||
| 38 | /// | 41 | /// |
| 39 | /// [reducedBy] is a percentage value of how much of the width you want | 42 | /// [reducedBy] is a percentage value of how much of the width you want |
| 40 | /// if you for example want 46% of the width, then you reduce it by 56%. | 43 | /// if you for example want 46% of the width, then you reduce it by 56%. |
| @@ -105,9 +108,9 @@ extension ContextExtensionss on BuildContext { | @@ -105,9 +108,9 @@ extension ContextExtensionss on BuildContext { | ||
| 105 | bool get isTablet => isSmallTablet || isLargeTablet; | 108 | bool get isTablet => isSmallTablet || isLargeTablet; |
| 106 | 109 | ||
| 107 | /// Returns a specific value according to the screen size | 110 | /// Returns a specific value according to the screen size |
| 108 | - /// if the device width is higher than or equal to 1200 return [desktop] value. | ||
| 109 | - /// if the device width is higher than or equal to 600 and less than 1200 | ||
| 110 | - /// return [tablet] value. | 111 | + /// if the device width is higher than or equal to 1200 return |
| 112 | + /// [desktop] value. if the device width is higher than or equal to 600 | ||
| 113 | + /// and less than 1200 return [tablet] value. | ||
| 111 | /// if the device width is less than 300 return [watch] value. | 114 | /// if the device width is less than 300 return [watch] value. |
| 112 | /// in other cases return [mobile] value. | 115 | /// in other cases return [mobile] value. |
| 113 | T responsiveValue<T>({ | 116 | T responsiveValue<T>({ |
| @@ -116,7 +119,7 @@ extension ContextExtensionss on BuildContext { | @@ -116,7 +119,7 @@ extension ContextExtensionss on BuildContext { | ||
| 116 | T desktop, | 119 | T desktop, |
| 117 | T watch, | 120 | T watch, |
| 118 | }) { | 121 | }) { |
| 119 | - double deviceWidth = mediaQuerySize.shortestSide; | 122 | + var deviceWidth = mediaQuerySize.shortestSide; |
| 120 | if (GetPlatform.isDesktop) { | 123 | if (GetPlatform.isDesktop) { |
| 121 | deviceWidth = mediaQuerySize.width; | 124 | deviceWidth = mediaQuerySize.width; |
| 122 | } | 125 | } |
| @@ -2,7 +2,7 @@ import 'dart:math'; | @@ -2,7 +2,7 @@ import 'dart:math'; | ||
| 2 | 2 | ||
| 3 | extension Precision on double { | 3 | extension Precision on double { |
| 4 | double toPrecision(int fractionDigits) { | 4 | double toPrecision(int fractionDigits) { |
| 5 | - double mod = pow(10, fractionDigits.toDouble()); | 5 | + var mod = pow(10, fractionDigits.toDouble()).toDouble(); |
| 6 | return ((this * mod).round().toDouble() / mod); | 6 | return ((this * mod).round().toDouble() / mod); |
| 7 | } | 7 | } |
| 8 | } | 8 | } |
| 1 | import '../regex/get_utils.dart'; | 1 | import '../regex/get_utils.dart'; |
| 2 | 2 | ||
| 3 | extension GetDynamicUtils on dynamic { | 3 | extension GetDynamicUtils on dynamic { |
| 4 | - /// It's This is overloading the IDE's options. Only the most useful and popular options will stay here. | 4 | + /// It's This is overloading the IDE's options. Only the most useful and |
| 5 | + /// popular options will stay here. | ||
| 5 | 6 | ||
| 6 | bool get isNull => GetUtils.isNull(this); | 7 | bool get isNull => GetUtils.isNull(this); |
| 8 | + | ||
| 7 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); | 9 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); |
| 8 | } | 10 | } |
| @@ -4,7 +4,9 @@ import '../regex/get_utils.dart'; | @@ -4,7 +4,9 @@ import '../regex/get_utils.dart'; | ||
| 4 | 4 | ||
| 5 | extension GetNumUtils on num { | 5 | extension GetNumUtils on num { |
| 6 | bool isLowerThan(num b) => GetUtils.isLowerThan(this, b); | 6 | bool isLowerThan(num b) => GetUtils.isLowerThan(this, b); |
| 7 | + | ||
| 7 | bool isGreaterThan(num b) => GetUtils.isGreaterThan(this, b); | 8 | bool isGreaterThan(num b) => GetUtils.isGreaterThan(this, b); |
| 9 | + | ||
| 8 | bool isEqual(num b) => GetUtils.isEqual(this, b); | 10 | bool isEqual(num b) => GetUtils.isEqual(this, b); |
| 9 | 11 | ||
| 10 | /// Utility to delay some callback (or code execution). | 12 | /// Utility to delay some callback (or code execution). |
| @@ -34,11 +36,15 @@ extension GetNumUtils on num { | @@ -34,11 +36,15 @@ extension GetNumUtils on num { | ||
| 34 | /// print(1.5.hours); | 36 | /// print(1.5.hours); |
| 35 | ///``` | 37 | ///``` |
| 36 | Duration get milliseconds => Duration(microseconds: (this * 1000).round()); | 38 | Duration get milliseconds => Duration(microseconds: (this * 1000).round()); |
| 39 | + | ||
| 37 | Duration get seconds => Duration(milliseconds: (this * 1000).round()); | 40 | Duration get seconds => Duration(milliseconds: (this * 1000).round()); |
| 41 | + | ||
| 38 | Duration get minutes => | 42 | Duration get minutes => |
| 39 | Duration(seconds: (this * Duration.secondsPerMinute).round()); | 43 | Duration(seconds: (this * Duration.secondsPerMinute).round()); |
| 44 | + | ||
| 40 | Duration get hours => | 45 | Duration get hours => |
| 41 | Duration(minutes: (this * Duration.minutesPerHour).round()); | 46 | Duration(minutes: (this * Duration.minutesPerHour).round()); |
| 47 | + | ||
| 42 | Duration get days => Duration(hours: (this * Duration.hoursPerDay).round()); | 48 | Duration get days => Duration(hours: (this * Duration.hoursPerDay).round()); |
| 43 | 49 | ||
| 44 | //final _delayMaps = <Function, Future>{}; | 50 | //final _delayMaps = <Function, Future>{}; |
| @@ -2,45 +2,82 @@ import '../regex/get_utils.dart'; | @@ -2,45 +2,82 @@ import '../regex/get_utils.dart'; | ||
| 2 | 2 | ||
| 3 | extension GetStringUtils on String { | 3 | extension GetStringUtils on String { |
| 4 | bool get isNum => GetUtils.isNum(this); | 4 | bool get isNum => GetUtils.isNum(this); |
| 5 | + | ||
| 5 | bool get isNumericOnly => GetUtils.isNumericOnly(this); | 6 | bool get isNumericOnly => GetUtils.isNumericOnly(this); |
| 7 | + | ||
| 6 | bool get isAlphabetOnly => GetUtils.isAlphabetOnly(this); | 8 | bool get isAlphabetOnly => GetUtils.isAlphabetOnly(this); |
| 9 | + | ||
| 7 | bool get isBool => GetUtils.isBool(this); | 10 | bool get isBool => GetUtils.isBool(this); |
| 11 | + | ||
| 8 | bool get isVectorFileName => GetUtils.isVector(this); | 12 | bool get isVectorFileName => GetUtils.isVector(this); |
| 13 | + | ||
| 9 | bool get isImageFileName => GetUtils.isImage(this); | 14 | bool get isImageFileName => GetUtils.isImage(this); |
| 15 | + | ||
| 10 | bool get isAudioFileName => GetUtils.isAudio(this); | 16 | bool get isAudioFileName => GetUtils.isAudio(this); |
| 17 | + | ||
| 11 | bool get isVideoFileName => GetUtils.isVideo(this); | 18 | bool get isVideoFileName => GetUtils.isVideo(this); |
| 19 | + | ||
| 12 | bool get isTxtFileName => GetUtils.isTxt(this); | 20 | bool get isTxtFileName => GetUtils.isTxt(this); |
| 21 | + | ||
| 13 | bool get isDocumentFileName => GetUtils.isWord(this); | 22 | bool get isDocumentFileName => GetUtils.isWord(this); |
| 23 | + | ||
| 14 | bool get isExcelFileName => GetUtils.isExcel(this); | 24 | bool get isExcelFileName => GetUtils.isExcel(this); |
| 25 | + | ||
| 15 | bool get isPPTFileName => GetUtils.isPPT(this); | 26 | bool get isPPTFileName => GetUtils.isPPT(this); |
| 27 | + | ||
| 16 | bool get isAPKFileName => GetUtils.isAPK(this); | 28 | bool get isAPKFileName => GetUtils.isAPK(this); |
| 29 | + | ||
| 17 | bool get isPDFFileName => GetUtils.isPDF(this); | 30 | bool get isPDFFileName => GetUtils.isPDF(this); |
| 31 | + | ||
| 18 | bool get isHTMLFileName => GetUtils.isHTML(this); | 32 | bool get isHTMLFileName => GetUtils.isHTML(this); |
| 33 | + | ||
| 19 | bool get isURL => GetUtils.isURL(this); | 34 | bool get isURL => GetUtils.isURL(this); |
| 35 | + | ||
| 20 | bool get isEmail => GetUtils.isEmail(this); | 36 | bool get isEmail => GetUtils.isEmail(this); |
| 37 | + | ||
| 21 | bool get isPhoneNumber => GetUtils.isPhoneNumber(this); | 38 | bool get isPhoneNumber => GetUtils.isPhoneNumber(this); |
| 39 | + | ||
| 22 | bool get isDateTime => GetUtils.isDateTime(this); | 40 | bool get isDateTime => GetUtils.isDateTime(this); |
| 41 | + | ||
| 23 | bool get isMD5 => GetUtils.isMD5(this); | 42 | bool get isMD5 => GetUtils.isMD5(this); |
| 43 | + | ||
| 24 | bool get isSHA1 => GetUtils.isSHA1(this); | 44 | bool get isSHA1 => GetUtils.isSHA1(this); |
| 45 | + | ||
| 25 | bool get isSHA256 => GetUtils.isSHA256(this); | 46 | bool get isSHA256 => GetUtils.isSHA256(this); |
| 47 | + | ||
| 26 | bool get isBinary => GetUtils.isBinary(this); | 48 | bool get isBinary => GetUtils.isBinary(this); |
| 49 | + | ||
| 27 | bool get isIPv4 => GetUtils.isIPv4(this); | 50 | bool get isIPv4 => GetUtils.isIPv4(this); |
| 51 | + | ||
| 28 | bool get isIPv6 => GetUtils.isIPv6(this); | 52 | bool get isIPv6 => GetUtils.isIPv6(this); |
| 53 | + | ||
| 29 | bool get isHexadecimal => GetUtils.isHexadecimal(this); | 54 | bool get isHexadecimal => GetUtils.isHexadecimal(this); |
| 55 | + | ||
| 30 | bool get isPalindrom => GetUtils.isPalindrom(this); | 56 | bool get isPalindrom => GetUtils.isPalindrom(this); |
| 57 | + | ||
| 31 | bool get isPassport => GetUtils.isPassport(this); | 58 | bool get isPassport => GetUtils.isPassport(this); |
| 59 | + | ||
| 32 | bool get isCurrency => GetUtils.isCurrency(this); | 60 | bool get isCurrency => GetUtils.isCurrency(this); |
| 61 | + | ||
| 33 | bool isCpf(String s) => GetUtils.isCpf(this); | 62 | bool isCpf(String s) => GetUtils.isCpf(this); |
| 63 | + | ||
| 34 | bool isCnpj(String s) => GetUtils.isCnpj(this); | 64 | bool isCnpj(String s) => GetUtils.isCnpj(this); |
| 65 | + | ||
| 35 | bool isCaseInsensitiveContains(String b) => | 66 | bool isCaseInsensitiveContains(String b) => |
| 36 | GetUtils.isCaseInsensitiveContains(this, b); | 67 | GetUtils.isCaseInsensitiveContains(this, b); |
| 68 | + | ||
| 37 | bool isCaseInsensitiveContainsAny(String b) => | 69 | bool isCaseInsensitiveContainsAny(String b) => |
| 38 | GetUtils.isCaseInsensitiveContainsAny(this, b); | 70 | GetUtils.isCaseInsensitiveContainsAny(this, b); |
| 71 | + | ||
| 39 | String capitalize(String s, {bool firstOnly = false}) => | 72 | String capitalize(String s, {bool firstOnly = false}) => |
| 40 | GetUtils.capitalize(this, firstOnly: firstOnly); | 73 | GetUtils.capitalize(this, firstOnly: firstOnly); |
| 74 | + | ||
| 41 | String capitalizeFirst(String s) => GetUtils.capitalizeFirst(this); | 75 | String capitalizeFirst(String s) => GetUtils.capitalizeFirst(this); |
| 76 | + | ||
| 42 | String removeAllWhitespace(String s) => GetUtils.removeAllWhitespace(this); | 77 | String removeAllWhitespace(String s) => GetUtils.removeAllWhitespace(this); |
| 78 | + | ||
| 43 | String camelCase(String s) => GetUtils.camelCase(this); | 79 | String camelCase(String s) => GetUtils.camelCase(this); |
| 80 | + | ||
| 44 | String numericOnly(String s, {bool firstWordOnly = false}) => | 81 | String numericOnly(String s, {bool firstWordOnly = false}) => |
| 45 | GetUtils.numericOnly(this, firstWordOnly: firstWordOnly); | 82 | GetUtils.numericOnly(this, firstWordOnly: firstWordOnly); |
| 46 | } | 83 | } |
| 1 | import 'platform_web.dart' if (dart.library.io) 'platform_io.dart'; | 1 | import 'platform_web.dart' if (dart.library.io) 'platform_io.dart'; |
| 2 | 2 | ||
| 3 | +// ignore: avoid_classes_with_only_static_members | ||
| 3 | class GetPlatform { | 4 | class GetPlatform { |
| 4 | static bool get isWeb => GeneralPlatform.isWeb; | 5 | static bool get isWeb => GeneralPlatform.isWeb; |
| 6 | + | ||
| 5 | static bool get isMacOS => GeneralPlatform.isMacOS; | 7 | static bool get isMacOS => GeneralPlatform.isMacOS; |
| 8 | + | ||
| 6 | static bool get isWindows => GeneralPlatform.isWindows; | 9 | static bool get isWindows => GeneralPlatform.isWindows; |
| 10 | + | ||
| 7 | static bool get isLinux => GeneralPlatform.isLinux; | 11 | static bool get isLinux => GeneralPlatform.isLinux; |
| 12 | + | ||
| 8 | static bool get isAndroid => GeneralPlatform.isAndroid; | 13 | static bool get isAndroid => GeneralPlatform.isAndroid; |
| 14 | + | ||
| 9 | static bool get isIOS => GeneralPlatform.isIOS; | 15 | static bool get isIOS => GeneralPlatform.isIOS; |
| 16 | + | ||
| 10 | static bool get isFuchsia => GeneralPlatform.isFuchsia; | 17 | static bool get isFuchsia => GeneralPlatform.isFuchsia; |
| 18 | + | ||
| 11 | static bool get isMobile => GetPlatform.isIOS || GetPlatform.isAndroid; | 19 | static bool get isMobile => GetPlatform.isIOS || GetPlatform.isAndroid; |
| 20 | + | ||
| 12 | static bool get isDesktop => | 21 | static bool get isDesktop => |
| 13 | GetPlatform.isMacOS || GetPlatform.isWindows || GetPlatform.isLinux; | 22 | GetPlatform.isMacOS || GetPlatform.isWindows || GetPlatform.isLinux; |
| 14 | } | 23 | } |
| 1 | import 'dart:io'; | 1 | import 'dart:io'; |
| 2 | 2 | ||
| 3 | +// ignore: avoid_classes_with_only_static_members | ||
| 3 | class GeneralPlatform { | 4 | class GeneralPlatform { |
| 4 | static bool get isWeb => false; | 5 | static bool get isWeb => false; |
| 6 | + | ||
| 5 | static bool get isMacOS => Platform.isMacOS; | 7 | static bool get isMacOS => Platform.isMacOS; |
| 8 | + | ||
| 6 | static bool get isWindows => Platform.isWindows; | 9 | static bool get isWindows => Platform.isWindows; |
| 10 | + | ||
| 7 | static bool get isLinux => Platform.isLinux; | 11 | static bool get isLinux => Platform.isLinux; |
| 12 | + | ||
| 8 | static bool get isAndroid => Platform.isAndroid; | 13 | static bool get isAndroid => Platform.isAndroid; |
| 14 | + | ||
| 9 | static bool get isIOS => Platform.isIOS; | 15 | static bool get isIOS => Platform.isIOS; |
| 16 | + | ||
| 10 | static bool get isFuchsia => Platform.isFuchsia; | 17 | static bool get isFuchsia => Platform.isFuchsia; |
| 18 | + | ||
| 11 | static bool get isDesktop => | 19 | static bool get isDesktop => |
| 12 | Platform.isMacOS || Platform.isWindows || Platform.isLinux; | 20 | Platform.isMacOS || Platform.isWindows || Platform.isLinux; |
| 13 | } | 21 | } |
| @@ -2,10 +2,11 @@ | @@ -2,10 +2,11 @@ | ||
| 2 | // ignore: avoid_web_libraries_in_flutter | 2 | // ignore: avoid_web_libraries_in_flutter |
| 3 | import 'dart:html' as html; | 3 | import 'dart:html' as html; |
| 4 | 4 | ||
| 5 | -import 'package:get/utils.dart'; | 5 | +import '../../../utils.dart'; |
| 6 | 6 | ||
| 7 | html.Navigator _navigator = html.window.navigator; | 7 | html.Navigator _navigator = html.window.navigator; |
| 8 | 8 | ||
| 9 | +// ignore: avoid_classes_with_only_static_members | ||
| 9 | class GeneralPlatform { | 10 | class GeneralPlatform { |
| 10 | static bool get isWeb => true; | 11 | static bool get isWeb => true; |
| 11 | 12 | ||
| @@ -29,5 +30,6 @@ class GeneralPlatform { | @@ -29,5 +30,6 @@ class GeneralPlatform { | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | static bool get isFuchsia => false; | 32 | static bool get isFuchsia => false; |
| 33 | + | ||
| 32 | static bool get isDesktop => isMacOS || isWindows || isLinux; | 34 | static bool get isDesktop => isMacOS || isWindows || isLinux; |
| 33 | } | 35 | } |
| @@ -10,7 +10,7 @@ class GetQueue { | @@ -10,7 +10,7 @@ class GetQueue { | ||
| 10 | var item = _queue.removeAt(0); | 10 | var item = _queue.removeAt(0); |
| 11 | try { | 11 | try { |
| 12 | item.completer.complete(await item.job()); | 12 | item.completer.complete(await item.job()); |
| 13 | - } catch (e) { | 13 | + } on Exception catch (e) { |
| 14 | item.completer.completeError(e); | 14 | item.completer.completeError(e); |
| 15 | } | 15 | } |
| 16 | _active = false; | 16 | _active = false; |
| @@ -27,7 +27,8 @@ class GetQueue { | @@ -27,7 +27,8 @@ class GetQueue { | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | class _Item { | 29 | class _Item { |
| 30 | - final completer; | ||
| 31 | - final job; | 30 | + final dynamic completer; |
| 31 | + final dynamic job; | ||
| 32 | + | ||
| 32 | _Item(this.completer, this.job); | 33 | _Item(this.completer, this.job); |
| 33 | } | 34 | } |
| @@ -4,22 +4,23 @@ class GetUtils { | @@ -4,22 +4,23 @@ class GetUtils { | ||
| 4 | 4 | ||
| 5 | /// In dart2js (in flutter v1.17) a var by default is undefined. | 5 | /// In dart2js (in flutter v1.17) a var by default is undefined. |
| 6 | /// *Use this only if you are in version <- 1.17*. | 6 | /// *Use this only if you are in version <- 1.17*. |
| 7 | - /// So we assure the null type in json convertions to avoid the "value":value==null?null:value; | ||
| 8 | - /// someVar.nil will force the null type if the var is null or undefined. | 7 | + /// So we assure the null type in json convertions to avoid the |
| 8 | + /// "value":value==null?null:value; someVar.nil will force the null type | ||
| 9 | + /// if the var is null or undefined. | ||
| 9 | /// `nil` taken from ObjC just to have a shorter sintax. | 10 | /// `nil` taken from ObjC just to have a shorter sintax. |
| 10 | static dynamic nil(dynamic s) => s == null ? null : s; | 11 | static dynamic nil(dynamic s) => s == null ? null : s; |
| 11 | 12 | ||
| 12 | /// Checks if data is null or blank (empty or only contains whitespace). | 13 | /// Checks if data is null or blank (empty or only contains whitespace). |
| 13 | static bool isNullOrBlank(dynamic s) { | 14 | static bool isNullOrBlank(dynamic s) { |
| 14 | if (isNull(s)) return true; | 15 | if (isNull(s)) return true; |
| 15 | - switch (s.runtimeType) { | 16 | + |
| 17 | + switch (s.runtimeType as Type) { | ||
| 16 | case String: | 18 | case String: |
| 17 | case List: | 19 | case List: |
| 18 | case Map: | 20 | case Map: |
| 19 | case Set: | 21 | case Set: |
| 20 | case Iterable: | 22 | case Iterable: |
| 21 | - return s.isEmpty; | ||
| 22 | - break; | 23 | + return s.isEmpty as bool; |
| 23 | default: | 24 | default: |
| 24 | return s.toString() == 'null' || s.toString().trim().isEmpty; | 25 | return s.toString() == 'null' || s.toString().trim().isEmpty; |
| 25 | } | 26 | } |
| @@ -46,7 +47,9 @@ class GetUtils { | @@ -46,7 +47,9 @@ class GetUtils { | ||
| 46 | 47 | ||
| 47 | /// Checks if string is an video file. | 48 | /// Checks if string is an video file. |
| 48 | static bool isVideo(String filePath) { | 49 | static bool isVideo(String filePath) { |
| 49 | - String ext = filePath.toLowerCase(); | 50 | + var ext = filePath.toLowerCase(); |
| 51 | + | ||
| 52 | + // FIXME: why all those ()? | ||
| 50 | return (((((ext.endsWith(".mp4") || ext.endsWith(".avi")) || | 53 | return (((((ext.endsWith(".mp4") || ext.endsWith(".avi")) || |
| 51 | ext.endsWith(".wmv")) || | 54 | ext.endsWith(".wmv")) || |
| 52 | ext.endsWith(".rmvb")) || | 55 | ext.endsWith(".rmvb")) || |
| @@ -57,7 +60,9 @@ class GetUtils { | @@ -57,7 +60,9 @@ class GetUtils { | ||
| 57 | 60 | ||
| 58 | /// Checks if string is an image file. | 61 | /// Checks if string is an image file. |
| 59 | static bool isImage(String filePath) { | 62 | static bool isImage(String filePath) { |
| 60 | - String ext = filePath.toLowerCase(); | 63 | + final ext = filePath.toLowerCase(); |
| 64 | + | ||
| 65 | + // FIXME: why all those ()? | ||
| 61 | return (((ext.endsWith(".jpg") || ext.endsWith(".jpeg")) || | 66 | return (((ext.endsWith(".jpg") || ext.endsWith(".jpeg")) || |
| 62 | ext.endsWith(".png")) || | 67 | ext.endsWith(".png")) || |
| 63 | ext.endsWith(".gif")) || | 68 | ext.endsWith(".gif")) || |
| @@ -66,7 +71,9 @@ class GetUtils { | @@ -66,7 +71,9 @@ class GetUtils { | ||
| 66 | 71 | ||
| 67 | /// Checks if string is an audio file. | 72 | /// Checks if string is an audio file. |
| 68 | static bool isAudio(String filePath) { | 73 | static bool isAudio(String filePath) { |
| 69 | - String ext = filePath.toLowerCase(); | 74 | + final ext = filePath.toLowerCase(); |
| 75 | + | ||
| 76 | + // FIXME: why all those ()? | ||
| 70 | return (((ext.endsWith(".mp3") || ext.endsWith(".wav")) || | 77 | return (((ext.endsWith(".mp3") || ext.endsWith(".wav")) || |
| 71 | ext.endsWith(".wma")) || | 78 | ext.endsWith(".wma")) || |
| 72 | ext.endsWith(".amr")) || | 79 | ext.endsWith(".amr")) || |
| @@ -75,19 +82,19 @@ class GetUtils { | @@ -75,19 +82,19 @@ class GetUtils { | ||
| 75 | 82 | ||
| 76 | /// Checks if string is an powerpoint file. | 83 | /// Checks if string is an powerpoint file. |
| 77 | static bool isPPT(String filePath) { | 84 | static bool isPPT(String filePath) { |
| 78 | - String ext = filePath.toLowerCase(); | 85 | + final ext = filePath.toLowerCase(); |
| 79 | return ext.endsWith(".ppt") || ext.endsWith(".pptx"); | 86 | return ext.endsWith(".ppt") || ext.endsWith(".pptx"); |
| 80 | } | 87 | } |
| 81 | 88 | ||
| 82 | /// Checks if string is an word file. | 89 | /// Checks if string is an word file. |
| 83 | static bool isWord(String filePath) { | 90 | static bool isWord(String filePath) { |
| 84 | - String ext = filePath.toLowerCase(); | 91 | + final ext = filePath.toLowerCase(); |
| 85 | return ext.endsWith(".doc") || ext.endsWith(".docx"); | 92 | return ext.endsWith(".doc") || ext.endsWith(".docx"); |
| 86 | } | 93 | } |
| 87 | 94 | ||
| 88 | /// Checks if string is an excel file. | 95 | /// Checks if string is an excel file. |
| 89 | static bool isExcel(String filePath) { | 96 | static bool isExcel(String filePath) { |
| 90 | - String ext = filePath.toLowerCase(); | 97 | + final ext = filePath.toLowerCase(); |
| 91 | return ext.endsWith(".xls") || ext.endsWith(".xlsx"); | 98 | return ext.endsWith(".xls") || ext.endsWith(".xlsx"); |
| 92 | } | 99 | } |
| 93 | 100 | ||
| @@ -174,9 +181,11 @@ class GetUtils { | @@ -174,9 +181,11 @@ class GetUtils { | ||
| 174 | 181 | ||
| 175 | /// Checks if string is Palindrom. | 182 | /// Checks if string is Palindrom. |
| 176 | static bool isPalindrom(String s) { | 183 | static bool isPalindrom(String s) { |
| 177 | - bool isPalindrom = true; | 184 | + var isPalindrom = true; |
| 178 | for (var i = 0; i < s.length; i++) { | 185 | for (var i = 0; i < s.length; i++) { |
| 179 | - if (s[i] != s[s.length - i - 1]) isPalindrom = false; | 186 | + if (s[i] != s[s.length - i - 1]) { |
| 187 | + isPalindrom = false; | ||
| 188 | + } | ||
| 180 | } | 189 | } |
| 181 | return isPalindrom; | 190 | return isPalindrom; |
| 182 | } | 191 | } |
| @@ -187,13 +196,15 @@ class GetUtils { | @@ -187,13 +196,15 @@ class GetUtils { | ||
| 187 | if ((s is String || s is List) && !isNullOrBlank(s)) { | 196 | if ((s is String || s is List) && !isNullOrBlank(s)) { |
| 188 | var first = s[0]; | 197 | var first = s[0]; |
| 189 | var isOneAKind = true; | 198 | var isOneAKind = true; |
| 190 | - for (var i = 0; i < s.length; i++) { | 199 | + var len = s.length as num; |
| 200 | + for (var i = 0; i < len; i++) { | ||
| 191 | if (s[i] != first) isOneAKind = false; | 201 | if (s[i] != first) isOneAKind = false; |
| 192 | } | 202 | } |
| 193 | return isOneAKind; | 203 | return isOneAKind; |
| 194 | } | 204 | } |
| 205 | + | ||
| 195 | if (s is int) { | 206 | if (s is int) { |
| 196 | - String value = s.toString(); | 207 | + var value = s.toString(); |
| 197 | var first = value[0]; | 208 | var first = value[0]; |
| 198 | var isOneAKind = true; | 209 | var isOneAKind = true; |
| 199 | for (var i = 0; i < value.length; i++) { | 210 | for (var i = 0; i < value.length; i++) { |
| @@ -215,20 +226,17 @@ class GetUtils { | @@ -215,20 +226,17 @@ class GetUtils { | ||
| 215 | /// Checks if length of data is LOWER than maxLength. | 226 | /// Checks if length of data is LOWER than maxLength. |
| 216 | static bool isLengthLowerThan(dynamic s, int maxLength) { | 227 | static bool isLengthLowerThan(dynamic s, int maxLength) { |
| 217 | if (isNull(s)) return (maxLength <= 0) ? true : false; | 228 | if (isNull(s)) return (maxLength <= 0) ? true : false; |
| 218 | - switch (s.runtimeType) { | 229 | + switch (s.runtimeType as Type) { |
| 219 | case String: | 230 | case String: |
| 220 | case List: | 231 | case List: |
| 221 | case Map: | 232 | case Map: |
| 222 | case Set: | 233 | case Set: |
| 223 | case Iterable: | 234 | case Iterable: |
| 224 | - return s.length < maxLength; | ||
| 225 | - break; | 235 | + return (s.length as num) < maxLength; |
| 226 | case int: | 236 | case int: |
| 227 | return s.toString().length < maxLength; | 237 | return s.toString().length < maxLength; |
| 228 | - break; | ||
| 229 | case double: | 238 | case double: |
| 230 | return s.toString().replaceAll('.', '').length < maxLength; | 239 | return s.toString().replaceAll('.', '').length < maxLength; |
| 231 | - break; | ||
| 232 | default: | 240 | default: |
| 233 | return false; | 241 | return false; |
| 234 | } | 242 | } |
| @@ -237,20 +245,17 @@ class GetUtils { | @@ -237,20 +245,17 @@ class GetUtils { | ||
| 237 | /// Checks if length of data is GREATER than maxLength. | 245 | /// Checks if length of data is GREATER than maxLength. |
| 238 | static bool isLengthGreaterThan(dynamic s, int maxLength) { | 246 | static bool isLengthGreaterThan(dynamic s, int maxLength) { |
| 239 | if (isNull(s)) return false; | 247 | if (isNull(s)) return false; |
| 240 | - switch (s.runtimeType) { | 248 | + switch (s.runtimeType as Type) { |
| 241 | case String: | 249 | case String: |
| 242 | case List: | 250 | case List: |
| 243 | case Map: | 251 | case Map: |
| 244 | case Set: | 252 | case Set: |
| 245 | case Iterable: | 253 | case Iterable: |
| 246 | - return s.length > maxLength; | ||
| 247 | - break; | 254 | + return (s.length as num) > maxLength; |
| 248 | case int: | 255 | case int: |
| 249 | return s.toString().length > maxLength; | 256 | return s.toString().length > maxLength; |
| 250 | - break; | ||
| 251 | case double: | 257 | case double: |
| 252 | return s.toString().replaceAll('.', '').length > maxLength; | 258 | return s.toString().replaceAll('.', '').length > maxLength; |
| 253 | - break; | ||
| 254 | default: | 259 | default: |
| 255 | return false; | 260 | return false; |
| 256 | } | 261 | } |
| @@ -259,13 +264,13 @@ class GetUtils { | @@ -259,13 +264,13 @@ class GetUtils { | ||
| 259 | /// Checks if length of data is GREATER OR EQUAL to maxLength. | 264 | /// Checks if length of data is GREATER OR EQUAL to maxLength. |
| 260 | static bool isLengthGreaterOrEqual(dynamic s, int maxLength) { | 265 | static bool isLengthGreaterOrEqual(dynamic s, int maxLength) { |
| 261 | if (isNull(s)) return false; | 266 | if (isNull(s)) return false; |
| 262 | - switch (s.runtimeType) { | 267 | + switch (s.runtimeType as Type) { |
| 263 | case String: | 268 | case String: |
| 264 | case List: | 269 | case List: |
| 265 | case Map: | 270 | case Map: |
| 266 | case Set: | 271 | case Set: |
| 267 | case Iterable: | 272 | case Iterable: |
| 268 | - return s.length >= maxLength; | 273 | + return (s.length as num) >= maxLength; |
| 269 | break; | 274 | break; |
| 270 | case int: | 275 | case int: |
| 271 | return s.toString().length >= maxLength; | 276 | return s.toString().length >= maxLength; |
| @@ -281,17 +286,15 @@ class GetUtils { | @@ -281,17 +286,15 @@ class GetUtils { | ||
| 281 | /// Checks if length of data is LOWER OR EQUAL to maxLength. | 286 | /// Checks if length of data is LOWER OR EQUAL to maxLength. |
| 282 | static bool isLengthLowerOrEqual(dynamic s, int maxLength) { | 287 | static bool isLengthLowerOrEqual(dynamic s, int maxLength) { |
| 283 | if (isNull(s)) return false; | 288 | if (isNull(s)) return false; |
| 284 | - switch (s.runtimeType) { | 289 | + switch (s.runtimeType as Type) { |
| 285 | case String: | 290 | case String: |
| 286 | case List: | 291 | case List: |
| 287 | case Map: | 292 | case Map: |
| 288 | case Set: | 293 | case Set: |
| 289 | case Iterable: | 294 | case Iterable: |
| 290 | - return s.length <= maxLength; | ||
| 291 | - break; | 295 | + return (s.length as num) <= maxLength; |
| 292 | case int: | 296 | case int: |
| 293 | return s.toString().length <= maxLength; | 297 | return s.toString().length <= maxLength; |
| 294 | - break; | ||
| 295 | case double: | 298 | case double: |
| 296 | return s.toString().replaceAll('.', '').length <= maxLength; | 299 | return s.toString().replaceAll('.', '').length <= maxLength; |
| 297 | default: | 300 | default: |
| @@ -302,7 +305,7 @@ class GetUtils { | @@ -302,7 +305,7 @@ class GetUtils { | ||
| 302 | /// Checks if length of data is EQUAL to maxLength. | 305 | /// Checks if length of data is EQUAL to maxLength. |
| 303 | static bool isLengthEqualTo(dynamic s, int maxLength) { | 306 | static bool isLengthEqualTo(dynamic s, int maxLength) { |
| 304 | if (isNull(s)) return false; | 307 | if (isNull(s)) return false; |
| 305 | - switch (s.runtimeType) { | 308 | + switch (s.runtimeType as Type) { |
| 306 | case String: | 309 | case String: |
| 307 | case List: | 310 | case List: |
| 308 | case Map: | 311 | case Map: |
| @@ -328,14 +331,16 @@ class GetUtils { | @@ -328,14 +331,16 @@ class GetUtils { | ||
| 328 | isLengthLowerOrEqual(s, maxLength); | 331 | isLengthLowerOrEqual(s, maxLength); |
| 329 | } | 332 | } |
| 330 | 333 | ||
| 331 | - /// Checks if a contains b (Treating or interpreting upper- and lowercase letters as being the same). | 334 | + /// Checks if a contains b (Treating or interpreting upper- and lowercase |
| 335 | + /// letters as being the same). | ||
| 332 | static bool isCaseInsensitiveContains(String a, String b) => | 336 | static bool isCaseInsensitiveContains(String a, String b) => |
| 333 | a.toLowerCase().contains(b.toLowerCase()); | 337 | a.toLowerCase().contains(b.toLowerCase()); |
| 334 | 338 | ||
| 335 | - /// Checks if a contains b or b contains a (Treating or interpreting upper- and lowercase letters as being the same). | 339 | + /// Checks if a contains b or b contains a (Treating or |
| 340 | + /// interpreting upper- and lowercase letters as being the same). | ||
| 336 | static bool isCaseInsensitiveContainsAny(String a, String b) { | 341 | static bool isCaseInsensitiveContainsAny(String a, String b) { |
| 337 | - String lowA = a.toLowerCase(); | ||
| 338 | - String lowB = b.toLowerCase(); | 342 | + final lowA = a.toLowerCase(); |
| 343 | + final lowB = b.toLowerCase(); | ||
| 339 | return lowA.contains(lowB) || lowB.contains(lowA); | 344 | return lowA.contains(lowB) || lowB.contains(lowA); |
| 340 | } | 345 | } |
| 341 | 346 | ||
| @@ -362,8 +367,7 @@ class GetUtils { | @@ -362,8 +367,7 @@ class GetUtils { | ||
| 362 | if (RegExp(r'^(\d)\1*$').hasMatch(numbers)) return false; | 367 | if (RegExp(r'^(\d)\1*$').hasMatch(numbers)) return false; |
| 363 | 368 | ||
| 364 | // Dividir dígitos | 369 | // Dividir dígitos |
| 365 | - List<int> digits = | ||
| 366 | - numbers.split('').map((String d) => int.parse(d)).toList(); | 370 | + var digits = numbers.split('').map(int.parse).toList(); |
| 367 | 371 | ||
| 368 | // Calcular o primeiro dígito verificador | 372 | // Calcular o primeiro dígito verificador |
| 369 | var calcDv1 = 0; | 373 | var calcDv1 = 0; |
| @@ -404,8 +408,7 @@ class GetUtils { | @@ -404,8 +408,7 @@ class GetUtils { | ||
| 404 | if (RegExp(r'^(\d)\1*$').hasMatch(numbers)) return false; | 408 | if (RegExp(r'^(\d)\1*$').hasMatch(numbers)) return false; |
| 405 | 409 | ||
| 406 | // split the digits | 410 | // split the digits |
| 407 | - List<int> digits = | ||
| 408 | - numbers.split('').map((String d) => int.parse(d)).toList(); | 411 | + var digits = numbers.split('').map(int.parse).toList(); |
| 409 | 412 | ||
| 410 | // Calculate the first verifier digit | 413 | // Calculate the first verifier digit |
| 411 | var calcDv1 = 0; | 414 | var calcDv1 = 0; |
| @@ -441,9 +444,11 @@ class GetUtils { | @@ -441,9 +444,11 @@ class GetUtils { | ||
| 441 | if (isNullOrBlank(s)) return null; | 444 | if (isNullOrBlank(s)) return null; |
| 442 | if (firstOnly) return capitalizeFirst(s); | 445 | if (firstOnly) return capitalizeFirst(s); |
| 443 | 446 | ||
| 444 | - List lst = s.split(' '); | ||
| 445 | - String newStr = ''; | ||
| 446 | - for (var s in lst) newStr += capitalizeFirst(s); | 447 | + var lst = s.split(' '); |
| 448 | + var newStr = ''; | ||
| 449 | + for (var s in lst) { | ||
| 450 | + newStr += capitalizeFirst(s); | ||
| 451 | + } | ||
| 447 | return newStr; | 452 | return newStr; |
| 448 | } | 453 | } |
| 449 | 454 | ||
| @@ -470,9 +475,10 @@ class GetUtils { | @@ -470,9 +475,10 @@ class GetUtils { | ||
| 470 | 475 | ||
| 471 | /// Extract numeric value of string | 476 | /// Extract numeric value of string |
| 472 | /// Example: OTP 12312 27/04/2020 => 1231227042020ß | 477 | /// Example: OTP 12312 27/04/2020 => 1231227042020ß |
| 473 | - /// If firstword only is true, then the example return is "12312" (first found numeric word) | 478 | + /// If firstword only is true, then the example return is "12312" |
| 479 | + /// (first found numeric word) | ||
| 474 | static String numericOnly(String s, {bool firstWordOnly = false}) { | 480 | static String numericOnly(String s, {bool firstWordOnly = false}) { |
| 475 | - String numericOnlyStr = ''; | 481 | + var numericOnlyStr = ''; |
| 476 | for (var i = 0; i < s.length; i++) { | 482 | for (var i = 0; i < s.length; i++) { |
| 477 | if (isNumericOnly(s[i])) numericOnlyStr += s[i]; | 483 | if (isNumericOnly(s[i])) numericOnlyStr += s[i]; |
| 478 | if (firstWordOnly && numericOnlyStr.isNotEmpty && s[i] == " ") break; | 484 | if (firstWordOnly && numericOnlyStr.isNotEmpty && s[i] == " ") break; |
| @@ -480,6 +486,7 @@ class GetUtils { | @@ -480,6 +486,7 @@ class GetUtils { | ||
| 480 | return numericOnlyStr; | 486 | return numericOnlyStr; |
| 481 | } | 487 | } |
| 482 | 488 | ||
| 483 | - static bool hasMatch(String s, Pattern p) => | ||
| 484 | - (s == null) ? false : RegExp(p).hasMatch(s); | 489 | + static bool hasMatch(String value, String pattern) { |
| 490 | + return (value == null) ? false : RegExp(pattern).hasMatch(value); | ||
| 491 | + } | ||
| 485 | } | 492 | } |
| @@ -2,56 +2,96 @@ import 'get_utils.dart'; | @@ -2,56 +2,96 @@ import 'get_utils.dart'; | ||
| 2 | 2 | ||
| 3 | extension GetStringUtils on String { | 3 | extension GetStringUtils on String { |
| 4 | bool get isNum => GetUtils.isNum(this); | 4 | bool get isNum => GetUtils.isNum(this); |
| 5 | + | ||
| 5 | bool get isNumericOnly => GetUtils.isNumericOnly(this); | 6 | bool get isNumericOnly => GetUtils.isNumericOnly(this); |
| 7 | + | ||
| 6 | bool get isAlphabetOnly => GetUtils.isAlphabetOnly(this); | 8 | bool get isAlphabetOnly => GetUtils.isAlphabetOnly(this); |
| 9 | + | ||
| 7 | bool get isBool => GetUtils.isBool(this); | 10 | bool get isBool => GetUtils.isBool(this); |
| 11 | + | ||
| 8 | bool get isVectorFileName => GetUtils.isVector(this); | 12 | bool get isVectorFileName => GetUtils.isVector(this); |
| 13 | + | ||
| 9 | bool get isImageFileName => GetUtils.isImage(this); | 14 | bool get isImageFileName => GetUtils.isImage(this); |
| 15 | + | ||
| 10 | bool get isAudioFileName => GetUtils.isAudio(this); | 16 | bool get isAudioFileName => GetUtils.isAudio(this); |
| 17 | + | ||
| 11 | bool get isVideoFileName => GetUtils.isVideo(this); | 18 | bool get isVideoFileName => GetUtils.isVideo(this); |
| 19 | + | ||
| 12 | bool get isTxtFileName => GetUtils.isTxt(this); | 20 | bool get isTxtFileName => GetUtils.isTxt(this); |
| 21 | + | ||
| 13 | bool get isDocumentFileName => GetUtils.isWord(this); | 22 | bool get isDocumentFileName => GetUtils.isWord(this); |
| 23 | + | ||
| 14 | bool get isExcelFileName => GetUtils.isExcel(this); | 24 | bool get isExcelFileName => GetUtils.isExcel(this); |
| 25 | + | ||
| 15 | bool get isPPTFileName => GetUtils.isPPT(this); | 26 | bool get isPPTFileName => GetUtils.isPPT(this); |
| 27 | + | ||
| 16 | bool get isAPKFileName => GetUtils.isAPK(this); | 28 | bool get isAPKFileName => GetUtils.isAPK(this); |
| 29 | + | ||
| 17 | bool get isPDFFileName => GetUtils.isPDF(this); | 30 | bool get isPDFFileName => GetUtils.isPDF(this); |
| 31 | + | ||
| 18 | bool get isHTMLFileName => GetUtils.isHTML(this); | 32 | bool get isHTMLFileName => GetUtils.isHTML(this); |
| 33 | + | ||
| 19 | bool get isURL => GetUtils.isURL(this); | 34 | bool get isURL => GetUtils.isURL(this); |
| 35 | + | ||
| 20 | bool get isEmail => GetUtils.isEmail(this); | 36 | bool get isEmail => GetUtils.isEmail(this); |
| 37 | + | ||
| 21 | bool get isPhoneNumber => GetUtils.isPhoneNumber(this); | 38 | bool get isPhoneNumber => GetUtils.isPhoneNumber(this); |
| 39 | + | ||
| 22 | bool get isDateTime => GetUtils.isDateTime(this); | 40 | bool get isDateTime => GetUtils.isDateTime(this); |
| 41 | + | ||
| 23 | bool get isMD5 => GetUtils.isMD5(this); | 42 | bool get isMD5 => GetUtils.isMD5(this); |
| 43 | + | ||
| 24 | bool get isSHA1 => GetUtils.isSHA1(this); | 44 | bool get isSHA1 => GetUtils.isSHA1(this); |
| 45 | + | ||
| 25 | bool get isSHA256 => GetUtils.isSHA256(this); | 46 | bool get isSHA256 => GetUtils.isSHA256(this); |
| 47 | + | ||
| 26 | bool get isBinary => GetUtils.isBinary(this); | 48 | bool get isBinary => GetUtils.isBinary(this); |
| 49 | + | ||
| 27 | bool get isIPv4 => GetUtils.isIPv4(this); | 50 | bool get isIPv4 => GetUtils.isIPv4(this); |
| 51 | + | ||
| 28 | bool get isIPv6 => GetUtils.isIPv6(this); | 52 | bool get isIPv6 => GetUtils.isIPv6(this); |
| 53 | + | ||
| 29 | bool get isHexadecimal => GetUtils.isHexadecimal(this); | 54 | bool get isHexadecimal => GetUtils.isHexadecimal(this); |
| 55 | + | ||
| 30 | bool get isPalindrom => GetUtils.isPalindrom(this); | 56 | bool get isPalindrom => GetUtils.isPalindrom(this); |
| 57 | + | ||
| 31 | bool get isPassport => GetUtils.isPassport(this); | 58 | bool get isPassport => GetUtils.isPassport(this); |
| 59 | + | ||
| 32 | bool get isCurrency => GetUtils.isCurrency(this); | 60 | bool get isCurrency => GetUtils.isCurrency(this); |
| 61 | + | ||
| 33 | bool isCpf(String s) => GetUtils.isCpf(this); | 62 | bool isCpf(String s) => GetUtils.isCpf(this); |
| 63 | + | ||
| 34 | bool isCnpj(String s) => GetUtils.isCnpj(this); | 64 | bool isCnpj(String s) => GetUtils.isCnpj(this); |
| 65 | + | ||
| 35 | bool isCaseInsensitiveContains(String b) => | 66 | bool isCaseInsensitiveContains(String b) => |
| 36 | GetUtils.isCaseInsensitiveContains(this, b); | 67 | GetUtils.isCaseInsensitiveContains(this, b); |
| 68 | + | ||
| 37 | bool isCaseInsensitiveContainsAny(String b) => | 69 | bool isCaseInsensitiveContainsAny(String b) => |
| 38 | GetUtils.isCaseInsensitiveContainsAny(this, b); | 70 | GetUtils.isCaseInsensitiveContainsAny(this, b); |
| 71 | + | ||
| 39 | String capitalize(String s, {bool firstOnly = false}) => | 72 | String capitalize(String s, {bool firstOnly = false}) => |
| 40 | GetUtils.capitalize(this, firstOnly: firstOnly); | 73 | GetUtils.capitalize(this, firstOnly: firstOnly); |
| 74 | + | ||
| 41 | String capitalizeFirst(String s) => GetUtils.capitalizeFirst(this); | 75 | String capitalizeFirst(String s) => GetUtils.capitalizeFirst(this); |
| 76 | + | ||
| 42 | String removeAllWhitespace(String s) => GetUtils.removeAllWhitespace(this); | 77 | String removeAllWhitespace(String s) => GetUtils.removeAllWhitespace(this); |
| 78 | + | ||
| 43 | String camelCase(String s) => GetUtils.camelCase(this); | 79 | String camelCase(String s) => GetUtils.camelCase(this); |
| 80 | + | ||
| 44 | String numericOnly(String s, {bool firstWordOnly = false}) => | 81 | String numericOnly(String s, {bool firstWordOnly = false}) => |
| 45 | GetUtils.numericOnly(this, firstWordOnly: firstWordOnly); | 82 | GetUtils.numericOnly(this, firstWordOnly: firstWordOnly); |
| 46 | } | 83 | } |
| 47 | 84 | ||
| 48 | extension GetNumUtils on num { | 85 | extension GetNumUtils on num { |
| 49 | bool isLowerThan(num b) => GetUtils.isLowerThan(this, b); | 86 | bool isLowerThan(num b) => GetUtils.isLowerThan(this, b); |
| 87 | + | ||
| 50 | bool isGreaterThan(num b) => GetUtils.isGreaterThan(this, b); | 88 | bool isGreaterThan(num b) => GetUtils.isGreaterThan(this, b); |
| 89 | + | ||
| 51 | bool isEqual(num b) => GetUtils.isEqual(this, b); | 90 | bool isEqual(num b) => GetUtils.isEqual(this, b); |
| 52 | } | 91 | } |
| 53 | 92 | ||
| 54 | extension GetDynamicUtils on dynamic { | 93 | extension GetDynamicUtils on dynamic { |
| 55 | bool get isNull => GetUtils.isNull(this); | 94 | bool get isNull => GetUtils.isNull(this); |
| 95 | + | ||
| 56 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); | 96 | bool get isNullOrBlank => GetUtils.isNullOrBlank(this); |
| 57 | } | 97 | } |
| 1 | -export 'src/state_manager/simple/get_state.dart'; | ||
| 2 | -export 'src/state_manager/simple/immutable_state.dart'; | ||
| 3 | -export 'src/state_manager/simple/get_view.dart'; | ||
| 4 | -export 'src/state_manager/simple/simple_builder.dart'; | ||
| 5 | -export 'src/state_manager/simple/mixin_state.dart'; | ||
| 6 | -export 'src/state_manager/rx/rx_core/rx_interface.dart'; | ||
| 7 | export 'src/state_manager/rx/rx_core/rx_impl.dart'; | 1 | export 'src/state_manager/rx/rx_core/rx_impl.dart'; |
| 2 | +export 'src/state_manager/rx/rx_core/rx_interface.dart'; | ||
| 8 | export 'src/state_manager/rx/rx_iterables/rx_list.dart'; | 3 | export 'src/state_manager/rx/rx_iterables/rx_list.dart'; |
| 9 | export 'src/state_manager/rx/rx_iterables/rx_map.dart'; | 4 | export 'src/state_manager/rx/rx_iterables/rx_map.dart'; |
| 10 | export 'src/state_manager/rx/rx_iterables/rx_set.dart'; | 5 | export 'src/state_manager/rx/rx_iterables/rx_set.dart'; |
| 11 | -export 'src/state_manager/rx/rx_workers/rx_workers.dart'; | ||
| 12 | -export 'src/state_manager/rx/rx_widgets/rx_obx_widget.dart'; | ||
| 13 | export 'src/state_manager/rx/rx_widgets/rx_getx_widget.dart'; | 6 | export 'src/state_manager/rx/rx_widgets/rx_getx_widget.dart'; |
| 7 | +export 'src/state_manager/rx/rx_widgets/rx_obx_widget.dart'; | ||
| 8 | +export 'src/state_manager/rx/rx_workers/rx_workers.dart'; | ||
| 9 | +export 'src/state_manager/simple/get_state.dart'; | ||
| 10 | +export 'src/state_manager/simple/get_view.dart'; | ||
| 11 | +export 'src/state_manager/simple/immutable_state.dart'; | ||
| 12 | +export 'src/state_manager/simple/mixin_state.dart'; | ||
| 13 | +export 'src/state_manager/simple/simple_builder.dart'; |
| 1 | export 'src/utils/extensions/export.dart'; | 1 | export 'src/utils/extensions/export.dart'; |
| 2 | -export 'src/utils/queue/get_queue.dart'; | ||
| 3 | export 'src/utils/platform/platform.dart'; | 2 | export 'src/utils/platform/platform.dart'; |
| 3 | +export 'src/utils/queue/get_queue.dart'; | ||
| 4 | export 'src/utils/regex/get_utils.dart'; | 4 | export 'src/utils/regex/get_utils.dart'; |
| @@ -43,6 +43,13 @@ packages: | @@ -43,6 +43,13 @@ packages: | ||
| 43 | url: "https://pub.dartlang.org" | 43 | url: "https://pub.dartlang.org" |
| 44 | source: hosted | 44 | source: hosted |
| 45 | version: "1.15.0-nullsafety.2" | 45 | version: "1.15.0-nullsafety.2" |
| 46 | + effective_dart: | ||
| 47 | + dependency: "direct dev" | ||
| 48 | + description: | ||
| 49 | + name: effective_dart | ||
| 50 | + url: "https://pub.dartlang.org" | ||
| 51 | + source: hosted | ||
| 52 | + version: "1.2.4" | ||
| 46 | fake_async: | 53 | fake_async: |
| 47 | dependency: transitive | 54 | dependency: transitive |
| 48 | description: | 55 | description: |
| @@ -13,6 +13,7 @@ dependencies: | @@ -13,6 +13,7 @@ dependencies: | ||
| 13 | dev_dependencies: | 13 | dev_dependencies: |
| 14 | flutter_test: | 14 | flutter_test: |
| 15 | sdk: flutter | 15 | sdk: flutter |
| 16 | + effective_dart: ^1.0.0 | ||
| 16 | 17 | ||
| 17 | # For information on the generic Dart part of this file, see the | 18 | # For information on the generic Dart part of this file, see the |
| 18 | # following page: https://dart.dev/tools/pub/pubspec | 19 | # following page: https://dart.dev/tools/pub/pubspec |
| @@ -61,12 +61,13 @@ void main() { | @@ -61,12 +61,13 @@ void main() { | ||
| 61 | 61 | ||
| 62 | testWidgets( | 62 | testWidgets( |
| 63 | "GetMaterialApp with debugShowMaterialGrid null", | 63 | "GetMaterialApp with debugShowMaterialGrid null", |
| 64 | - (WidgetTester testr) async { | 64 | + (tester) async { |
| 65 | expect( | 65 | expect( |
| 66 | () => GetMaterialApp( | 66 | () => GetMaterialApp( |
| 67 | debugShowMaterialGrid: null, | 67 | debugShowMaterialGrid: null, |
| 68 | ), | 68 | ), |
| 69 | - throwsAssertionError); | 69 | + throwsAssertionError, |
| 70 | + ); | ||
| 70 | }, | 71 | }, |
| 71 | ); | 72 | ); |
| 72 | } | 73 | } |
| 1 | import 'package:flutter_test/flutter_test.dart'; | 1 | import 'package:flutter_test/flutter_test.dart'; |
| 2 | import 'package:get/get.dart'; | 2 | import 'package:get/get.dart'; |
| 3 | + | ||
| 3 | import 'util/matcher.dart'; | 4 | import 'util/matcher.dart'; |
| 4 | 5 | ||
| 5 | class Mock { | 6 | class Mock { |
| @@ -19,6 +20,7 @@ class DisposableController extends DisposableInterface { | @@ -19,6 +20,7 @@ class DisposableController extends DisposableInterface { | ||
| 19 | } | 20 | } |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 23 | +// ignore: one_member_abstracts | ||
| 22 | abstract class Service { | 24 | abstract class Service { |
| 23 | String post(); | 25 | String post(); |
| 24 | } | 26 | } |
| @@ -32,7 +34,7 @@ class Api implements Service { | @@ -32,7 +34,7 @@ class Api implements Service { | ||
| 32 | 34 | ||
| 33 | void main() { | 35 | void main() { |
| 34 | test('Get.putAsync test', () async { | 36 | test('Get.putAsync test', () async { |
| 35 | - await Get.putAsync<String>(() => Mock.test()); | 37 | + await Get.putAsync<String>(Mock.test); |
| 36 | expect('test', Get.find<String>()); | 38 | expect('test', Get.find<String>()); |
| 37 | Get.reset(); | 39 | Get.reset(); |
| 38 | }); | 40 | }); |
| @@ -70,9 +72,7 @@ void main() { | @@ -70,9 +72,7 @@ void main() { | ||
| 70 | }); | 72 | }); |
| 71 | 73 | ||
| 72 | group('test put, delete and check onInit execution', () { | 74 | group('test put, delete and check onInit execution', () { |
| 73 | - tearDownAll(() { | ||
| 74 | - Get.reset(); | ||
| 75 | - }); | 75 | + tearDownAll(Get.reset); |
| 76 | 76 | ||
| 77 | test('Get.put test with init check', () async { | 77 | test('Get.put test with init check', () async { |
| 78 | final instance = Get.put<DisposableController>(DisposableController()); | 78 | final instance = Get.put<DisposableController>(DisposableController()); |
| @@ -202,8 +202,9 @@ void main() { | @@ -202,8 +202,9 @@ void main() { | ||
| 202 | expect(find.byType(FirstScreen), findsOneWidget); | 202 | expect(find.byType(FirstScreen), findsOneWidget); |
| 203 | 203 | ||
| 204 | Get.offUntil( | 204 | Get.offUntil( |
| 205 | - MaterialPageRoute(builder: (BuildContext context) => SecondScreen()), | ||
| 206 | - ModalRoute.withName('/')); | 205 | + MaterialPageRoute(builder: (context) => SecondScreen()), |
| 206 | + ModalRoute.withName('/'), | ||
| 207 | + ); | ||
| 207 | 208 | ||
| 208 | await tester.pumpAndSettle(); | 209 | await tester.pumpAndSettle(); |
| 209 | 210 |
| @@ -66,13 +66,14 @@ void main() { | @@ -66,13 +66,14 @@ void main() { | ||
| 66 | 66 | ||
| 67 | testWidgets( | 67 | testWidgets( |
| 68 | "MixinBuilder with build null", | 68 | "MixinBuilder with build null", |
| 69 | - (WidgetTester tester) async { | 69 | + (tester) async { |
| 70 | expect( | 70 | expect( |
| 71 | () => MixinBuilder<Controller>( | 71 | () => MixinBuilder<Controller>( |
| 72 | init: Controller(), | 72 | init: Controller(), |
| 73 | builder: null, | 73 | builder: null, |
| 74 | ), | 74 | ), |
| 75 | - throwsAssertionError); | 75 | + throwsAssertionError, |
| 76 | + ); | ||
| 76 | }, | 77 | }, |
| 77 | ); | 78 | ); |
| 78 | } | 79 | } |
| @@ -80,12 +81,12 @@ void main() { | @@ -80,12 +81,12 @@ void main() { | ||
| 80 | class Controller extends GetxController { | 81 | class Controller extends GetxController { |
| 81 | static Controller get to => Get.find(); | 82 | static Controller get to => Get.find(); |
| 82 | int count = 0; | 83 | int count = 0; |
| 83 | - var counter = 0.obs; | ||
| 84 | - var doubleNum = 0.0.obs; | ||
| 85 | - var string = "string".obs; | ||
| 86 | - var list = [].obs; | ||
| 87 | - var map = {}.obs; | ||
| 88 | - var boolean = true.obs; | 84 | + RxInt counter = 0.obs; |
| 85 | + RxDouble doubleNum = 0.0.obs; | ||
| 86 | + RxString string = "string".obs; | ||
| 87 | + RxList list = [].obs; | ||
| 88 | + RxMap map = {}.obs; | ||
| 89 | + RxBool boolean = true.obs; | ||
| 89 | 90 | ||
| 90 | void increment() { | 91 | void increment() { |
| 91 | counter.value++; | 92 | counter.value++; |
| @@ -3,7 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; | @@ -3,7 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; | ||
| 3 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
| 4 | 4 | ||
| 5 | void main() { | 5 | void main() { |
| 6 | - Controller controller = Get.put<Controller>(Controller()); | 6 | + final controller = Get.put(Controller()); |
| 7 | testWidgets("GetxController smoke test", (tester) async { | 7 | testWidgets("GetxController smoke test", (tester) async { |
| 8 | await tester.pumpWidget( | 8 | await tester.pumpWidget( |
| 9 | MaterialApp( | 9 | MaterialApp( |
| @@ -11,31 +11,17 @@ void main() { | @@ -11,31 +11,17 @@ void main() { | ||
| 11 | children: [ | 11 | children: [ |
| 12 | Obx( | 12 | Obx( |
| 13 | () => Column(children: [ | 13 | () => Column(children: [ |
| 14 | - Text( | ||
| 15 | - 'Count: ${controller.counter.value}', | ||
| 16 | - ), | ||
| 17 | - Text( | ||
| 18 | - 'Double: ${controller.doubleNum.value}', | ||
| 19 | - ), | ||
| 20 | - Text( | ||
| 21 | - 'String: ${controller.string.value}', | ||
| 22 | - ), | ||
| 23 | - Text( | ||
| 24 | - 'List: ${controller.list.length}', | ||
| 25 | - ), | ||
| 26 | - Text( | ||
| 27 | - 'Bool: ${controller.boolean.value}', | ||
| 28 | - ), | ||
| 29 | - Text( | ||
| 30 | - 'Map: ${controller.map.length}', | ||
| 31 | - ), | 14 | + Text('Count: ${controller.counter.value}'), |
| 15 | + Text('Double: ${controller.doubleNum.value}'), | ||
| 16 | + Text('String: ${controller.string.value}'), | ||
| 17 | + Text('List: ${controller.list.length}'), | ||
| 18 | + Text('Bool: ${controller.boolean.value}'), | ||
| 19 | + Text('Map: ${controller.map.length}'), | ||
| 32 | FlatButton( | 20 | FlatButton( |
| 33 | child: Text("increment"), | 21 | child: Text("increment"), |
| 34 | - onPressed: () => controller.increment(), | 22 | + onPressed: controller.increment, |
| 35 | ), | 23 | ), |
| 36 | - Obx(() => Text( | ||
| 37 | - 'Obx: ${controller.map.length}', | ||
| 38 | - )) | 24 | + Obx(() => Text('Obx: ${controller.map.length}')) |
| 39 | ]), | 25 | ]), |
| 40 | ), | 26 | ), |
| 41 | ], | 27 | ], |
| @@ -68,12 +54,12 @@ void main() { | @@ -68,12 +54,12 @@ void main() { | ||
| 68 | class Controller extends GetxController { | 54 | class Controller extends GetxController { |
| 69 | static Controller get to => Get.find(); | 55 | static Controller get to => Get.find(); |
| 70 | 56 | ||
| 71 | - var counter = 0.obs; | ||
| 72 | - var doubleNum = 0.0.obs; | ||
| 73 | - var string = "string".obs; | ||
| 74 | - var list = [].obs; | ||
| 75 | - var map = {}.obs; | ||
| 76 | - var boolean = true.obs; | 57 | + RxInt counter = 0.obs; |
| 58 | + RxDouble doubleNum = 0.0.obs; | ||
| 59 | + RxString string = "string".obs; | ||
| 60 | + RxList list = [].obs; | ||
| 61 | + RxMap map = {}.obs; | ||
| 62 | + RxBool boolean = true.obs; | ||
| 77 | 63 | ||
| 78 | void increment() { | 64 | void increment() { |
| 79 | counter.value++; | 65 | counter.value++; |
| @@ -74,22 +74,22 @@ void main() { | @@ -74,22 +74,22 @@ void main() { | ||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | class Controller2 extends GetxController { | 76 | class Controller2 extends GetxController { |
| 77 | - var lazy = 0.obs; | 77 | + RxInt lazy = 0.obs; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | class ControllerNonGlobal extends GetxController { | 80 | class ControllerNonGlobal extends GetxController { |
| 81 | - var nonGlobal = 0.obs; | 81 | + RxInt nonGlobal = 0.obs; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | class Controller extends GetxController { | 84 | class Controller extends GetxController { |
| 85 | static Controller get to => Get.find(); | 85 | static Controller get to => Get.find(); |
| 86 | 86 | ||
| 87 | - var counter = 0.obs; | ||
| 88 | - var doubleNum = 0.0.obs; | ||
| 89 | - var string = "string".obs; | ||
| 90 | - var list = [].obs; | ||
| 91 | - var map = {}.obs; | ||
| 92 | - var boolean = true.obs; | 87 | + RxInt counter = 0.obs; |
| 88 | + RxDouble doubleNum = 0.0.obs; | ||
| 89 | + RxString string = "string".obs; | ||
| 90 | + RxList list = [].obs; | ||
| 91 | + RxMap map = {}.obs; | ||
| 92 | + RxBool boolean = true.obs; | ||
| 93 | 93 | ||
| 94 | void increment() { | 94 | void increment() { |
| 95 | counter.value++; | 95 | counter.value++; |
| @@ -70,13 +70,14 @@ void main() { | @@ -70,13 +70,14 @@ void main() { | ||
| 70 | 70 | ||
| 71 | testWidgets( | 71 | testWidgets( |
| 72 | "MixinBuilder with build null", | 72 | "MixinBuilder with build null", |
| 73 | - (WidgetTester test) async { | 73 | + (test) async { |
| 74 | expect( | 74 | expect( |
| 75 | () => GetBuilder<Controller>( | 75 | () => GetBuilder<Controller>( |
| 76 | init: Controller(), | 76 | init: Controller(), |
| 77 | builder: null, | 77 | builder: null, |
| 78 | ), | 78 | ), |
| 79 | - throwsAssertionError); | 79 | + throwsAssertionError, |
| 80 | + ); | ||
| 80 | }, | 81 | }, |
| 81 | ); | 82 | ); |
| 82 | } | 83 | } |
| @@ -85,6 +86,7 @@ class Controller extends GetxController { | @@ -85,6 +86,7 @@ class Controller extends GetxController { | ||
| 85 | static Controller get to => Get.find(); | 86 | static Controller get to => Get.find(); |
| 86 | 87 | ||
| 87 | int counter = 0; | 88 | int counter = 0; |
| 89 | + | ||
| 88 | void increment() { | 90 | void increment() { |
| 89 | counter++; | 91 | counter++; |
| 90 | update(); | 92 | update(); |
| @@ -4,7 +4,7 @@ import 'package:get/get.dart'; | @@ -4,7 +4,7 @@ import 'package:get/get.dart'; | ||
| 4 | void main() { | 4 | void main() { |
| 5 | testWidgets( | 5 | testWidgets( |
| 6 | "GetMaterialApp with routes null", | 6 | "GetMaterialApp with routes null", |
| 7 | - (WidgetTester testr) async { | 7 | + (tester) async { |
| 8 | expect( | 8 | expect( |
| 9 | () => GetMaterialApp( | 9 | () => GetMaterialApp( |
| 10 | routes: null, | 10 | routes: null, |
| @@ -15,7 +15,7 @@ void main() { | @@ -15,7 +15,7 @@ void main() { | ||
| 15 | 15 | ||
| 16 | testWidgets( | 16 | testWidgets( |
| 17 | "GetMaterialApp with navigatorObservers null", | 17 | "GetMaterialApp with navigatorObservers null", |
| 18 | - (WidgetTester testr) async { | 18 | + (tester) async { |
| 19 | expect( | 19 | expect( |
| 20 | () => GetMaterialApp( | 20 | () => GetMaterialApp( |
| 21 | navigatorObservers: null, | 21 | navigatorObservers: null, |
| @@ -25,7 +25,7 @@ void main() { | @@ -25,7 +25,7 @@ void main() { | ||
| 25 | ); | 25 | ); |
| 26 | testWidgets( | 26 | testWidgets( |
| 27 | "GetMaterialApp with title null", | 27 | "GetMaterialApp with title null", |
| 28 | - (WidgetTester testr) async { | 28 | + (tester) async { |
| 29 | expect( | 29 | expect( |
| 30 | () => GetMaterialApp( | 30 | () => GetMaterialApp( |
| 31 | title: null, | 31 | title: null, |
| @@ -35,37 +35,40 @@ void main() { | @@ -35,37 +35,40 @@ void main() { | ||
| 35 | ); | 35 | ); |
| 36 | testWidgets( | 36 | testWidgets( |
| 37 | "GetMaterialApp with debugShowMaterialGrid null", | 37 | "GetMaterialApp with debugShowMaterialGrid null", |
| 38 | - (WidgetTester testr) async { | 38 | + (test) async { |
| 39 | expect( | 39 | expect( |
| 40 | () => GetMaterialApp( | 40 | () => GetMaterialApp( |
| 41 | debugShowMaterialGrid: null, | 41 | debugShowMaterialGrid: null, |
| 42 | ), | 42 | ), |
| 43 | - throwsAssertionError); | 43 | + throwsAssertionError, |
| 44 | + ); | ||
| 44 | }, | 45 | }, |
| 45 | ); | 46 | ); |
| 46 | testWidgets( | 47 | testWidgets( |
| 47 | "GetMaterialApp with showPerformanceOverlay null", | 48 | "GetMaterialApp with showPerformanceOverlay null", |
| 48 | - (WidgetTester testr) async { | 49 | + (test) async { |
| 49 | expect( | 50 | expect( |
| 50 | () => GetMaterialApp( | 51 | () => GetMaterialApp( |
| 51 | showPerformanceOverlay: null, | 52 | showPerformanceOverlay: null, |
| 52 | ), | 53 | ), |
| 53 | - throwsAssertionError); | 54 | + throwsAssertionError, |
| 55 | + ); | ||
| 54 | }, | 56 | }, |
| 55 | ); | 57 | ); |
| 56 | testWidgets( | 58 | testWidgets( |
| 57 | "GetMaterialApp with showSemanticsDebugger null", | 59 | "GetMaterialApp with showSemanticsDebugger null", |
| 58 | - (WidgetTester testr) async { | 60 | + (test) async { |
| 59 | expect( | 61 | expect( |
| 60 | () => GetMaterialApp( | 62 | () => GetMaterialApp( |
| 61 | showSemanticsDebugger: null, | 63 | showSemanticsDebugger: null, |
| 62 | ), | 64 | ), |
| 63 | - throwsAssertionError); | 65 | + throwsAssertionError, |
| 66 | + ); | ||
| 64 | }, | 67 | }, |
| 65 | ); | 68 | ); |
| 66 | testWidgets( | 69 | testWidgets( |
| 67 | "GetMaterialApp with debugShowCheckedModeBanner null", | 70 | "GetMaterialApp with debugShowCheckedModeBanner null", |
| 68 | - (WidgetTester testr) async { | 71 | + (tester) async { |
| 69 | expect( | 72 | expect( |
| 70 | () => GetMaterialApp( | 73 | () => GetMaterialApp( |
| 71 | debugShowCheckedModeBanner: null, | 74 | debugShowCheckedModeBanner: null, |
| @@ -76,7 +79,7 @@ void main() { | @@ -76,7 +79,7 @@ void main() { | ||
| 76 | 79 | ||
| 77 | testWidgets( | 80 | testWidgets( |
| 78 | "GetMaterialApp with checkerboardRasterCacheImages null", | 81 | "GetMaterialApp with checkerboardRasterCacheImages null", |
| 79 | - (WidgetTester testr) async { | 82 | + (tester) async { |
| 80 | expect( | 83 | expect( |
| 81 | () => GetMaterialApp( | 84 | () => GetMaterialApp( |
| 82 | checkerboardRasterCacheImages: null, | 85 | checkerboardRasterCacheImages: null, |
| @@ -87,12 +90,13 @@ void main() { | @@ -87,12 +90,13 @@ void main() { | ||
| 87 | 90 | ||
| 88 | testWidgets( | 91 | testWidgets( |
| 89 | "GetMaterialApp with checkerboardOffscreenLayers null", | 92 | "GetMaterialApp with checkerboardOffscreenLayers null", |
| 90 | - (WidgetTester testr) async { | 93 | + (tester) async { |
| 91 | expect( | 94 | expect( |
| 92 | () => GetMaterialApp( | 95 | () => GetMaterialApp( |
| 93 | checkerboardOffscreenLayers: null, | 96 | checkerboardOffscreenLayers: null, |
| 94 | ), | 97 | ), |
| 95 | - throwsAssertionError); | 98 | + throwsAssertionError, |
| 99 | + ); | ||
| 96 | }, | 100 | }, |
| 97 | ); | 101 | ); |
| 98 | } | 102 | } |
| @@ -5,37 +5,39 @@ import 'package:get/src/navigation/routes/get_route.dart'; | @@ -5,37 +5,39 @@ import 'package:get/src/navigation/routes/get_route.dart'; | ||
| 5 | void main() { | 5 | void main() { |
| 6 | testWidgets( | 6 | testWidgets( |
| 7 | 'GetPage page null', | 7 | 'GetPage page null', |
| 8 | - (WidgetTester testr) async { | 8 | + (tester) async { |
| 9 | expect(() => GetPage(page: null, name: null), throwsAssertionError); | 9 | expect(() => GetPage(page: null, name: null), throwsAssertionError); |
| 10 | }, | 10 | }, |
| 11 | ); | 11 | ); |
| 12 | 12 | ||
| 13 | testWidgets( | 13 | testWidgets( |
| 14 | "GetPage maintainState null", | 14 | "GetPage maintainState null", |
| 15 | - (WidgetTester testr) async { | 15 | + (tester) async { |
| 16 | expect( | 16 | expect( |
| 17 | () => GetPage(page: () => Scaffold(), maintainState: null, name: '/'), | 17 | () => GetPage(page: () => Scaffold(), maintainState: null, name: '/'), |
| 18 | - throwsAssertionError); | 18 | + throwsAssertionError, |
| 19 | + ); | ||
| 19 | }, | 20 | }, |
| 20 | ); | 21 | ); |
| 21 | 22 | ||
| 22 | testWidgets( | 23 | testWidgets( |
| 23 | "GetPage name null", | 24 | "GetPage name null", |
| 24 | - (WidgetTester testr) async { | 25 | + (tester) async { |
| 25 | expect( | 26 | expect( |
| 26 | - () => | ||
| 27 | - GetPage(page: () => Scaffold(), maintainState: null, name: null), | ||
| 28 | - throwsAssertionError); | 27 | + () => GetPage(page: () => Scaffold(), maintainState: null, name: null), |
| 28 | + throwsAssertionError, | ||
| 29 | + ); | ||
| 29 | }, | 30 | }, |
| 30 | ); | 31 | ); |
| 31 | 32 | ||
| 32 | testWidgets( | 33 | testWidgets( |
| 33 | "GetPage fullscreenDialog null", | 34 | "GetPage fullscreenDialog null", |
| 34 | - (WidgetTester testr) async { | 35 | + (tester) async { |
| 35 | expect( | 36 | expect( |
| 36 | - () => GetPage( | ||
| 37 | - page: () => Scaffold(), fullscreenDialog: null, name: '/'), | ||
| 38 | - throwsAssertionError); | 37 | + () => |
| 38 | + GetPage(page: () => Scaffold(), fullscreenDialog: null, name: '/'), | ||
| 39 | + throwsAssertionError, | ||
| 40 | + ); | ||
| 39 | }, | 41 | }, |
| 40 | ); | 42 | ); |
| 41 | } | 43 | } |
| @@ -3,7 +3,7 @@ import 'package:get/utils.dart'; | @@ -3,7 +3,7 @@ import 'package:get/utils.dart'; | ||
| 3 | 3 | ||
| 4 | void main() { | 4 | void main() { |
| 5 | test('Test for toPrecision on Double', () { | 5 | test('Test for toPrecision on Double', () { |
| 6 | - double testVar = 5.4545454; | 6 | + var testVar = 5.4545454; |
| 7 | expect(testVar.toPrecision(2), equals(5.45)); | 7 | expect(testVar.toPrecision(2), equals(5.45)); |
| 8 | }); | 8 | }); |
| 9 | } | 9 | } |
| @@ -4,7 +4,7 @@ import 'package:get/utils.dart'; | @@ -4,7 +4,7 @@ import 'package:get/utils.dart'; | ||
| 4 | 4 | ||
| 5 | void main() { | 5 | void main() { |
| 6 | group('Group test for PaddingX Extension', () { | 6 | group('Group test for PaddingX Extension', () { |
| 7 | - testWidgets('Test of paddingAll', (WidgetTester tester) async { | 7 | + testWidgets('Test of paddingAll', (tester) async { |
| 8 | Widget containerTest; | 8 | Widget containerTest; |
| 9 | 9 | ||
| 10 | expect(find.byType(Padding), findsNothing); | 10 | expect(find.byType(Padding), findsNothing); |
| @@ -14,7 +14,7 @@ void main() { | @@ -14,7 +14,7 @@ void main() { | ||
| 14 | expect(find.byType(Padding), findsOneWidget); | 14 | expect(find.byType(Padding), findsOneWidget); |
| 15 | }); | 15 | }); |
| 16 | 16 | ||
| 17 | - testWidgets('Test of paddingOnly', (WidgetTester tester) async { | 17 | + testWidgets('Test of paddingOnly', (tester) async { |
| 18 | Widget containerTest; | 18 | Widget containerTest; |
| 19 | 19 | ||
| 20 | expect(find.byType(Padding), findsNothing); | 20 | expect(find.byType(Padding), findsNothing); |
| @@ -24,7 +24,7 @@ void main() { | @@ -24,7 +24,7 @@ void main() { | ||
| 24 | expect(find.byType(Padding), findsOneWidget); | 24 | expect(find.byType(Padding), findsOneWidget); |
| 25 | }); | 25 | }); |
| 26 | 26 | ||
| 27 | - testWidgets('Test of paddingSymmetric', (WidgetTester tester) async { | 27 | + testWidgets('Test of paddingSymmetric', (tester) async { |
| 28 | Widget containerTest; | 28 | Widget containerTest; |
| 29 | 29 | ||
| 30 | expect(find.byType(Padding), findsNothing); | 30 | expect(find.byType(Padding), findsNothing); |
| @@ -34,7 +34,7 @@ void main() { | @@ -34,7 +34,7 @@ void main() { | ||
| 34 | expect(find.byType(Padding), findsOneWidget); | 34 | expect(find.byType(Padding), findsOneWidget); |
| 35 | }); | 35 | }); |
| 36 | 36 | ||
| 37 | - testWidgets('Test of paddingZero', (WidgetTester tester) async { | 37 | + testWidgets('Test of paddingZero', (tester) async { |
| 38 | Widget containerTest; | 38 | Widget containerTest; |
| 39 | 39 | ||
| 40 | expect(find.byType(Padding), findsNothing); | 40 | expect(find.byType(Padding), findsNothing); |
| @@ -46,7 +46,7 @@ void main() { | @@ -46,7 +46,7 @@ void main() { | ||
| 46 | }); | 46 | }); |
| 47 | 47 | ||
| 48 | group('Group test for MarginX Extension', () { | 48 | group('Group test for MarginX Extension', () { |
| 49 | - testWidgets('Test of marginAll', (WidgetTester tester) async { | 49 | + testWidgets('Test of marginAll', (tester) async { |
| 50 | Widget containerTest; | 50 | Widget containerTest; |
| 51 | 51 | ||
| 52 | await tester.pumpWidget(containerTest.marginAll(16)); | 52 | await tester.pumpWidget(containerTest.marginAll(16)); |
| @@ -54,7 +54,7 @@ void main() { | @@ -54,7 +54,7 @@ void main() { | ||
| 54 | expect(find.byType(Container), findsOneWidget); | 54 | expect(find.byType(Container), findsOneWidget); |
| 55 | }); | 55 | }); |
| 56 | 56 | ||
| 57 | - testWidgets('Test of marginOnly', (WidgetTester tester) async { | 57 | + testWidgets('Test of marginOnly', (tester) async { |
| 58 | Widget containerTest; | 58 | Widget containerTest; |
| 59 | 59 | ||
| 60 | await tester.pumpWidget(containerTest.marginOnly(top: 16)); | 60 | await tester.pumpWidget(containerTest.marginOnly(top: 16)); |
| @@ -62,7 +62,7 @@ void main() { | @@ -62,7 +62,7 @@ void main() { | ||
| 62 | expect(find.byType(Container), findsOneWidget); | 62 | expect(find.byType(Container), findsOneWidget); |
| 63 | }); | 63 | }); |
| 64 | 64 | ||
| 65 | - testWidgets('Test of marginSymmetric', (WidgetTester tester) async { | 65 | + testWidgets('Test of marginSymmetric', (tester) async { |
| 66 | Widget containerTest; | 66 | Widget containerTest; |
| 67 | 67 | ||
| 68 | await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16)); | 68 | await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16)); |
| @@ -70,7 +70,7 @@ void main() { | @@ -70,7 +70,7 @@ void main() { | ||
| 70 | expect(find.byType(Container), findsOneWidget); | 70 | expect(find.byType(Container), findsOneWidget); |
| 71 | }); | 71 | }); |
| 72 | 72 | ||
| 73 | - testWidgets('Test of marginZero', (WidgetTester tester) async { | 73 | + testWidgets('Test of marginZero', (tester) async { |
| 74 | Widget containerTest; | 74 | Widget containerTest; |
| 75 | 75 | ||
| 76 | await tester.pumpWidget(containerTest.marginZero); | 76 | await tester.pumpWidget(containerTest.marginZero); |
| @@ -56,7 +56,7 @@ class HavingMatcher<T> implements TypeMatcher<T> { | @@ -56,7 +56,7 @@ class HavingMatcher<T> implements TypeMatcher<T> { | ||
| 56 | HavingMatcher(_parent, description, feature, matcher, _functionMatchers); | 56 | HavingMatcher(_parent, description, feature, matcher, _functionMatchers); |
| 57 | 57 | ||
| 58 | @override | 58 | @override |
| 59 | - bool matches(item, Map matchState) { | 59 | + bool matches(dynamic item, Map matchState) { |
| 60 | for (var matcher in <Matcher>[_parent].followedBy(_functionMatchers)) { | 60 | for (var matcher in <Matcher>[_parent].followedBy(_functionMatchers)) { |
| 61 | if (!matcher.matches(item, matchState)) { | 61 | if (!matcher.matches(item, matchState)) { |
| 62 | addStateInfo(matchState, {'matcher': matcher}); | 62 | addStateInfo(matchState, {'matcher': matcher}); |
| @@ -68,7 +68,11 @@ class HavingMatcher<T> implements TypeMatcher<T> { | @@ -68,7 +68,11 @@ class HavingMatcher<T> implements TypeMatcher<T> { | ||
| 68 | 68 | ||
| 69 | @override | 69 | @override |
| 70 | Description describeMismatch( | 70 | Description describeMismatch( |
| 71 | - item, Description mismatchDescription, Map matchState, bool verbose) { | 71 | + dynamic item, |
| 72 | + Description mismatchDescription, | ||
| 73 | + Map matchState, | ||
| 74 | + bool verbose, | ||
| 75 | + ) { | ||
| 72 | var matcher = matchState['matcher'] as Matcher; | 76 | var matcher = matchState['matcher'] as Matcher; |
| 73 | matcher.describeMismatch( | 77 | matcher.describeMismatch( |
| 74 | item, mismatchDescription, matchState['state'] as Map, verbose); | 78 | item, mismatchDescription, matchState['state'] as Map, verbose); |
| @@ -101,7 +105,11 @@ class TypeMatcher<T> extends Matcher { | @@ -101,7 +105,11 @@ class TypeMatcher<T> extends Matcher { | ||
| 101 | 105 | ||
| 102 | @override | 106 | @override |
| 103 | Description describeMismatch( | 107 | Description describeMismatch( |
| 104 | - item, Description mismatchDescription, Map matchState, bool verbose) { | 108 | + dynamic item, |
| 109 | + Description mismatchDescription, | ||
| 110 | + Map matchState, | ||
| 111 | + bool verbose, | ||
| 112 | + ) { | ||
| 105 | var name = _stripDynamic(T); | 113 | var name = _stripDynamic(T); |
| 106 | return mismatchDescription.add("is not an instance of '$name'"); | 114 | return mismatchDescription.add("is not an instance of '$name'"); |
| 107 | } | 115 | } |
-
Please register or login to post a comment