Skip to content

Commit

Permalink
Update to version 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonataslaw committed Jun 26, 2020
1 parent 61cac09 commit c3e7561
Show file tree
Hide file tree
Showing 42 changed files with 2,011 additions and 1,293 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [3.0.1]
- Breaking changes on Rx api and GetController and RxController were merged, and now you only have the 'GetxController'
- Refactor routing system. Now you can add custom transitions and more
- Improved the use of dynamic routes, you can now define two different pages according to your arguments.
- Added GetView widget
- Added internacionalization
- Added validations
- Added Get queqe
- Added GetStorage (with separated package)
- Minor bug fixes.


## [2.14.0]
- Added getPages API.
- Deprecated namedPages
Expand All @@ -12,7 +24,7 @@

## [2.13.0]
- Update docs
- Fix Bindings list on GetRouteBase
- Fix Bindings list on GetPageRoute

## [2.12.5]
- Update readme
Expand Down Expand Up @@ -64,7 +76,7 @@ Get.lazyPut () will not receive this resource. Initially he had it, but we saw i
## [2.10.0]
- Added SmartManagement, your application's memory is managed intelligently like never before!
- Added Obx, a widget that knows when to rebuild a child, without needing any type.
- Added MIxinBuilder - If you need to use GetBuilder in conjunction with GetX, use GetController with this widget, and the changes will occur either using update (this) or changing some reactive variable. Use only if necessary, for better RAM consumption, prefer widgets in that order:
- Added MIxinBuilder - If you need to use GetBuilder in conjunction with GetX, use GetxController with this widget, and the changes will occur either using update (this) or changing some reactive variable. Use only if necessary, for better RAM consumption, prefer widgets in that order:
Obx => GetX => GetBuilder => MixinBuilder.
Obx is the lightest of all, and MixinBuilder is a mix of the other 3, whenever possible, use the specific widget.
- Refactor: refactor StateManager of Get.
Expand Down
177 changes: 136 additions & 41 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ extension MDQ on BuildContext {
/// True if the current device is Tablet
bool get isTablet => isSmallTablet || isLargeTablet;
}

4 changes: 4 additions & 0 deletions lib/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export 'src/snackbar/snack.dart';
export 'src/bottomsheet/bottomsheet.dart';
export 'src/snackbar/snack_route.dart';
export 'src/state/get_state.dart';
export 'src/state/get_view.dart';
export 'src/regex/get_utils.dart';
export 'src/queue/get_queue.dart';
export 'src/state/mixin_state.dart';
export 'src/rx/rx_interface.dart';
export 'src/rx/rx_impl.dart';
Expand All @@ -21,3 +24,4 @@ export 'src/routes/observers/route_observer.dart';
export 'src/routes/transitions_type.dart';
export 'src/platform/platform.dart';
export 'src/extension_instance.dart';
export 'src/routes/custom_transition.dart';
5 changes: 3 additions & 2 deletions lib/src/extension_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ extension Storage on GetImpl {
return GetInstance().lazyPut<S>(builder, tag: tag);
}

Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder, {String tag}) async =>
GetInstance().putAsync<S>(builder, tag: tag);
Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder,
{String tag, bool permanent = false}) async =>
GetInstance().putAsync<S>(builder, tag: tag, permanent: permanent);

S find<S>({String tag, FcBuilderFunc<S> instance}) =>
GetInstance().find<S>(tag: tag, instance: instance);
Expand Down
17 changes: 8 additions & 9 deletions lib/src/get_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'root/smart_management.dart';
import 'rx/rx_interface.dart';
import 'typedefs/typedefs.dart';


class GetConfig {
//////////// INSTANCE MANAGER
static Map<dynamic, dynamic> _singl = {};
Expand All @@ -26,8 +25,9 @@ class GetInstance {
GetConfig._factory.putIfAbsent(key, () => builder);
}

Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder, {String tag}) async {
return put<S>(await builder(), tag: tag);
Future<S> putAsync<S>(FcBuilderFuncAsync<S> builder,
{String tag, bool permanent = false}) async {
return put<S>(await builder(), tag: tag, permanent: permanent);
}

/// Inject class on Get Instance Manager
Expand Down Expand Up @@ -105,14 +105,13 @@ class GetInstance {
}

void registerRouteInstance<S>({String tag}) {
// print("Register route [$S] as ${currentRoute}");
GetConfig.routesKey
.putIfAbsent(_getKey(S, tag), () => GetConfig.currentRoute);
}

S findByType<S>(Type type, {String tag}) {
String key = _getKey(type, tag);
return GetConfig._singl[key].getSependency();
return GetConfig._singl[key].getSependency() as S;
}

void initController<S>({String tag}) {
Expand All @@ -136,7 +135,7 @@ class GetInstance {
callInit = true;
}

FcBuilder builder = GetConfig._singl[key];
FcBuilder builder = GetConfig._singl[key] as FcBuilder;
if (builder == null) {
if (tag == null) {
throw "class ${S.toString()} is not register";
Expand All @@ -148,7 +147,7 @@ class GetInstance {
initController<S>(tag: tag);
}

return GetConfig._singl[key].getSependency();
return GetConfig._singl[key].getSependency() as S;
} else {
if (!GetConfig._factory.containsKey(key))
throw " $S not found. You need call put<$S>($S()) before";
Expand Down Expand Up @@ -177,7 +176,7 @@ class GetInstance {
/// Remove dependency of [S] on dependency abstraction. For concrete class use delete
void remove<S>({String tag}) {
String key = _getKey(S, tag);
FcBuilder builder = GetConfig._singl[key];
FcBuilder builder = GetConfig._singl[key] as FcBuilder;
final i = builder.dependency;

if (i is DisposableInterface) {
Expand Down Expand Up @@ -217,7 +216,7 @@ class GetInstance {
return false;
}

FcBuilder builder = GetConfig._singl[newKey];
FcBuilder builder = GetConfig._singl[newKey] as FcBuilder;
if (builder.permanent) {
(key == null)
? print(
Expand Down
8 changes: 4 additions & 4 deletions lib/src/get_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ abstract class GetService {
Color overlayColor = Colors.transparent,
Form userInputForm});

void snackbar(title, message,
void snackbar(String title, String message,
{Color colorText,
Duration duration,

Expand Down Expand Up @@ -224,11 +224,11 @@ abstract class GetService {

/// INSTANCE MANAGER
GetMaterialController getController;
GetMaterialController getxController;

changeTheme(ThemeData theme);
void changeTheme(ThemeData theme);

changeThemeMode(ThemeMode themeMode);
void changeThemeMode(ThemeMode themeMode);

GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey);

Expand Down
110 changes: 83 additions & 27 deletions lib/src/get_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/src/get_instance.dart';
import 'package:get/src/get_interface.dart';
import 'bottomsheet/bottomsheet.dart';
import 'platform/platform.dart';
import 'root/parse_route.dart';
import 'root/root_controller.dart';
import 'routes/bindings_interface.dart';
import 'routes/default_route.dart';
Expand All @@ -22,7 +23,7 @@ class GetImpl implements GetService {
bool defaultPopGesture = GetPlatform.isIOS;
bool defaultOpaqueRoute = true;
Transition defaultTransition =
(GetPlatform.isIOS ? Transition.cupertino : Transition.fade);
(GetPlatform.isIOS ? Transition.leftToRight : Transition.fadeIn);
Duration defaultDurationTransition = Duration(milliseconds: 400);
bool defaultGlobalState = true;
RouteSettings settings;
Expand All @@ -45,32 +46,42 @@ class GetImpl implements GetService {
bool fullscreenDialog = false,
Object arguments,
Bindings binding,
preventDuplicates = true,
bool popGesture}) {
return global(id).currentState.push(GetRouteBase(
if (preventDuplicates &&
'/' + page.toString().toLowerCase() == currentRoute) {
return null;
}

return global(id).currentState.push(GetPageRoute(
opaque: opaque ?? true,
page: page,
page: () => page,
settings: RouteSettings(
name: '/' + page.toString().toLowerCase(), arguments: arguments),
popGesture: popGesture ?? defaultPopGesture,
transition: transition ?? defaultTransition,
fullscreenDialog: fullscreenDialog,
binding: binding,
transitionDuration: duration ?? defaultDurationTransition));
duration: duration ?? defaultDurationTransition));
}

/// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed
/// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
/// of rebuilding every app after a route, use opaque = true as the parameter.
Future<T> toNamed<T>(String page, {Object arguments, int id}) {
// if (key.currentState.mounted) // add this if appear problems on future with route navigate
// when widget don't mounted
Future<T> toNamed<T>(String page,
{Object arguments, int id, preventDuplicates = true}) {
if (preventDuplicates && page == currentRoute) {
return null;
}
return global(id).currentState.pushNamed(page, arguments: arguments);
}

/// It replaces Navigator.pushReplacementNamed, but needs no context.
Future<T> offNamed<T>(String page, {Object arguments, int id}) {
// if (key.currentState.mounted) // add this if appear problems on future with route navigate
// when widget don't mounted
Future<T> offNamed<T>(String page,
{Object arguments, int id, preventDuplicates = true}) {
if (preventDuplicates && page == currentRoute) {
return null;
}
return global(id)
.currentState
.pushReplacementNamed(page, arguments: arguments);
Expand Down Expand Up @@ -128,13 +139,21 @@ class GetImpl implements GetService {
(!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen);

/// It replaces Navigator.pop, but needs no context.
void back({dynamic result, bool closeOverlays = false, int id}) {
void back(
{dynamic result,
bool closeOverlays = false,
bool canPop = true,
int id}) {
if (closeOverlays && isOverlaysOpen) {
navigator.popUntil((route) {
return (isOverlaysClosed);
});
}
if (global(id).currentState.canPop()) {
if (canPop) {
if (global(id).currentState.canPop()) {
global(id).currentState.pop(result);
}
} else {
global(id).currentState.pop(result);
}
}
Expand Down Expand Up @@ -162,17 +181,22 @@ class GetImpl implements GetService {
Object arguments,
Bindings binding,
bool fullscreenDialog = false,
preventDuplicates = true,
Duration duration}) {
return global(id).currentState.pushReplacement(GetRouteBase(
if (preventDuplicates &&
'/' + page.toString().toLowerCase() == currentRoute) {
return null;
}
return global(id).currentState.pushReplacement(GetPageRoute(
opaque: opaque ?? true,
page: page,
page: () => page,
binding: binding,
settings: RouteSettings(
name: '/' + page.toString().toLowerCase(), arguments: arguments),
fullscreenDialog: fullscreenDialog,
popGesture: popGesture ?? defaultPopGesture,
transition: transition ?? defaultTransition,
transitionDuration: duration ?? defaultDurationTransition));
duration: duration ?? defaultDurationTransition));
}

/// It replaces Navigator.pushAndRemoveUntil, but needs no context
Expand All @@ -184,21 +208,22 @@ class GetImpl implements GetService {
Object arguments,
Bindings binding,
bool fullscreenDialog = false,
Transition transition,
Duration duration}) {
Duration duration,
Transition transition}) {
var route = (Route<dynamic> rota) => false;

return global(id).currentState.pushAndRemoveUntil(
GetRouteBase(
GetPageRoute(
opaque: opaque ?? true,
popGesture: popGesture ?? defaultPopGesture,
page: page,
page: () => page,
binding: binding,
settings: RouteSettings(
name: '/' + page.toString().toLowerCase(), arguments: arguments),
name: '/' + page.runtimeType.toString().toLowerCase(),
arguments: arguments),
fullscreenDialog: fullscreenDialog,
transition: transition ?? defaultTransition,
transitionDuration: duration ?? defaultDurationTransition,
duration: duration ?? defaultDurationTransition,
),
predicate ?? route);
}
Expand Down Expand Up @@ -461,7 +486,7 @@ class GetImpl implements GetService {
}
}

void snackbar(title, message,
void snackbar(String title, String message,
{Color colorText,
Duration duration,

Expand Down Expand Up @@ -558,6 +583,24 @@ class GetImpl implements GetService {
}
}

ParseRouteTree routeTree;

addPages(List<GetPage> getPages) {
if (getPages != null) {
if (routeTree == null) routeTree = ParseRouteTree();
getPages.forEach((element) {
routeTree.addRoute(element);
});
}
}

addPage(GetPage getPage) {
if (getPage != null) {
if (routeTree == null) routeTree = ParseRouteTree();
routeTree.addRoute(getPage);
}
}

/// change default config of Get
config(
{bool enableLog,
Expand Down Expand Up @@ -588,14 +631,27 @@ class GetImpl implements GetService {
}
}

GetMaterialController getController = GetMaterialController();
GetMaterialController getxController = GetMaterialController();

Locale locale;

void updateLocale(Locale l) {
locale = l;
getxController.update();
}

Map<String, Map<String, String>> translations;

void addTranslations(Map<String, Map<String, String>> tr) {
translations.addAll(tr);
}

changeTheme(ThemeData theme) {
getController.setTheme(theme);
void changeTheme(ThemeData theme) {
getxController.setTheme(theme);
}

changeThemeMode(ThemeMode themeMode) {
getController.setThemeMode(themeMode);
void changeThemeMode(ThemeMode themeMode) {
getxController.setThemeMode(themeMode);
}

GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) {
Expand Down
Loading

0 comments on commit c3e7561

Please sign in to comment.