Jonny Borges

improve speed on getConnect and improve CupertinoApp code

... ... @@ -9,6 +9,8 @@ void main() {
runApp(MyApp());
}
class Controller extends GetxController {}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
... ...
... ... @@ -10,8 +10,10 @@ abstract class IHomeProvider {
class HomeProvider extends GetConnect implements IHomeProvider {
@override
void onInit() {
httpClient.defaultDecoder =
(val) => CasesModel.fromJson(val as Map<String, dynamic>);
httpClient.defaultDecoder = (val) {
print(val);
return CasesModel.fromJson(val as Map<String, dynamic>);
};
httpClient.baseUrl = 'https://api.covid19api.com';
super.onInit();
}
... ...
... ... @@ -6,14 +6,12 @@ import 'dart:convert';
class CasesModel {
CasesModel({
required this.id,
required this.message,
required this.global,
required this.countries,
required this.date,
});
final String id;
final String message;
final Global global;
final List<Country> countries;
... ... @@ -25,7 +23,6 @@ class CasesModel {
String toRawJson() => json.encode(toJson());
factory CasesModel.fromJson(Map<String, dynamic> json) => CasesModel(
id: json["ID"] as String,
message: json["Message"] as String,
global: Global.fromJson(json["Global"] as Map<String, dynamic>),
countries: List<Country>.from((json["Countries"] as Iterable).map(
... ... @@ -35,7 +32,6 @@ class CasesModel {
);
Map<String, dynamic> toJson() => {
"ID": id,
"Message": message,
"Global": global.toJson(),
"Countries": List<dynamic>.from(countries.map((x) => x.toJson())),
... ...
... ... @@ -25,7 +25,6 @@ class MockRepositorySuccess implements IHomeRepository {
totalRecovered: 0),
countries: [],
date: DateTime.now(),
id: '',
message: '',
);
}
... ...
... ... @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
... ...
... ... @@ -7,6 +7,7 @@ FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
... ...
... ... @@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
... ... @@ -346,7 +346,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
... ... @@ -395,7 +395,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
... ...
... ... @@ -13,7 +13,7 @@ class Request<T> {
final Uri url;
final Decoder<T>? decoder;
final ResponseInterceptor<T>? responseInterceptor;
/// The Http Method from this [Request]
... ... @@ -66,18 +66,17 @@ class Request<T> {
assert(maxRedirects > 0);
}
return Request._(
url: url,
method: method,
bodyBytes: bodyBytes ??= BodyBytesStream.fromBytes(const []),
headers: Map.from(headers),
followRedirects: followRedirects,
maxRedirects: maxRedirects,
contentLength: contentLength,
files: files,
persistentConnection: persistentConnection,
decoder: decoder,
responseInterceptor: responseInterceptor
);
url: url,
method: method,
bodyBytes: bodyBytes ??= BodyBytesStream.fromBytes(const []),
headers: Map.from(headers),
followRedirects: followRedirects,
maxRedirects: maxRedirects,
contentLength: contentLength,
files: files,
persistentConnection: persistentConnection,
decoder: decoder,
responseInterceptor: responseInterceptor);
}
Request<T> copyWith({
... ... @@ -100,24 +99,22 @@ class Request<T> {
}
return Request<T>._(
url: url ?? this.url,
method: method ?? this.method,
bodyBytes: bodyBytes ?? this.bodyBytes,
headers: headers == null ? this.headers : Map.from(headers),
followRedirects: followRedirects ?? this.followRedirects,
maxRedirects: maxRedirects ?? this.maxRedirects,
contentLength: contentLength ?? this.contentLength,
files: files ?? this.files,
persistentConnection: persistentConnection ?? this.persistentConnection,
decoder: decoder ?? this.decoder,
responseInterceptor: responseInterceptor ?? this.responseInterceptor
);
url: url ?? this.url,
method: method ?? this.method,
bodyBytes: bodyBytes ?? this.bodyBytes,
headers: headers == null ? this.headers : Map.from(headers),
followRedirects: followRedirects ?? this.followRedirects,
maxRedirects: maxRedirects ?? this.maxRedirects,
contentLength: contentLength ?? this.contentLength,
files: files ?? this.files,
persistentConnection: persistentConnection ?? this.persistentConnection,
decoder: decoder ?? this.decoder,
responseInterceptor: responseInterceptor ?? this.responseInterceptor);
}
}
extension BodyBytesStream on Stream<List<int>> {
static Stream<List<int>> fromBytes(List<int> bytes) =>
Stream.fromIterable([bytes]);
static Stream<List<int>> fromBytes(List<int> bytes) => Stream.value(bytes);
Future<Uint8List> toBytes() {
var completer = Completer<Uint8List>();
... ...
... ... @@ -170,9 +170,13 @@ extension Inst on GetInterface {
final isInit = _singl[key]!.isInit;
S? i;
if (!isInit) {
i = _startController<S>(tag: name);
if (_singl[key]!.isSingleton!) {
final isSingleton = _singl[key]?.isSingleton ?? false;
if (isSingleton) {
_singl[key]!.isInit = true;
}
i = _startController<S>(tag: name);
if (isSingleton) {
if (Get.smartManagement != SmartManagement.onlyBuilder) {
RouterReportManager.instance
.reportDependencyLinkedToRoute(_getKey(S, name));
... ...
... ... @@ -17,9 +17,7 @@ mixin GetLifeCycleMixin {
@protected
@mustCallSuper
void onInit() {
ambiguate(Engine.instance)
?.addPostFrameCallback((_) => onReady());
ambiguate(Engine.instance)?.addPostFrameCallback((_) => onReady());
}
/// Called 1 frame after onInit(). It is the perfect place to enter
... ...
... ... @@ -2,10 +2,7 @@ import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import '../../get_core/get_core.dart';
import '../../get_instance/src/bindings_interface.dart';
import '../../get_utils/get_utils.dart';
import '../get_navigation.dart';
import '../../get.dart';
import 'dialog/dialog_route.dart';
/// It replaces the Flutter Navigator, but needs no context.
... ... @@ -1259,8 +1256,8 @@ extension GetNavigationExt on GetInterface {
TDelegate? delegate<TDelegate extends RouterDelegate<TPage>, TPage>() =>
_getxController.routerDelegate as TDelegate?;
GetMaterialController get _getxController => GetMaterialController.to;
static final GetMaterialController _getxController =
Get.find<GetMaterialController>();
}
extension OverlayExt on GetInterface {
... ...
... ... @@ -7,6 +7,7 @@ import '../../../get_instance/get_instance.dart';
import '../../../get_state_manager/get_state_manager.dart';
import '../../../get_utils/get_utils.dart';
import '../../get_navigation.dart';
import '../router_report.dart';
class GetCupertinoApp extends StatelessWidget {
final GlobalKey<NavigatorState>? navigatorKey;
... ... @@ -62,6 +63,9 @@ class GetCupertinoApp extends StatelessWidget {
final BackButtonDispatcher? backButtonDispatcher;
final CupertinoThemeData? theme;
final bool useInheritedMediaQuery;
final List<Bind> binds;
final ScrollBehavior? scrollBehavior;
GetCupertinoApp({
Key? key,
this.theme,
... ... @@ -86,6 +90,8 @@ class GetCupertinoApp extends StatelessWidget {
this.onInit,
this.onDispose,
this.locale,
this.binds = const [],
this.scrollBehavior,
this.fallbackLocale,
this.localizationsDelegates,
this.localeListResolutionCallback,
... ... @@ -156,6 +162,8 @@ class GetCupertinoApp extends StatelessWidget {
this.showSemanticsDebugger = false,
this.debugShowCheckedModeBanner = true,
this.shortcuts,
this.binds = const [],
this.scrollBehavior,
this.actions,
this.customTransition,
this.translationsKeys,
... ... @@ -188,125 +196,87 @@ class GetCupertinoApp extends StatelessWidget {
super(key: key);
@override
Widget build(BuildContext context) => GetBuilder<GetMaterialController>(
init: Get.rootController,
dispose: (d) {
onDispose?.call();
// Get.clearRouteTree();
// Get.clearTranslations();
// Get.resetRootNavigator();
// Get.routerDelegate = null;
// Get.routeInformationParser = null;
},
initState: (i) {
Get.engine.addPostFrameCallback((timeStamp) {
onReady?.call();
});
if (locale != null) Get.locale = locale;
if (fallbackLocale != null) Get.fallbackLocale = fallbackLocale;
if (translations != null) {
Get.addTranslations(translations!.keys);
} else if (translationsKeys != null) {
Get.addTranslations(translationsKeys!);
}
// Get.customTransition = customTransition;
initialBinding?.dependencies();
// if (getPages != null) {
// Get.addPages(getPages!);
// } else {
// Get.addPage(
// GetPage(
// name: _cleanRouteName("/${home.runtimeType}"),
// page: () => home!,
// ),
// );
// }
Get.smartManagement = smartManagement;
onInit?.call();
Get.config(
enableLog: enableLog ?? Get.isLogEnable,
logWriterCallback: logWriterCallback,
defaultTransition: defaultTransition ?? Get.defaultTransition,
defaultOpaqueRoute: opaqueRoute ?? Get.isOpaqueRouteDefault,
defaultPopGesture: popGesture ?? Get.isPopGestureEnable,
defaultDurationTransition:
transitionDuration ?? Get.defaultTransitionDuration,
);
},
builder: (_) {
final routerDelegate = _.createDelegate(
pages: getPages ?? [],
notFoundRoute: unknownRoute,
Widget build(BuildContext context) {
return Binds(
binds: [
Bind.lazyPut<GetMaterialController>(
() => GetMaterialController(
ConfigData(
backButtonDispatcher: backButtonDispatcher,
binds: binds,
customTransition: customTransition,
defaultGlobalState: defaultGlobalState,
defaultTransition: defaultTransition,
enableLog: enableLog,
fallbackLocale: fallbackLocale,
getPages: getPages,
home: home,
initialRoute: initialRoute,
locale: locale,
logWriterCallback: logWriterCallback,
navigatorKey: navigatorKey,
navigatorObservers: (navigatorObservers == null
? <NavigatorObserver>[
GetObserver(routingCallback, Get.routing)
]
: <NavigatorObserver>[
GetObserver(routingCallback, Get.routing)
]
..addAll(navigatorObservers!)));
final routeInformationParser = _.createInformationParser(
initialRoute: initialRoute ??
getPages?.first.name ??
_cleanRouteName("/${home.runtimeType}"),
);
return CupertinoApp.router(
routerDelegate: routerDelegate,
routeInformationParser: routeInformationParser,
backButtonDispatcher: backButtonDispatcher,
routeInformationProvider: routeInformationProvider,
key: _.unikey,
theme: theme,
builder: defaultBuilder,
title: title,
onGenerateTitle: onGenerateTitle,
color: color,
locale: Get.locale ?? locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
useInheritedMediaQuery: useInheritedMediaQuery,
);
},
);
Widget defaultBuilder(BuildContext context, Widget? child) {
return Directionality(
textDirection: textDirection ??
(rtlLanguages.contains(Get.locale?.languageCode)
? TextDirection.rtl
: TextDirection.ltr),
child: builder == null
? (child ?? Material())
: builder!(context, child ?? Material()),
navigatorObservers: navigatorObservers,
onDispose: onDispose,
onInit: onInit,
onReady: onReady,
opaqueRoute: opaqueRoute,
popGesture: popGesture,
routeInformationParser: routeInformationParser,
routeInformationProvider: routeInformationProvider,
routerDelegate: routerDelegate,
routingCallback: routingCallback,
scaffoldMessengerKey: GlobalKey<ScaffoldMessengerState>(),
smartManagement: smartManagement,
transitionDuration: transitionDuration,
translations: translations,
translationsKeys: translationsKeys,
unknownRoute: unknownRoute,
),
),
onClose: () {
Get.clearTranslations();
RouterReportManager.dispose();
Get.resetInstance(clearRouteBindings: true);
},
),
...binds,
],
child: Builder(builder: (context) {
final controller = context.listen<GetMaterialController>();
return CupertinoApp.router(
routerDelegate: controller.routerDelegate,
routeInformationParser: controller.routeInformationParser,
backButtonDispatcher: backButtonDispatcher,
routeInformationProvider: routeInformationProvider,
key: controller.unikey,
builder: (context, child) => Directionality(
textDirection: textDirection ??
(rtlLanguages.contains(Get.locale?.languageCode)
? TextDirection.rtl
: TextDirection.ltr),
child: builder == null
? (child ?? Material())
: builder!(context, child ?? Material()),
),
title: title,
onGenerateTitle: onGenerateTitle,
color: color,
theme: theme,
locale: Get.locale ?? locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
scrollBehavior: scrollBehavior,
useInheritedMediaQuery: useInheritedMediaQuery,
);
}),
);
}
// Route<dynamic> generator(RouteSettings settings) {
// return PageRedirect(settings: settings, unknownRoute: unknownRoute).page();
// }
// List<Route<dynamic>> initialRoutesGenerate(String name) {
// return [
// PageRedirect(
// settings: RouteSettings(name: name),
// unknownRoute: unknownRoute,
// ).page()
// ];
// }
}
... ...
... ... @@ -8,6 +8,14 @@ import '../../../get_utils/get_utils.dart';
import '../../get_navigation.dart';
import '../router_report.dart';
class GetMaterialApp extends StatelessWidget {
final GlobalKey<NavigatorState>? navigatorKey;
final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey;
... ...
... ... @@ -70,10 +70,6 @@ class ConfigData {
class GetMaterialController extends FullLifeCycleController {
GetMaterialController(this.config);
static GetMaterialController get to {
return Get.find();
}
late final RouterDelegate<Object> routerDelegate;
late final RouteInformationParser<Object> routeInformationParser;
final ConfigData config;
... ... @@ -91,7 +87,7 @@ class GetMaterialController extends FullLifeCycleController {
if (config.getPages == null && config.home == null) {
throw 'You need add pages or home';
}
print('route delefate from onInit');
routerDelegate = config.routerDelegate ??
createDelegate(
pages: config.getPages ??
... ... @@ -104,13 +100,20 @@ class GetMaterialController extends FullLifeCycleController {
notFoundRoute: config.unknownRoute,
navigatorKey: config.navigatorKey,
navigatorObservers: (config.navigatorObservers == null
? <NavigatorObserver>[GetObserver(config.routingCallback, Get.routing)]
: <NavigatorObserver>[GetObserver(config.routingCallback, routing), ...config.navigatorObservers!]),
? <NavigatorObserver>[
GetObserver(config.routingCallback, Get.routing)
]
: <NavigatorObserver>[
GetObserver(config.routingCallback, routing),
...config.navigatorObservers!
]),
);
routeInformationParser = config.routeInformationParser ??
createInformationParser(
initialRoute: config.initialRoute ?? config.getPages?.first.name ?? cleanRouteName("/${config.home.runtimeType}"),
initialRoute: config.initialRoute ??
config.getPages?.first.name ??
cleanRouteName("/${config.home.runtimeType}"),
);
if (config.locale != null) Get.locale = config.locale;
... ... @@ -136,7 +139,8 @@ class GetMaterialController extends FullLifeCycleController {
defaultTransition = config.defaultTransition ?? getThemeTransition();
defaultOpaqueRoute = config.opaqueRoute ?? true;
defaultPopGesture = config.popGesture ?? GetPlatform.isIOS;
defaultTransitionDuration = config.transitionDuration ?? Duration(milliseconds: 300);
defaultTransitionDuration =
config.transitionDuration ?? Duration(milliseconds: 300);
// defaultTransitionCurve = Curves.easeOutQuad;
// defaultDialogTransitionCurve = Curves.easeOutQuad;
... ... @@ -145,7 +149,8 @@ class GetMaterialController extends FullLifeCycleController {
getThemeTransition() {
final platform = Get.theme.platform;
final matchingTransition = Get.theme.pageTransitionsTheme.builders[platform];
final matchingTransition =
Get.theme.pageTransitionsTheme.builders[platform];
switch (matchingTransition) {
case CupertinoPageTransitionsBuilder():
return Transition.cupertino;
... ... @@ -265,7 +270,8 @@ class GetMaterialController extends FullLifeCycleController {
List<NavigatorObserver>? navigatorObservers,
TransitionDelegate<dynamic>? transitionDelegate,
PopMode backButtonPopMode = PopMode.history,
PreventDuplicateHandlingMode preventDuplicateHandlingMode = PreventDuplicateHandlingMode.reorderRoutes,
PreventDuplicateHandlingMode preventDuplicateHandlingMode =
PreventDuplicateHandlingMode.reorderRoutes,
GlobalKey<NavigatorState>? navigatorKey,
}) {
return GetDelegate(
... ...
... ... @@ -47,8 +47,7 @@ void main() {
await tester.pumpAndSettle();
expect(
GetMaterialController.to.rootDelegate.currentConfiguration?.route?.name,
expect(Get.rootController.rootDelegate.currentConfiguration?.route?.name,
'/404');
});
... ...