Jonny Borges

update to 4.0.0-nullsafety.2

  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: 60bd88df915880d23877bfc1602e8ddcf4c4dd2a
  8 + channel: stable
  9 +
  10 +project_type: app
  1 +## [4.0.0-nullsafety.2]
  2 +- Added append function to StateMixin. Now is possible track loading, success and error handle of your application with ONE LINE OF CODE. Ex: append(()=> api.getUser);
  3 +
1 ## [4.0.0-nullsafety.0] 4 ## [4.0.0-nullsafety.0]
2 - Migrate to null-safety 5 - Migrate to null-safety
3 - Added ScrollMixin to controllers 6 - Added ScrollMixin to controllers
@@ -5,11 +5,11 @@ import 'en_US.dart'; @@ -5,11 +5,11 @@ import 'en_US.dart';
5 import 'pt_BR.dart'; 5 import 'pt_BR.dart';
6 6
7 class TranslationService extends Translations { 7 class TranslationService extends Translations {
8 - static final locale = Get.deviceLocale; 8 + static Locale get locale => Get.deviceLocale!;
9 static final fallbackLocale = Locale('en', 'US'); 9 static final fallbackLocale = Locale('en', 'US');
10 - @override 10 + @override
11 Map<String, Map<String, String>> get keys => { 11 Map<String, Map<String, String>> get keys => {
12 - 'en_US': en_US,  
13 - 'pt_BR': pt_BR,  
14 - };  
15 -}  
  12 + 'en_US': en_US,
  13 + 'pt_BR': pt_BR,
  14 + };
  15 +}
  1 +import 'dart:ui';
  2 +
1 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
2 import 'package:get/get.dart'; 4 import 'package:get/get.dart';
3 import 'lang/translation_service.dart'; 5 import 'lang/translation_service.dart';
@@ -9,7 +11,7 @@ void main() { @@ -9,7 +11,7 @@ void main() {
9 } 11 }
10 12
11 class MyApp extends StatelessWidget { 13 class MyApp extends StatelessWidget {
12 - const MyApp({Key key}) : super(key: key); 14 + const MyApp({Key? key}) : super(key: key);
13 15
14 @override 16 @override
15 Widget build(BuildContext context) { 17 Widget build(BuildContext context) {
@@ -9,7 +9,8 @@ abstract class IHomeProvider { @@ -9,7 +9,8 @@ abstract class IHomeProvider {
9 class HomeProvider extends GetConnect implements IHomeProvider { 9 class HomeProvider extends GetConnect implements IHomeProvider {
10 @override 10 @override
11 void onInit() { 11 void onInit() {
12 - httpClient.defaultDecoder = CasesModel.fromJson; 12 + httpClient.defaultDecoder =
  13 + (val) => CasesModel.fromJson(val as Map<String, dynamic>);
13 httpClient.baseUrl = 'https://api.covid19api.com'; 14 httpClient.baseUrl = 'https://api.covid19api.com';
14 } 15 }
15 16
@@ -3,16 +3,16 @@ import '../domain/entity/cases_model.dart'; @@ -3,16 +3,16 @@ import '../domain/entity/cases_model.dart';
3 import 'home_api_provider.dart'; 3 import 'home_api_provider.dart';
4 4
5 class HomeRepository implements IHomeRepository { 5 class HomeRepository implements IHomeRepository {
6 - HomeRepository({this.provider}); 6 + HomeRepository({required this.provider});
7 final IHomeProvider provider; 7 final IHomeProvider provider;
8 8
9 @override 9 @override
10 Future<CasesModel> getCases() async { 10 Future<CasesModel> getCases() async {
11 final cases = await provider.getCases("/summary"); 11 final cases = await provider.getCases("/summary");
12 if (cases.status.hasError) { 12 if (cases.status.hasError) {
13 - return Future.error(cases.statusText); 13 + return Future.error(cases.statusText!);
14 } else { 14 } else {
15 - return cases.body; 15 + return cases.body!;
16 } 16 }
17 } 17 }
18 } 18 }
1 // To parse this JSON data, do 1 // To parse this JSON data, do
2 // 2 //
3 -// final CasesModel = CasesModelFromJson(jsonString); 3 +// final welcome = welcomeFromJson(jsonString);
4 4
5 import 'dart:convert'; 5 import 'dart:convert';
6 6
7 class CasesModel { 7 class CasesModel {
8 - final Global global;  
9 - final List<Country> countries;  
10 - final String date;  
11 -  
12 CasesModel({ 8 CasesModel({
13 - this.global,  
14 - this.countries,  
15 - this.date, 9 + required this.id,
  10 + required this.message,
  11 + required this.global,
  12 + required this.countries,
  13 + required this.date,
16 }); 14 });
17 15
18 - static CasesModel fromRawJson(String str) => 16 + final String id;
  17 + final String message;
  18 + final Global global;
  19 + final List<Country> countries;
  20 + final DateTime date;
  21 +
  22 + factory CasesModel.fromRawJson(String str) =>
19 CasesModel.fromJson(json.decode(str) as Map<String, dynamic>); 23 CasesModel.fromJson(json.decode(str) as Map<String, dynamic>);
20 24
21 String toRawJson() => json.encode(toJson()); 25 String toRawJson() => json.encode(toJson());
22 26
23 - static CasesModel fromJson(dynamic json) => CasesModel(  
24 - global: json["Global"] == null  
25 - ? null  
26 - : Global.fromJson(json["Global"] as Map<String, dynamic>),  
27 - countries: json["Countries"] == null  
28 - ? null  
29 - : List<Country>.from(  
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, 27 + factory CasesModel.fromJson(Map<String, dynamic> json) => CasesModel(
  28 + id: json["ID"] as String,
  29 + message: json["Message"] as String,
  30 + global: Global.fromJson(json["Global"] as Map<String, dynamic>),
  31 + countries: List<Country>.from((json["Countries"] as Iterable).map(
  32 + (x) => Country.fromJson(x as Map<String, dynamic>),
  33 + )),
  34 + date: DateTime.parse(json["Date"] as String),
34 ); 35 );
35 36
36 Map<String, dynamic> toJson() => { 37 Map<String, dynamic> toJson() => {
37 - "Global": global == null ? null : global.toJson(),  
38 - "Countries": countries == null  
39 - ? null  
40 - : List<dynamic>.from(countries.map((x) => x.toJson())),  
41 - "Date": date == null ? null : date, 38 + "ID": id,
  39 + "Message": message,
  40 + "Global": global.toJson(),
  41 + "Countries": List<dynamic>.from(countries.map((x) => x.toJson())),
  42 + "Date": date.toIso8601String(),
42 }; 43 };
43 } 44 }
44 45
45 class Country { 46 class Country {
  47 + Country({
  48 + required this.id,
  49 + required this.country,
  50 + required this.countryCode,
  51 + required this.slug,
  52 + required this.newConfirmed,
  53 + required this.totalConfirmed,
  54 + required this.newDeaths,
  55 + required this.totalDeaths,
  56 + required this.newRecovered,
  57 + required this.totalRecovered,
  58 + required this.date,
  59 + required this.premium,
  60 + });
  61 +
  62 + final String id;
46 final String country; 63 final String country;
47 final String countryCode; 64 final String countryCode;
48 final String slug; 65 final String slug;
@@ -52,20 +69,8 @@ class Country { @@ -52,20 +69,8 @@ class Country {
52 final int totalDeaths; 69 final int totalDeaths;
53 final int newRecovered; 70 final int newRecovered;
54 final int totalRecovered; 71 final int totalRecovered;
55 - final String date;  
56 -  
57 - Country({  
58 - this.country,  
59 - this.countryCode,  
60 - this.slug,  
61 - this.newConfirmed,  
62 - this.totalConfirmed,  
63 - this.newDeaths,  
64 - this.totalDeaths,  
65 - this.newRecovered,  
66 - this.totalRecovered,  
67 - this.date,  
68 - }); 72 + final DateTime date;
  73 + final Premium premium;
69 74
70 factory Country.fromRawJson(String str) => 75 factory Country.fromRawJson(String str) =>
71 Country.fromJson(json.decode(str) as Map<String, dynamic>); 76 Country.fromJson(json.decode(str) as Map<String, dynamic>);
@@ -73,56 +78,67 @@ class Country { @@ -73,56 +78,67 @@ class Country {
73 String toRawJson() => json.encode(toJson()); 78 String toRawJson() => json.encode(toJson());
74 79
75 factory Country.fromJson(Map<String, dynamic> json) => Country( 80 factory Country.fromJson(Map<String, dynamic> json) => Country(
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,  
80 - newConfirmed:  
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,  
88 - newRecovered:  
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, 81 + id: json["ID"] as String,
  82 + country: json["Country"] as String,
  83 + countryCode: json["CountryCode"] as String,
  84 + slug: json["Slug"] as String,
  85 + newConfirmed: json["NewConfirmed"] as int,
  86 + totalConfirmed: json["TotalConfirmed"] as int,
  87 + newDeaths: json["NewDeaths"] as int,
  88 + totalDeaths: json["TotalDeaths"] as int,
  89 + newRecovered: json["NewRecovered"] as int,
  90 + totalRecovered: json["TotalRecovered"] as int,
  91 + date: DateTime.parse(json["Date"] as String),
  92 + premium: Premium.fromJson(json["Premium"] as Map<String, dynamic>),
94 ); 93 );
95 94
96 Map<String, dynamic> toJson() => { 95 Map<String, dynamic> toJson() => {
97 - "Country": country == null ? null : country,  
98 - "CountryCode": countryCode == null ? null : countryCode,  
99 - "Slug": slug == null ? null : slug,  
100 - "NewConfirmed": newConfirmed == null ? null : newConfirmed,  
101 - "TotalConfirmed": totalConfirmed == null ? null : totalConfirmed,  
102 - "NewDeaths": newDeaths == null ? null : newDeaths,  
103 - "TotalDeaths": totalDeaths == null ? null : totalDeaths,  
104 - "NewRecovered": newRecovered == null ? null : newRecovered,  
105 - "TotalRecovered": totalRecovered == null ? null : totalRecovered,  
106 - "Date": date == null ? null : date, 96 + "ID": id,
  97 + "Country": country,
  98 + "CountryCode": countryCode,
  99 + "Slug": slug,
  100 + "NewConfirmed": newConfirmed,
  101 + "TotalConfirmed": totalConfirmed,
  102 + "NewDeaths": newDeaths,
  103 + "TotalDeaths": totalDeaths,
  104 + "NewRecovered": newRecovered,
  105 + "TotalRecovered": totalRecovered,
  106 + "Date": date.toIso8601String(),
  107 + "Premium": premium.toJson(),
107 }; 108 };
108 } 109 }
109 110
  111 +class Premium {
  112 + Premium();
  113 +
  114 + factory Premium.fromRawJson(String str) =>
  115 + Premium.fromJson(json.decode(str) as Map<String, dynamic>);
  116 +
  117 + String toRawJson() => json.encode(toJson());
  118 +
  119 + factory Premium.fromJson(Map<String, dynamic> json) => Premium();
  120 +
  121 + Map<String, dynamic> toJson() => {};
  122 +}
  123 +
110 class Global { 124 class Global {
  125 + Global({
  126 + required this.newConfirmed,
  127 + required this.totalConfirmed,
  128 + required this.newDeaths,
  129 + required this.totalDeaths,
  130 + required this.newRecovered,
  131 + required this.totalRecovered,
  132 + required this.date,
  133 + });
  134 +
111 final int newConfirmed; 135 final int newConfirmed;
112 final int totalConfirmed; 136 final int totalConfirmed;
113 final int newDeaths; 137 final int newDeaths;
114 final int totalDeaths; 138 final int totalDeaths;
115 final int newRecovered; 139 final int newRecovered;
116 final int totalRecovered; 140 final int totalRecovered;
117 -  
118 - Global({  
119 - this.newConfirmed,  
120 - this.totalConfirmed,  
121 - this.newDeaths,  
122 - this.totalDeaths,  
123 - this.newRecovered,  
124 - this.totalRecovered,  
125 - }); 141 + final DateTime date;
126 142
127 factory Global.fromRawJson(String str) => 143 factory Global.fromRawJson(String str) =>
128 Global.fromJson(json.decode(str) as Map<String, dynamic>); 144 Global.fromJson(json.decode(str) as Map<String, dynamic>);
@@ -130,27 +146,22 @@ class Global { @@ -130,27 +146,22 @@ class Global {
130 String toRawJson() => json.encode(toJson()); 146 String toRawJson() => json.encode(toJson());
131 147
132 factory Global.fromJson(Map<String, dynamic> json) => Global( 148 factory Global.fromJson(Map<String, dynamic> json) => Global(
133 - newConfirmed:  
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,  
141 - newRecovered:  
142 - json["NewRecovered"] == null ? null : json["NewRecovered"] as int,  
143 - totalRecovered: json["TotalRecovered"] == null  
144 - ? null  
145 - : json["TotalRecovered"] as int, 149 + newConfirmed: json["NewConfirmed"] as int,
  150 + totalConfirmed: json["TotalConfirmed"] as int,
  151 + newDeaths: json["NewDeaths"] as int,
  152 + totalDeaths: json["TotalDeaths"] as int,
  153 + newRecovered: json["NewRecovered"] as int,
  154 + totalRecovered: json["TotalRecovered"] as int,
  155 + date: DateTime.parse(json["Date"] as String),
146 ); 156 );
147 157
148 Map<String, dynamic> toJson() => { 158 Map<String, dynamic> toJson() => {
149 - "NewConfirmed": newConfirmed == null ? null : newConfirmed,  
150 - "TotalConfirmed": totalConfirmed == null ? null : totalConfirmed,  
151 - "NewDeaths": newDeaths == null ? null : newDeaths,  
152 - "TotalDeaths": totalDeaths == null ? null : totalDeaths,  
153 - "NewRecovered": newRecovered == null ? null : newRecovered,  
154 - "TotalRecovered": totalRecovered == null ? null : totalRecovered, 159 + "NewConfirmed": newConfirmed,
  160 + "TotalConfirmed": totalConfirmed,
  161 + "NewDeaths": newDeaths,
  162 + "TotalDeaths": totalDeaths,
  163 + "NewRecovered": newRecovered,
  164 + "TotalRecovered": totalRecovered,
  165 + "Date": date.toIso8601String(),
155 }; 166 };
156 } 167 }
@@ -4,22 +4,16 @@ import '../../domain/adapters/repository_adapter.dart'; @@ -4,22 +4,16 @@ import '../../domain/adapters/repository_adapter.dart';
4 import '../../domain/entity/cases_model.dart'; 4 import '../../domain/entity/cases_model.dart';
5 5
6 class HomeController extends SuperController<CasesModel> { 6 class HomeController extends SuperController<CasesModel> {
7 - HomeController({this.homeRepository}); 7 + HomeController({required this.homeRepository});
8 8
9 - /// inject repo abstraction dependency  
10 final IHomeRepository homeRepository; 9 final IHomeRepository homeRepository;
11 10
12 - /// When the controller is initialized, make the http request  
13 @override 11 @override
14 void onInit() { 12 void onInit() {
15 super.onInit(); 13 super.onInit();
16 - // show loading on start, data on success  
17 - // and error message on error with 0 boilerplate  
18 - homeRepository.getCases().then((data) {  
19 - change(data, status: RxStatus.success());  
20 - }, onError: (err) {  
21 - change(null, status: RxStatus.error(err.toString()));  
22 - }); 14 +
  15 + //Loading, Success, Error handle with 1 line of code
  16 + append(() => homeRepository.getCases);
23 } 17 }
24 18
25 @override 19 @override
@@ -29,9 +29,9 @@ class CountryView extends GetView<HomeController> { @@ -29,9 +29,9 @@ class CountryView extends GetView<HomeController> {
29 ), 29 ),
30 body: Center( 30 body: Center(
31 child: ListView.builder( 31 child: ListView.builder(
32 - itemCount: controller.state.countries.length, 32 + itemCount: controller.state!.countries.length,
33 itemBuilder: (context, index) { 33 itemBuilder: (context, index) {
34 - final country = controller.state.countries[index]; 34 + final country = controller.state!.countries[index];
35 return ListTile( 35 return ListTile(
36 onTap: () { 36 onTap: () {
37 Get.toNamed('/home/country/details', 37 Get.toNamed('/home/country/details',
@@ -42,7 +42,7 @@ class HomeView extends GetView<HomeController> { @@ -42,7 +42,7 @@ class HomeView extends GetView<HomeController> {
42 ), 42 ),
43 ), 43 ),
44 Text( 44 Text(
45 - '${state.global.totalConfirmed}', 45 + '${state!.global.totalConfirmed}',
46 style: TextStyle(fontSize: 45, fontWeight: FontWeight.bold), 46 style: TextStyle(fontSize: 45, fontWeight: FontWeight.bold),
47 ), 47 ),
48 SizedBox( 48 SizedBox(
@@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev @@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
18 version: 1.0.0+1 18 version: 1.0.0+1
19 19
20 environment: 20 environment:
21 - sdk: ">=2.7.0 <3.0.0" 21 + sdk: ">=2.12.0 <3.0.0"
22 22
23 dependencies: 23 dependencies:
24 flutter: 24 flutter:
@@ -17,7 +17,18 @@ class MockRepository implements IHomeRepository { @@ -17,7 +17,18 @@ class MockRepository implements IHomeRepository {
17 17
18 if (Random().nextBool()) { 18 if (Random().nextBool()) {
19 return CasesModel( 19 return CasesModel(
20 - global: Global(totalDeaths: 100, totalConfirmed: 200), 20 + global: Global(
  21 + totalDeaths: 100,
  22 + totalConfirmed: 200,
  23 + date: DateTime.now(),
  24 + newConfirmed: 0,
  25 + newDeaths: 0,
  26 + newRecovered: 0,
  27 + totalRecovered: 0),
  28 + countries: [],
  29 + date: DateTime.now(),
  30 + id: '',
  31 + message: '',
21 ); 32 );
22 } 33 }
23 34
@@ -30,7 +41,7 @@ void main() { @@ -30,7 +41,7 @@ void main() {
30 final binding = BindingsBuilder(() { 41 final binding = BindingsBuilder(() {
31 Get.lazyPut<IHomeRepository>(() => MockRepository()); 42 Get.lazyPut<IHomeRepository>(() => MockRepository());
32 Get.lazyPut<HomeController>( 43 Get.lazyPut<HomeController>(
33 - () => HomeController(homeRepository: Get.find())); 44 + () => HomeController(homeRepository: Get.find()!));
34 }); 45 });
35 46
36 test('Test Binding', () { 47 test('Test Binding', () {
@@ -69,8 +80,8 @@ void main() { @@ -69,8 +80,8 @@ void main() {
69 } 80 }
70 81
71 if (controller.status.isSuccess) { 82 if (controller.status.isSuccess) {
72 - expect(controller.state.global.totalDeaths, 100);  
73 - expect(controller.state.global.totalConfirmed, 200); 83 + expect(controller.state!.global.totalDeaths, 100);
  84 + expect(controller.state!.global.totalConfirmed, 200);
74 } 85 }
75 }); 86 });
76 87
@@ -104,33 +115,6 @@ void main() { @@ -104,33 +115,6 @@ void main() {
104 ), 115 ),
105 test: (e) { 116 test: (e) {
106 expect(find.text("ban:0"), findsOneWidget); 117 expect(find.text("ban:0"), findsOneWidget);
107 - expect(e.count.value, 0);  
108 - },  
109 - );  
110 -  
111 - testGetBuilder(  
112 - 'GetBuilder test',  
113 - widget: GetBuilder<Controller>(  
114 - init: Controller(),  
115 - builder: (controller) {  
116 - return Text("ban:${controller.count}");  
117 - },  
118 - ),  
119 - test: (e) {  
120 - expect(find.text("ban:0"), findsOneWidget);  
121 - expect(e.count.value, 0);  
122 - },  
123 - );  
124 -  
125 - testObx(  
126 - 'Obx test',  
127 - widget: (controller) => Obx(  
128 - () => Text("ban:${controller.count}"),  
129 - ),  
130 - controller: Controller(),  
131 - test: (e) {  
132 - expect(find.text("ban:0"), findsOneWidget);  
133 - expect(e.count.value, 0);  
134 }, 118 },
135 ); 119 );
136 120
@@ -93,7 +93,7 @@ class GetHttpClient { @@ -93,7 +93,7 @@ class GetHttpClient {
93 Progress? uploadProgress, 93 Progress? uploadProgress,
94 ) async { 94 ) async {
95 List<int>? bodyBytes; 95 List<int>? bodyBytes;
96 - BodyBytesStream? bodyStream; 96 + Stream<List<int>>? bodyStream;
97 final headers = <String, String>{}; 97 final headers = <String, String>{};
98 98
99 headers['user-agent'] = userAgent; 99 headers['user-agent'] = userAgent;
@@ -145,7 +145,7 @@ class GetHttpClient { @@ -145,7 +145,7 @@ class GetHttpClient {
145 ); 145 );
146 } 146 }
147 147
148 - BodyBytesStream _trackProgress( 148 + Stream<List<int>> _trackProgress(
149 List<int> bodyBytes, 149 List<int> bodyBytes,
150 Progress? uploadProgress, 150 Progress? uploadProgress,
151 ) { 151 ) {
@@ -163,7 +163,7 @@ class GetHttpClient { @@ -163,7 +163,7 @@ class GetHttpClient {
163 sink.add(data); 163 sink.add(data);
164 }), 164 }),
165 ); 165 );
166 - return BodyBytesStream(byteStream); 166 + return byteStream;
167 } 167 }
168 168
169 void _setSimpleHeaders( 169 void _setSimpleHeaders(
@@ -46,7 +46,7 @@ class HttpRequestImpl implements HttpRequestBase { @@ -46,7 +46,7 @@ class HttpRequestImpl implements HttpRequestBase {
46 var reader = html.FileReader(); 46 var reader = html.FileReader();
47 47
48 reader.onLoad.first.then((_) async { 48 reader.onLoad.first.then((_) async {
49 - var bodyBytes = BodyBytesStream.fromBytes(reader.result as Uint8List?); 49 + var bodyBytes = BodyBytesStream.fromBytes(reader.result as List<int>);
50 50
51 final stringBody = 51 final stringBody =
52 await bodyBytesToString(bodyBytes, xhr.responseHeaders); 52 await bodyBytesToString(bodyBytes, xhr.responseHeaders);
@@ -50,7 +50,7 @@ class HttpRequestImpl extends HttpRequestBase { @@ -50,7 +50,7 @@ class HttpRequestImpl extends HttpRequestBase {
50 headers[key] = values.join(','); 50 headers[key] = values.join(',');
51 }); 51 });
52 52
53 - final bodyBytes = BodyBytesStream(response); 53 + final bodyBytes = (response);
54 final stringBody = await bodyBytesToString(bodyBytes, headers); 54 final stringBody = await bodyBytesToString(bodyBytes, headers);
55 55
56 final body = bodyDecoded<T>( 56 final body = bodyDecoded<T>(
@@ -19,11 +19,11 @@ class MultipartFile { @@ -19,11 +19,11 @@ class MultipartFile {
19 final String contentType; 19 final String contentType;
20 20
21 /// This stream will emit the file content of File. 21 /// This stream will emit the file content of File.
22 - BodyBytesStream? _stream; 22 + Stream<List<int>>? _stream;
23 23
24 int? _length; 24 int? _length;
25 25
26 - BodyBytesStream? get stream => _stream; 26 + Stream<List<int>>? get stream => _stream;
27 27
28 int? get length => _length; 28 int? get length => _length;
29 29
@@ -21,7 +21,7 @@ class Request<T> { @@ -21,7 +21,7 @@ class Request<T> {
21 final int? contentLength; 21 final int? contentLength;
22 22
23 /// The BodyBytesStream of body from this [Request] 23 /// The BodyBytesStream of body from this [Request]
24 - final BodyBytesStream bodyBytes; 24 + final Stream<List<int>> bodyBytes;
25 25
26 /// When true, the client will follow redirects to resolves this [Request] 26 /// When true, the client will follow redirects to resolves this [Request]
27 final bool followRedirects; 27 final bool followRedirects;
@@ -50,7 +50,7 @@ class Request<T> { @@ -50,7 +50,7 @@ class Request<T> {
50 required Uri url, 50 required Uri url,
51 required String method, 51 required String method,
52 required Map<String, String> headers, 52 required Map<String, String> headers,
53 - BodyBytesStream? bodyBytes, 53 + Stream<List<int>>? bodyBytes,
54 bool followRedirects = true, 54 bool followRedirects = true,
55 int maxRedirects = 4, 55 int maxRedirects = 4,
56 int? contentLength, 56 int? contentLength,
@@ -76,11 +76,9 @@ class Request<T> { @@ -76,11 +76,9 @@ class Request<T> {
76 } 76 }
77 } 77 }
78 78
79 -class BodyBytesStream extends StreamView<List<int>?> {  
80 - BodyBytesStream(Stream<List<int>?> stream) : super(stream);  
81 -  
82 - factory BodyBytesStream.fromBytes(List<int>? bytes) =>  
83 - BodyBytesStream(Stream.fromIterable([bytes])); 79 +extension BodyBytesStream on Stream<List<int>> {
  80 + static Stream<List<int>> fromBytes(List<int> bytes) =>
  81 + Stream.fromIterable([bytes]);
84 82
85 Future<Uint8List> toBytes() { 83 Future<Uint8List> toBytes() {
86 var completer = Completer<Uint8List>(); 84 var completer = Completer<Uint8List>();
@@ -89,7 +87,7 @@ class BodyBytesStream extends StreamView<List<int>?> { @@ -89,7 +87,7 @@ class BodyBytesStream extends StreamView<List<int>?> {
89 Uint8List.fromList(bytes), 87 Uint8List.fromList(bytes),
90 ), 88 ),
91 ); 89 );
92 - listen((val) => sink.add(val!), 90 + listen((val) => sink.add(val),
93 onError: completer.completeError, 91 onError: completer.completeError,
94 onDone: sink.close, 92 onDone: sink.close,
95 cancelOnError: true); 93 cancelOnError: true);
@@ -97,5 +95,5 @@ class BodyBytesStream extends StreamView<List<int>?> { @@ -97,5 +95,5 @@ class BodyBytesStream extends StreamView<List<int>?> {
97 } 95 }
98 96
99 Future<String> bytesToString([Encoding encoding = utf8]) => 97 Future<String> bytesToString([Encoding encoding = utf8]) =>
100 - encoding.decodeStream(this as Stream<List<int>>); 98 + encoding.decodeStream(this);
101 } 99 }
@@ -49,7 +49,7 @@ class Response<T> { @@ -49,7 +49,7 @@ class Response<T> {
49 bool get unauthorized => status.isUnauthorized; 49 bool get unauthorized => status.isUnauthorized;
50 50
51 /// The response body as a Stream of Bytes. 51 /// The response body as a Stream of Bytes.
52 - final BodyBytesStream? bodyBytes; 52 + final Stream<List<int>>? bodyBytes;
53 53
54 /// The response body as a Stream of Bytes. 54 /// The response body as a Stream of Bytes.
55 final String? bodyString; 55 final String? bodyString;
@@ -61,7 +61,7 @@ class Response<T> { @@ -61,7 +61,7 @@ class Response<T> {
61 } 61 }
62 62
63 Future<String> bodyBytesToString( 63 Future<String> bodyBytesToString(
64 - BodyBytesStream bodyBytes, Map<String, String> headers) { 64 + Stream<List<int>> bodyBytes, Map<String, String> headers) {
65 return bodyBytes.bytesToString(_encodingForHeaders(headers)); 65 return bodyBytes.bytesToString(_encodingForHeaders(headers));
66 } 66 }
67 67
@@ -52,10 +52,9 @@ String validateField(String field) { @@ -52,10 +52,9 @@ String validateField(String field) {
52 return field.toLowerCase(); 52 return field.toLowerCase();
53 } 53 }
54 54
55 -BodyBytesStream toBodyBytesStream(Stream<List<int>> stream) {  
56 - if (stream is BodyBytesStream) return stream as BodyBytesStream;  
57 - return BodyBytesStream(stream);  
58 -} 55 +// Stream<List<int>> toBodyBytesStream(Stream<List<int>> stream) {
  56 +// return (stream);
  57 +// }
59 58
60 final _asciiOnly = RegExp(r'^[\x00-\x7F]+$'); 59 final _asciiOnly = RegExp(r'^[\x00-\x7F]+$');
61 60
@@ -2,9 +2,9 @@ import 'dart:developer' as developer; @@ -2,9 +2,9 @@ import 'dart:developer' as developer;
2 import 'get_main.dart'; 2 import 'get_main.dart';
3 3
4 ///Voidcallback from logs 4 ///Voidcallback from logs
5 -typedef LogWriterCallback = void Function(String text, {bool? isError}); 5 +typedef LogWriterCallback = void Function(String text, {bool isError});
6 6
7 /// default logger from GetX 7 /// default logger from GetX
8 -void defaultLogWriterCallback(String value, {bool? isError = false}) {  
9 - if (isError! || Get.isLogEnable) developer.log(value, name: 'GETX'); 8 +void defaultLogWriterCallback(String value, {bool isError = false}) {
  9 + if (isError || Get.isLogEnable) developer.log(value, name: 'GETX');
10 } 10 }
@@ -67,7 +67,7 @@ extension Inst on GetInterface { @@ -67,7 +67,7 @@ extension Inst on GetInterface {
67 /// Finds a Instance of the required Class <[S]>(or [tag]) 67 /// Finds a Instance of the required Class <[S]>(or [tag])
68 /// In the case of using [Get.create()], it will generate an Instance 68 /// In the case of using [Get.create()], it will generate an Instance
69 /// each time you call [Get.find()]. 69 /// each time you call [Get.find()].
70 - S? find<S>({String? tag}) => GetInstance().find<S>(tag: tag); 70 + S find<S>({String? tag}) => GetInstance().find<S>(tag: tag)!;
71 71
72 /// Injects an [Instance<S>] in memory. 72 /// Injects an [Instance<S>] in memory.
73 /// 73 ///
@@ -1105,9 +1105,9 @@ Since version 2.8 it is possible to access the properties @@ -1105,9 +1105,9 @@ Since version 2.8 it is possible to access the properties
1105 //TODO: Change to ui.SingletonFlutterWindow rather dynamic 1105 //TODO: Change to ui.SingletonFlutterWindow rather dynamic
1106 //when Flutter update stable. dynamic is used to avoid Breaking Changes 1106 //when Flutter update stable. dynamic is used to avoid Breaking Changes
1107 /// The window to which this binding is bound. 1107 /// The window to which this binding is bound.
1108 - dynamic get window => ui.window; 1108 + ui.SingletonFlutterWindow get window => ui.window;
1109 1109
1110 - Locale get deviceLocale => ui.window.locale; 1110 + Locale? get deviceLocale => ui.window.locale;
1111 1111
1112 ///The number of device pixels for each logical pixel. 1112 ///The number of device pixels for each logical pixel.
1113 double get pixelRatio => ui.window.devicePixelRatio; 1113 double get pixelRatio => ui.window.devicePixelRatio;
@@ -35,7 +35,7 @@ abstract class GetView<T> extends StatelessWidget { @@ -35,7 +35,7 @@ abstract class GetView<T> extends StatelessWidget {
35 35
36 final String? tag = null; 36 final String? tag = null;
37 37
38 - T? get controller => GetInstance().find<T>(tag: tag); 38 + T get controller => GetInstance().find<T>(tag: tag)!;
39 39
40 @override 40 @override
41 Widget build(BuildContext context); 41 Widget build(BuildContext context);
@@ -53,7 +53,7 @@ abstract class GetWidget<S extends GetLifeCycleBase?> extends GetWidgetCache { @@ -53,7 +53,7 @@ abstract class GetWidget<S extends GetLifeCycleBase?> extends GetWidgetCache {
53 @protected 53 @protected
54 final String? tag = null; 54 final String? tag = null;
55 55
56 - S? get controller => GetWidget._cache[this] as S?; 56 + S get controller => GetWidget._cache[this] as S;
57 57
58 // static final _cache = <GetWidget, GetLifeCycleBase>{}; 58 // static final _cache = <GetWidget, GetLifeCycleBase>{};
59 59
1 import 'dart:ui'; 1 import 'dart:ui';
2 import '../../../get_core/get_core.dart'; 2 import '../../../get_core/get_core.dart';
3 3
4 -extension Trans on String? {  
5 - String? get tr { 4 +extension Trans on String {
  5 + String get tr {
6 // Returns the key if locale is null. 6 // Returns the key if locale is null.
7 if (Get.locale?.languageCode == null) return this; 7 if (Get.locale?.languageCode == null) return this;
8 8
@@ -14,13 +14,13 @@ extension Trans on String? { @@ -14,13 +14,13 @@ extension Trans on String? {
14 "${Get.locale!.languageCode}_${Get.locale!.countryCode}"]! 14 "${Get.locale!.languageCode}_${Get.locale!.countryCode}"]!
15 .containsKey(this)) { 15 .containsKey(this)) {
16 return Get.translations[ 16 return Get.translations[
17 - "${Get.locale!.languageCode}_${Get.locale!.countryCode}"]![this!]; 17 + "${Get.locale!.languageCode}_${Get.locale!.countryCode}"]![this]!;
18 18
19 // Checks if there is a callback language in the absence of the specific 19 // Checks if there is a callback language in the absence of the specific
20 // country, and if it contains that key. 20 // country, and if it contains that key.
21 } else if (Get.translations.containsKey(Get.locale!.languageCode) && 21 } else if (Get.translations.containsKey(Get.locale!.languageCode) &&
22 Get.translations[Get.locale!.languageCode]!.containsKey(this)) { 22 Get.translations[Get.locale!.languageCode]!.containsKey(this)) {
23 - return Get.translations[Get.locale!.languageCode]![this!]; 23 + return Get.translations[Get.locale!.languageCode]![this]!;
24 // If there is no corresponding language or corresponding key, return 24 // If there is no corresponding language or corresponding key, return
25 // the key. 25 // the key.
26 } else if (Get.fallbackLocale != null) { 26 } else if (Get.fallbackLocale != null) {
@@ -29,11 +29,11 @@ extension Trans on String? { @@ -29,11 +29,11 @@ extension Trans on String? {
29 29
30 if (Get.translations.containsKey(key) && 30 if (Get.translations.containsKey(key) &&
31 Get.translations[key]!.containsKey(this)) { 31 Get.translations[key]!.containsKey(this)) {
32 - return Get.translations[key]![this!]; 32 + return Get.translations[key]![this]!;
33 } 33 }
34 if (Get.translations.containsKey(fallback.languageCode) && 34 if (Get.translations.containsKey(fallback.languageCode) &&
35 Get.translations[fallback.languageCode]!.containsKey(this)) { 35 Get.translations[fallback.languageCode]!.containsKey(this)) {
36 - return Get.translations[fallback.languageCode]![this!]; 36 + return Get.translations[fallback.languageCode]![this]!;
37 } 37 }
38 return this; 38 return this;
39 } else { 39 } else {
@@ -41,25 +41,25 @@ extension Trans on String? { @@ -41,25 +41,25 @@ extension Trans on String? {
41 } 41 }
42 } 42 }
43 43
44 - String? trArgs([List<String> args = const []]) { 44 + String trArgs([List<String> args = const []]) {
45 var key = tr; 45 var key = tr;
46 if (args.isNotEmpty) { 46 if (args.isNotEmpty) {
47 for (final arg in args) { 47 for (final arg in args) {
48 - key = key!.replaceFirst(RegExp(r'%s'), arg.toString()); 48 + key = key.replaceFirst(RegExp(r'%s'), arg.toString());
49 } 49 }
50 } 50 }
51 return key; 51 return key;
52 } 52 }
53 53
54 - String? trPlural([String? pluralKey, int? i, List<String> args = const []]) {  
55 - return i == 1 ? pluralKey.trArgs(args) : trArgs(args); 54 + String trPlural([String? pluralKey, int? i, List<String> args = const []]) {
  55 + return i == 1 ? pluralKey!.trArgs(args) : trArgs(args);
56 } 56 }
57 57
58 String? trParams([Map<String, String> params = const {}]) { 58 String? trParams([Map<String, String> params = const {}]) {
59 var trans = tr; 59 var trans = tr;
60 if (params.isNotEmpty) { 60 if (params.isNotEmpty) {
61 params.forEach((key, value) { 61 params.forEach((key, value) {
62 - trans = trans!.replaceAll('@$key', value); 62 + trans = trans.replaceAll('@$key', value);
63 }); 63 });
64 } 64 }
65 return trans; 65 return trans;
@@ -67,7 +67,7 @@ extension Trans on String? { @@ -67,7 +67,7 @@ extension Trans on String? {
67 67
68 String? trPluralParams( 68 String? trPluralParams(
69 [String? pluralKey, int? i, Map<String, String> params = const {}]) { 69 [String? pluralKey, int? i, Map<String, String> params = const {}]) {
70 - return i == 1 ? pluralKey.trParams(params) : trParams(params); 70 + return i == 1 ? pluralKey!.trParams(params) : trParams(params);
71 } 71 }
72 } 72 }
73 73
1 name: get 1 name: get
2 description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX. 2 description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX.
3 -version: 4.0.0-nullsafety.0 3 +version: 4.0.0-nullsafety.2
4 homepage: https://github.com/jonataslaw/getx 4 homepage: https://github.com/jonataslaw/getx
5 5
6 environment: 6 environment:
@@ -39,7 +39,7 @@ void main() { @@ -39,7 +39,7 @@ void main() {
39 test('Get start and delete called just one time', () async { 39 test('Get start and delete called just one time', () async {
40 Get..put(Controller())..put(Controller()); 40 Get..put(Controller())..put(Controller());
41 41
42 - final controller = Get.find<Controller>()!; 42 + final controller = Get.find<Controller>();
43 expect(controller.init, 1); 43 expect(controller.init, 1);
44 44
45 Get..delete<Controller>()..delete<Controller>(); 45 Get..delete<Controller>()..delete<Controller>();
@@ -83,19 +83,19 @@ void main() { @@ -83,19 +83,19 @@ void main() {
83 83
84 test('Get.lazyPut fenix test', () async { 84 test('Get.lazyPut fenix test', () async {
85 Get.lazyPut<Controller>(() => Controller(), fenix: true); 85 Get.lazyPut<Controller>(() => Controller(), fenix: true);
86 - Get.find<Controller>()!.increment(); 86 + Get.find<Controller>().increment();
87 87
88 - expect(Get.find<Controller>()!.count, 1); 88 + expect(Get.find<Controller>().count, 1);
89 Get.delete<Controller>(); 89 Get.delete<Controller>();
90 - expect(Get.find<Controller>()!.count, 0); 90 + expect(Get.find<Controller>().count, 0);
91 Get.reset(); 91 Get.reset();
92 }); 92 });
93 93
94 test('Get.lazyPut without fenix', () async { 94 test('Get.lazyPut without fenix', () async {
95 Get.lazyPut<Controller>(() => Controller()); 95 Get.lazyPut<Controller>(() => Controller());
96 - Get.find<Controller>()!.increment(); 96 + Get.find<Controller>().increment();
97 97
98 - expect(Get.find<Controller>()!.count, 1); 98 + expect(Get.find<Controller>().count, 1);
99 Get.delete<Controller>(); 99 Get.delete<Controller>();
100 expect(() => Get.find<Controller>(), throwsA(m.TypeMatcher<String>())); 100 expect(() => Get.find<Controller>(), throwsA(m.TypeMatcher<String>()));
101 Get.reset(); 101 Get.reset();
@@ -103,13 +103,13 @@ void main() { @@ -103,13 +103,13 @@ void main() {
103 103
104 test('Get.reloadInstance test', () async { 104 test('Get.reloadInstance test', () async {
105 Get.lazyPut<Controller>(() => Controller()); 105 Get.lazyPut<Controller>(() => Controller());
106 - var ct1 = Get.find<Controller>()!; 106 + var ct1 = Get.find<Controller>();
107 ct1.increment(); 107 ct1.increment();
108 expect(ct1.count, 1); 108 expect(ct1.count, 1);
109 - ct1 = Get.find<Controller>()!; 109 + ct1 = Get.find<Controller>();
110 expect(ct1.count, 1); 110 expect(ct1.count, 1);
111 GetInstance().reload<Controller>(); 111 GetInstance().reload<Controller>();
112 - ct1 = Get.find<Controller>()!; 112 + ct1 = Get.find<Controller>();
113 expect(ct1.count, 0); 113 expect(ct1.count, 0);
114 Get.reset(); 114 Get.reset();
115 }); 115 });