Jonny Borges

fix stream error, add better error catch to GetX widget, fix error agent on web error

... ... @@ -21,10 +21,6 @@ class HomeView extends GetView<HomeController> {
return Scaffold(
body: GetRouterOutlet(
initialRoute: Routes.DASHBOARD,
// name: Routes.HOME,
//It's preferable to use emptyPage instead of emptyWidget
// emptyPage: (delegate) =>
// Get.routeTree.matchRoute(Routes.DASHBOARD).route!,
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
... ...
... ... @@ -33,6 +33,7 @@ abstract class GetConnectInterface with GetLifeCycleBase {
Map<String, dynamic>? query,
Decoder<T>? decoder,
});
Future<Response<T>> post<T>(
String url,
dynamic body, {
... ... @@ -95,6 +96,7 @@ class GetConnect extends GetConnectInterface {
this.timeout = const Duration(seconds: 5),
this.followRedirects = true,
this.maxRedirects = 5,
this.sendUserAgent = false,
this.maxAuthRetries = 1,
this.allowAutoSignedCert = false,
this.withCredentials = false,
... ... @@ -104,6 +106,7 @@ class GetConnect extends GetConnectInterface {
bool allowAutoSignedCert;
String userAgent;
bool sendUserAgent;
String? baseUrl;
String defaultContentType = 'application/json; charset=utf-8';
bool followRedirects;
... ... @@ -122,6 +125,7 @@ class GetConnect extends GetConnectInterface {
@override
GetHttpClient get httpClient => _httpClient ??= GetHttpClient(
userAgent: userAgent,
sendUserAgent: sendUserAgent,
timeout: timeout,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
... ...
... ... @@ -27,6 +27,8 @@ class GetHttpClient {
int maxRedirects;
int maxAuthRetries;
bool sendUserAgent;
Decoder? defaultDecoder;
Duration timeout;
... ... @@ -42,6 +44,7 @@ class GetHttpClient {
this.timeout = const Duration(seconds: 8),
this.followRedirects = true,
this.maxRedirects = 5,
this.sendUserAgent = false,
this.maxAuthRetries = 1,
bool allowAutoSignedCert = false,
this.baseUrl,
... ... @@ -98,7 +101,9 @@ class GetHttpClient {
Stream<List<int>>? bodyStream;
final headers = <String, String>{};
headers['user-agent'] = userAgent;
if (sendUserAgent) {
headers['user-agent'] = userAgent;
}
if (body is FormData) {
bodyBytes = await body.toBytes();
... ...
... ... @@ -240,7 +240,6 @@ class GetInstance {
}
for (final element in keysToRemove) {
print('reload $element');
reload(key: element);
//_routesKey.remove(element);
}
... ...
... ... @@ -205,6 +205,52 @@ extension ExtensionSnackbar on GetInterface {
}
}
extension OverlayExt on GetInterface {
Future<T> showOverlay<T>({
required Future<T> Function() asyncFunction,
Color opacityColor = Colors.black,
Widget? loadingWidget,
double opacity = .5,
}) async {
final navigatorState =
Navigator.of(Get.overlayContext!, rootNavigator: false);
final overlayState = navigatorState.overlay!;
final overlayEntryOpacity = OverlayEntry(builder: (context) {
return Opacity(
opacity: opacity,
child: Container(
color: opacityColor,
));
});
final overlayEntryLoader = OverlayEntry(builder: (context) {
return loadingWidget ??
Center(
child: Container(
height: 90,
width: 90,
child: Text('Loading...'),
));
});
overlayState.insert(overlayEntryOpacity);
overlayState.insert(overlayEntryLoader);
T data;
try {
data = await asyncFunction();
} on Exception catch (_) {
overlayEntryLoader.remove();
overlayEntryOpacity.remove();
rethrow;
}
overlayEntryLoader.remove();
overlayEntryOpacity.remove();
return data;
}
}
extension ExtensionDialog on GetInterface {
/// Show a dialog.
/// You can pass a [transitionDuration] and/or [transitionCurve],
... ...
... ... @@ -62,7 +62,7 @@ class GetStream<T> {
item._onError?.call(error);
}
if (item.cancelOnError!) {
if (item.cancelOnError ?? false) {
//item.cancel?.call();
itemsToRemove.add(item);
item.pause();
... ...
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import '../../../get_core/get_core.dart';
... ... @@ -41,6 +42,18 @@ class GetX<T extends DisposableInterface> extends StatefulWidget {
});
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(
DiagnosticsProperty<T>('controller', init),
)
..add(DiagnosticsProperty<String>('tag', tag))
..add(
ObjectFlagProperty<GetXControllerBuilder<T>>.has('builder', builder));
}
@override
GetXState<T> createState() => GetXState<T>();
}
... ... @@ -107,6 +120,12 @@ class GetXState<T extends DisposableInterface> extends State<GetX<T>> {
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<T>('controller', controller));
}
@override
Widget build(BuildContext context) => RxInterface.notifyChildren(
_observer,
() => widget.builder(controller!),
... ...
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import '../../../get_rx/src/rx_types/rx_types.dart';
... ... @@ -13,6 +14,12 @@ abstract class ObxWidget extends StatefulWidget {
const ObxWidget({Key? key}) : super(key: key);
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties..add(ObjectFlagProperty<Function>.has('builder', build));
}
@override
_ObxState createState() => _ObxState();
@protected
... ...
... ... @@ -119,7 +119,7 @@ extension ContextExtensionss on BuildContext {
/// and less than 1200 return [tablet] value.
/// if the device width is less than 300 return [watch] value.
/// in other cases return [mobile] value.
T? responsiveValue<T>({
T responsiveValue<T>({
T? mobile,
T? tablet,
T? desktop,
... ... @@ -129,9 +129,14 @@ extension ContextExtensionss on BuildContext {
if (GetPlatform.isDesktop) {
deviceWidth = mediaQuerySize.width;
}
if (deviceWidth >= 1200 && desktop != null) return desktop;
if (deviceWidth >= 600 && tablet != null) return tablet;
if (deviceWidth < 300 && watch != null) return watch;
return mobile;
if (deviceWidth >= 1200 && desktop != null) {
return desktop;
} else if (deviceWidth >= 600 && tablet != null) {
return tablet;
} else if (deviceWidth < 300 && watch != null) {
return watch;
} else {
return mobile!;
}
}
}
... ...