fix stream error, add better error catch to GetX widget, fix error agent on web error
Showing
9 changed files
with
93 additions
and
12 deletions
@@ -21,10 +21,6 @@ class HomeView extends GetView<HomeController> { | @@ -21,10 +21,6 @@ class HomeView extends GetView<HomeController> { | ||
21 | return Scaffold( | 21 | return Scaffold( |
22 | body: GetRouterOutlet( | 22 | body: GetRouterOutlet( |
23 | initialRoute: Routes.DASHBOARD, | 23 | initialRoute: Routes.DASHBOARD, |
24 | - // name: Routes.HOME, | ||
25 | - //It's preferable to use emptyPage instead of emptyWidget | ||
26 | - // emptyPage: (delegate) => | ||
27 | - // Get.routeTree.matchRoute(Routes.DASHBOARD).route!, | ||
28 | ), | 24 | ), |
29 | bottomNavigationBar: BottomNavigationBar( | 25 | bottomNavigationBar: BottomNavigationBar( |
30 | currentIndex: currentIndex, | 26 | currentIndex: currentIndex, |
@@ -33,6 +33,7 @@ abstract class GetConnectInterface with GetLifeCycleBase { | @@ -33,6 +33,7 @@ abstract class GetConnectInterface with GetLifeCycleBase { | ||
33 | Map<String, dynamic>? query, | 33 | Map<String, dynamic>? query, |
34 | Decoder<T>? decoder, | 34 | Decoder<T>? decoder, |
35 | }); | 35 | }); |
36 | + | ||
36 | Future<Response<T>> post<T>( | 37 | Future<Response<T>> post<T>( |
37 | String url, | 38 | String url, |
38 | dynamic body, { | 39 | dynamic body, { |
@@ -95,6 +96,7 @@ class GetConnect extends GetConnectInterface { | @@ -95,6 +96,7 @@ class GetConnect extends GetConnectInterface { | ||
95 | this.timeout = const Duration(seconds: 5), | 96 | this.timeout = const Duration(seconds: 5), |
96 | this.followRedirects = true, | 97 | this.followRedirects = true, |
97 | this.maxRedirects = 5, | 98 | this.maxRedirects = 5, |
99 | + this.sendUserAgent = false, | ||
98 | this.maxAuthRetries = 1, | 100 | this.maxAuthRetries = 1, |
99 | this.allowAutoSignedCert = false, | 101 | this.allowAutoSignedCert = false, |
100 | this.withCredentials = false, | 102 | this.withCredentials = false, |
@@ -104,6 +106,7 @@ class GetConnect extends GetConnectInterface { | @@ -104,6 +106,7 @@ class GetConnect extends GetConnectInterface { | ||
104 | 106 | ||
105 | bool allowAutoSignedCert; | 107 | bool allowAutoSignedCert; |
106 | String userAgent; | 108 | String userAgent; |
109 | + bool sendUserAgent; | ||
107 | String? baseUrl; | 110 | String? baseUrl; |
108 | String defaultContentType = 'application/json; charset=utf-8'; | 111 | String defaultContentType = 'application/json; charset=utf-8'; |
109 | bool followRedirects; | 112 | bool followRedirects; |
@@ -122,6 +125,7 @@ class GetConnect extends GetConnectInterface { | @@ -122,6 +125,7 @@ class GetConnect extends GetConnectInterface { | ||
122 | @override | 125 | @override |
123 | GetHttpClient get httpClient => _httpClient ??= GetHttpClient( | 126 | GetHttpClient get httpClient => _httpClient ??= GetHttpClient( |
124 | userAgent: userAgent, | 127 | userAgent: userAgent, |
128 | + sendUserAgent: sendUserAgent, | ||
125 | timeout: timeout, | 129 | timeout: timeout, |
126 | followRedirects: followRedirects, | 130 | followRedirects: followRedirects, |
127 | maxRedirects: maxRedirects, | 131 | maxRedirects: maxRedirects, |
@@ -27,6 +27,8 @@ class GetHttpClient { | @@ -27,6 +27,8 @@ class GetHttpClient { | ||
27 | int maxRedirects; | 27 | int maxRedirects; |
28 | int maxAuthRetries; | 28 | int maxAuthRetries; |
29 | 29 | ||
30 | + bool sendUserAgent; | ||
31 | + | ||
30 | Decoder? defaultDecoder; | 32 | Decoder? defaultDecoder; |
31 | 33 | ||
32 | Duration timeout; | 34 | Duration timeout; |
@@ -42,6 +44,7 @@ class GetHttpClient { | @@ -42,6 +44,7 @@ class GetHttpClient { | ||
42 | this.timeout = const Duration(seconds: 8), | 44 | this.timeout = const Duration(seconds: 8), |
43 | this.followRedirects = true, | 45 | this.followRedirects = true, |
44 | this.maxRedirects = 5, | 46 | this.maxRedirects = 5, |
47 | + this.sendUserAgent = false, | ||
45 | this.maxAuthRetries = 1, | 48 | this.maxAuthRetries = 1, |
46 | bool allowAutoSignedCert = false, | 49 | bool allowAutoSignedCert = false, |
47 | this.baseUrl, | 50 | this.baseUrl, |
@@ -98,7 +101,9 @@ class GetHttpClient { | @@ -98,7 +101,9 @@ class GetHttpClient { | ||
98 | Stream<List<int>>? bodyStream; | 101 | Stream<List<int>>? bodyStream; |
99 | final headers = <String, String>{}; | 102 | final headers = <String, String>{}; |
100 | 103 | ||
101 | - headers['user-agent'] = userAgent; | 104 | + if (sendUserAgent) { |
105 | + headers['user-agent'] = userAgent; | ||
106 | + } | ||
102 | 107 | ||
103 | if (body is FormData) { | 108 | if (body is FormData) { |
104 | bodyBytes = await body.toBytes(); | 109 | bodyBytes = await body.toBytes(); |
@@ -240,7 +240,6 @@ class GetInstance { | @@ -240,7 +240,6 @@ class GetInstance { | ||
240 | } | 240 | } |
241 | 241 | ||
242 | for (final element in keysToRemove) { | 242 | for (final element in keysToRemove) { |
243 | - print('reload $element'); | ||
244 | reload(key: element); | 243 | reload(key: element); |
245 | //_routesKey.remove(element); | 244 | //_routesKey.remove(element); |
246 | } | 245 | } |
@@ -205,6 +205,52 @@ extension ExtensionSnackbar on GetInterface { | @@ -205,6 +205,52 @@ extension ExtensionSnackbar on GetInterface { | ||
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | +extension OverlayExt on GetInterface { | ||
209 | + Future<T> showOverlay<T>({ | ||
210 | + required Future<T> Function() asyncFunction, | ||
211 | + Color opacityColor = Colors.black, | ||
212 | + Widget? loadingWidget, | ||
213 | + double opacity = .5, | ||
214 | + }) async { | ||
215 | + final navigatorState = | ||
216 | + Navigator.of(Get.overlayContext!, rootNavigator: false); | ||
217 | + final overlayState = navigatorState.overlay!; | ||
218 | + | ||
219 | + final overlayEntryOpacity = OverlayEntry(builder: (context) { | ||
220 | + return Opacity( | ||
221 | + opacity: opacity, | ||
222 | + child: Container( | ||
223 | + color: opacityColor, | ||
224 | + )); | ||
225 | + }); | ||
226 | + final overlayEntryLoader = OverlayEntry(builder: (context) { | ||
227 | + return loadingWidget ?? | ||
228 | + Center( | ||
229 | + child: Container( | ||
230 | + height: 90, | ||
231 | + width: 90, | ||
232 | + child: Text('Loading...'), | ||
233 | + )); | ||
234 | + }); | ||
235 | + overlayState.insert(overlayEntryOpacity); | ||
236 | + overlayState.insert(overlayEntryLoader); | ||
237 | + | ||
238 | + T data; | ||
239 | + | ||
240 | + try { | ||
241 | + data = await asyncFunction(); | ||
242 | + } on Exception catch (_) { | ||
243 | + overlayEntryLoader.remove(); | ||
244 | + overlayEntryOpacity.remove(); | ||
245 | + rethrow; | ||
246 | + } | ||
247 | + | ||
248 | + overlayEntryLoader.remove(); | ||
249 | + overlayEntryOpacity.remove(); | ||
250 | + return data; | ||
251 | + } | ||
252 | +} | ||
253 | + | ||
208 | extension ExtensionDialog on GetInterface { | 254 | extension ExtensionDialog on GetInterface { |
209 | /// Show a dialog. | 255 | /// Show a dialog. |
210 | /// You can pass a [transitionDuration] and/or [transitionCurve], | 256 | /// You can pass a [transitionDuration] and/or [transitionCurve], |
@@ -62,7 +62,7 @@ class GetStream<T> { | @@ -62,7 +62,7 @@ class GetStream<T> { | ||
62 | item._onError?.call(error); | 62 | item._onError?.call(error); |
63 | } | 63 | } |
64 | 64 | ||
65 | - if (item.cancelOnError!) { | 65 | + if (item.cancelOnError ?? false) { |
66 | //item.cancel?.call(); | 66 | //item.cancel?.call(); |
67 | itemsToRemove.add(item); | 67 | itemsToRemove.add(item); |
68 | item.pause(); | 68 | item.pause(); |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | 2 | ||
3 | +import 'package:flutter/foundation.dart'; | ||
3 | import 'package:flutter/widgets.dart'; | 4 | import 'package:flutter/widgets.dart'; |
4 | 5 | ||
5 | import '../../../get_core/get_core.dart'; | 6 | import '../../../get_core/get_core.dart'; |
@@ -41,6 +42,18 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | @@ -41,6 +42,18 @@ class GetX<T extends DisposableInterface> extends StatefulWidget { | ||
41 | }); | 42 | }); |
42 | 43 | ||
43 | @override | 44 | @override |
45 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
46 | + super.debugFillProperties(properties); | ||
47 | + properties | ||
48 | + ..add( | ||
49 | + DiagnosticsProperty<T>('controller', init), | ||
50 | + ) | ||
51 | + ..add(DiagnosticsProperty<String>('tag', tag)) | ||
52 | + ..add( | ||
53 | + ObjectFlagProperty<GetXControllerBuilder<T>>.has('builder', builder)); | ||
54 | + } | ||
55 | + | ||
56 | + @override | ||
44 | GetXState<T> createState() => GetXState<T>(); | 57 | GetXState<T> createState() => GetXState<T>(); |
45 | } | 58 | } |
46 | 59 | ||
@@ -107,6 +120,12 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | @@ -107,6 +120,12 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> { | ||
107 | } | 120 | } |
108 | 121 | ||
109 | @override | 122 | @override |
123 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
124 | + super.debugFillProperties(properties); | ||
125 | + properties.add(DiagnosticsProperty<T>('controller', controller)); | ||
126 | + } | ||
127 | + | ||
128 | + @override | ||
110 | Widget build(BuildContext context) => RxInterface.notifyChildren( | 129 | Widget build(BuildContext context) => RxInterface.notifyChildren( |
111 | _observer, | 130 | _observer, |
112 | () => widget.builder(controller!), | 131 | () => widget.builder(controller!), |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | +import 'package:flutter/foundation.dart'; | ||
2 | import 'package:flutter/widgets.dart'; | 3 | import 'package:flutter/widgets.dart'; |
3 | import '../../../get_rx/src/rx_types/rx_types.dart'; | 4 | import '../../../get_rx/src/rx_types/rx_types.dart'; |
4 | 5 | ||
@@ -13,6 +14,12 @@ abstract class ObxWidget extends StatefulWidget { | @@ -13,6 +14,12 @@ abstract class ObxWidget extends StatefulWidget { | ||
13 | const ObxWidget({Key? key}) : super(key: key); | 14 | const ObxWidget({Key? key}) : super(key: key); |
14 | 15 | ||
15 | @override | 16 | @override |
17 | + void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
18 | + super.debugFillProperties(properties); | ||
19 | + properties..add(ObjectFlagProperty<Function>.has('builder', build)); | ||
20 | + } | ||
21 | + | ||
22 | + @override | ||
16 | _ObxState createState() => _ObxState(); | 23 | _ObxState createState() => _ObxState(); |
17 | 24 | ||
18 | @protected | 25 | @protected |
@@ -119,7 +119,7 @@ extension ContextExtensionss on BuildContext { | @@ -119,7 +119,7 @@ extension ContextExtensionss on BuildContext { | ||
119 | /// and less than 1200 return [tablet] value. | 119 | /// and less than 1200 return [tablet] value. |
120 | /// if the device width is less than 300 return [watch] value. | 120 | /// if the device width is less than 300 return [watch] value. |
121 | /// in other cases return [mobile] value. | 121 | /// in other cases return [mobile] value. |
122 | - T? responsiveValue<T>({ | 122 | + T responsiveValue<T>({ |
123 | T? mobile, | 123 | T? mobile, |
124 | T? tablet, | 124 | T? tablet, |
125 | T? desktop, | 125 | T? desktop, |
@@ -129,9 +129,14 @@ extension ContextExtensionss on BuildContext { | @@ -129,9 +129,14 @@ extension ContextExtensionss on BuildContext { | ||
129 | if (GetPlatform.isDesktop) { | 129 | if (GetPlatform.isDesktop) { |
130 | deviceWidth = mediaQuerySize.width; | 130 | deviceWidth = mediaQuerySize.width; |
131 | } | 131 | } |
132 | - if (deviceWidth >= 1200 && desktop != null) return desktop; | ||
133 | - if (deviceWidth >= 600 && tablet != null) return tablet; | ||
134 | - if (deviceWidth < 300 && watch != null) return watch; | ||
135 | - return mobile; | 132 | + if (deviceWidth >= 1200 && desktop != null) { |
133 | + return desktop; | ||
134 | + } else if (deviceWidth >= 600 && tablet != null) { | ||
135 | + return tablet; | ||
136 | + } else if (deviceWidth < 300 && watch != null) { | ||
137 | + return watch; | ||
138 | + } else { | ||
139 | + return mobile!; | ||
140 | + } | ||
136 | } | 141 | } |
137 | } | 142 | } |
-
Please register or login to post a comment