Jonny Borges
Committed by GitHub

Update to 2.14.0

Added getPages 
Deprecated namedRoutes
Fix transitionDefault
## [2.14.0]
- Added getPages API.
- Deprecated namedPages
- Fix default transition
## [2.13.1]
- Added sort to ListX
- Prepared the framework for version 3
... ...
... ... @@ -102,7 +102,7 @@ This is a simple project but it already makes clear how powerful Get is. As your
- [Obx()](#obx)
- [Workers:](#workers)
- [Mixing the two state managers](#mixing-the-two-state-managers)
- [GetBuilder vs GetX && Obx vs MixinBuilder](#getbuilder-vs-getx--obx-vs-mixinbuilder)
- [GetBuilder vs GetX && Obx vs MixinBuilder](#getbuilder-vs-getx-vs-obx-vs-mixinbuilder)
- [Dependency Management](#dependency-management)
- [Simple Instance Manager](#simple-instance-manager)
- [Bindings](#bindings)
... ... @@ -236,11 +236,21 @@ void main() {
runApp(
GetMaterialApp(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: MyHomePage()),
'/second': GetRoute(page: Second()),
'/third': GetRoute(page: Third(),transition: Transition.cupertino);
},
getPages: [
GetPage(
name: '/',
page: () => MyHomePage(),
),
GetPage(
name: '/second',
page: () => Second(),
),
GetPage(
name: '/third',
page: () => Third(),
transition: Transition.cupertino
),
],
)
);
}
... ... @@ -281,15 +291,25 @@ void main() {
runApp(
GetMaterialApp(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: MyHomePage()),
getPages: [
GetPage(
name: '/',
page: () => MyHomePage(),
),
GetPage(
/// Important! :user is not a new route, it is just a parameter
/// specification. Do not use '/second/:user' and '/second'
/// if you need new route to user, use '/second/user/:user'
/// if '/second' is a route.
'/second/:user': GetRoute(page: Second()), // receive ID
'/third': GetRoute(page: Third(),transition: Transition.cupertino);
},
name: '/second/:user',
page: () => Second(),
),
GetPage(
name: '/third',
page: () => Third(),
transition: Transition.cupertino
),
],
)
);
}
... ... @@ -900,6 +920,34 @@ If we change count 2, only count2 and 3 are reconstructed, because the value of
If we add the number 1 to count 1, which already contains 1, no widget is reconstructed. If we add a value of 1 for count 1 and a value of 2 for count 2, only 2 and 3 will be reconstructed, simply because GetX not only changes what is necessary, it avoids duplicating events.
- NOTE: By default, the first event will allow rebuild even if it is the same. We created this behavior due to dualistic variables, such as Boolean.
Imagine you did this:
```dart
var isLogged = false.obs;
```
and then you check if a user is logged in to trigger an event in "ever".
```dart
onInit(){
ever(isLogged, fireRoute);
isLogged.value = await Preferences.hasToken();
}
fireRoute(logged) {
if (logged) {
Get.off(Home());
} else {
Get.off(Login());
}
}
```
if hasToken was false, there would be no change to isLogged, so ever would never be called. To avoid this type of behavior, the first change to an observable will always trigger an event, even if it is the same.
You can remove this behavior if you want, using:
`isLogged.firstRebuild = false;`
In addition, Get provides refined state control. You can condition an event (such as adding an object to a list), on a certain condition.
```dart
... ... @@ -962,6 +1010,7 @@ Camila
```
### Note about Lists
Working with Lists using Get is the best and most enjoyable thing in the world. They are completely observable as are the objects within it. That way, if you add a value to a list, it will automatically rebuild the widgets that use it.
You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that, unfortunate primitive types like String and int cannot be extended, making the use of .value mandatory, but that won't be a problem if you work with gets and setters for these.
... ... @@ -1029,7 +1078,7 @@ Some people opened a feature request, as they wanted to use only one type of rea
Probably using a GetController using GetX and Obx will work, but it will not be possible to use an RxController on a GetBuilder.
Extending these controllers is important, as they have life cycles, and can "start" and "end" events in their onInit() and onClose() methods.
## GetBuilder vs GetX && Obx vs MixinBuilder
## GetBuilder vs GetX vs Obx vs MixinBuilder
In a decade working with programming I was able to learn some valuable lessons.
My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible.
... ...
... ... @@ -27,4 +27,10 @@ extension Storage on GetImpl {
bool reset({bool clearFactory = true, bool clearRouteBindings = true}) =>
GetInstance().reset(
clearFactory: clearFactory, clearRouteBindings: clearRouteBindings);
/// Delete class instance on [S] and clean memory
Future<bool> delete<S>({String tag, String key}) async =>
GetInstance().delete<S>(tag: tag, key: key);
bool isRegistred<S>({String tag}) => GetInstance().isRegistred<S>(tag: tag);
}
... ...
... ... @@ -152,7 +152,7 @@ abstract class GetService {
Widget titleText,
Widget messageText,
Widget icon,
bool instantInit = false,
bool instantInit = true,
bool shouldIconPulse = true,
double maxWidth,
EdgeInsets margin = const EdgeInsets.all(0.0),
... ... @@ -239,7 +239,7 @@ abstract class GetService {
GlobalKey<NavigatorState> global(int k);
//////////// INSTANCE MANAGER
setParameter(Map<String, String> param);
// setParameter(Map<String, String> param);
/// give current arguments
Object get arguments;
... ...
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:get/src/get_instance.dart';
import 'package:get/src/get_interface.dart';
import 'bottomsheet/bottomsheet.dart';
import 'platform/platform.dart';
... ... @@ -133,7 +134,9 @@ class GetImpl implements GetService {
return (isOverlaysClosed);
});
}
global(id).currentState.pop(result);
if (global(id).currentState.canPop()) {
global(id).currentState.pop(result);
}
}
/// It will close as many screens as you define. Times must be> 0;
... ... @@ -380,7 +383,7 @@ class GetImpl implements GetService {
Widget titleText,
Widget messageText,
Widget icon,
bool instantInit = false,
bool instantInit = true,
bool shouldIconPulse = true,
double maxWidth,
EdgeInsets margin = const EdgeInsets.all(0.0),
... ... @@ -562,24 +565,24 @@ class GetImpl implements GetService {
bool defaultGlobalState,
Transition defaultTransition}) {
if (enableLog != null) {
enableLog = enableLog;
GetConfig.isLogEnable = enableLog;
}
if (defaultPopGesture != null) {
defaultPopGesture = defaultPopGesture;
this.defaultPopGesture = defaultPopGesture;
}
if (defaultOpaqueRoute != null) {
defaultOpaqueRoute = defaultOpaqueRoute;
this.defaultOpaqueRoute = defaultOpaqueRoute;
}
if (defaultTransition != null) {
defaultTransition = defaultTransition;
this.defaultTransition = defaultTransition;
}
if (defaultDurationTransition != null) {
defaultDurationTransition = defaultDurationTransition;
this.defaultDurationTransition = defaultDurationTransition;
}
if (defaultGlobalState != null) {
defaultGlobalState = defaultGlobalState;
this.defaultGlobalState = defaultGlobalState;
}
}
... ... @@ -624,11 +627,7 @@ class GetImpl implements GetService {
Routing _routing = Routing();
Map<String, String> _parameters = {};
setParameter(Map<String, String> param) {
_parameters = param;
}
Map<String, String> parameters = {};
setRouting(Routing rt) {
_routing = rt;
... ... @@ -641,9 +640,6 @@ class GetImpl implements GetService {
/// give current arguments
Object get arguments => _routing.args;
/// give current arguments
Map<String, String> get parameters => _parameters;
/// give name from current route
get currentRoute => _routing.current;
... ...
import 'package:flutter/widgets.dart';
import 'package:get/src/routes/get_route.dart';
class GetPageMatch {
GetPageMatch(this.route);
GetPage route;
Map<String, String> parameters = <String, String>{};
}
class ParseRouteTree {
final List<ParseRouteTreeNode> _nodes = <ParseRouteTreeNode>[];
bool _hasDefaultRoute = false;
void addRoute(GetPage route) {
String path = route.name;
if (path == Navigator.defaultRouteName) {
if (_hasDefaultRoute) {
throw ("Default route was already defined");
}
var node = ParseRouteTreeNode(path, ParseRouteTreeNodeType.component);
node.routes = [route];
_nodes.add(node);
_hasDefaultRoute = true;
return;
}
if (path.startsWith("/")) {
path = path.substring(1);
}
List<String> pathComponents = path.split('/');
ParseRouteTreeNode parent;
for (int i = 0; i < pathComponents.length; i++) {
String component = pathComponents[i];
ParseRouteTreeNode node = _nodeForComponent(component, parent);
if (node == null) {
ParseRouteTreeNodeType type = _typeForComponent(component);
node = ParseRouteTreeNode(component, type);
node.parent = parent;
if (parent == null) {
_nodes.add(node);
} else {
parent.nodes.add(node);
}
}
if (i == pathComponents.length - 1) {
if (node.routes == null) {
node.routes = [route];
} else {
node.routes.add(route);
}
}
parent = node;
}
}
GetPageMatch matchRoute(String path) {
String usePath = path;
if (usePath.startsWith("/")) {
usePath = path.substring(1);
}
List<String> components = usePath.split("/");
if (path == Navigator.defaultRouteName) {
components = ["/"];
}
Map<ParseRouteTreeNode, ParseRouteTreeNodeMatch> nodeMatches =
<ParseRouteTreeNode, ParseRouteTreeNodeMatch>{};
List<ParseRouteTreeNode> nodesToCheck = _nodes;
for (String checkComponent in components) {
Map<ParseRouteTreeNode, ParseRouteTreeNodeMatch> currentMatches =
<ParseRouteTreeNode, ParseRouteTreeNodeMatch>{};
List<ParseRouteTreeNode> nextNodes = <ParseRouteTreeNode>[];
for (ParseRouteTreeNode node in nodesToCheck) {
String pathPart = checkComponent;
Map<String, String> queryMap = {};
if (checkComponent.contains("?") && !checkComponent.contains("=")) {
var splitParam = checkComponent.split("?");
pathPart = splitParam[0];
queryMap = {pathPart: splitParam[1]};
} else if (checkComponent.contains("?")) {
var splitParam = checkComponent.split("?");
var splitParam2 = splitParam[1].split("=");
if (!splitParam2[1].contains("&")) {
pathPart = splitParam[0];
queryMap = {splitParam2[0]: splitParam2[1]};
} else {
pathPart = splitParam[0];
final segunda = splitParam[1];
var other = segunda.split(RegExp(r"[&,=]"));
for (var i = 0; i < (other.length - 1); i++) {
bool impar = (i % 2 == 0);
if (impar) {
queryMap.addAll({other[0 + i]: other[1 + i]});
}
}
}
}
bool isMatch = (node.part == pathPart || node.isParameter());
if (isMatch) {
ParseRouteTreeNodeMatch parentMatch = nodeMatches[node.parent];
ParseRouteTreeNodeMatch match =
ParseRouteTreeNodeMatch.fromMatch(parentMatch, node);
if (node.isParameter()) {
String paramKey = node.part.substring(1);
match.parameters[paramKey] = pathPart;
}
if (queryMap != null) {
match.parameters.addAll(queryMap);
}
currentMatches[node] = match;
if (node.nodes != null) {
nextNodes.addAll(node.nodes);
}
}
}
nodeMatches = currentMatches;
nodesToCheck = nextNodes;
if (currentMatches.values.length == 0) {
return null;
}
}
List<ParseRouteTreeNodeMatch> matches = nodeMatches.values.toList();
if (matches.length > 0) {
ParseRouteTreeNodeMatch match = matches.first;
ParseRouteTreeNode nodeToUse = match.node;
if (nodeToUse != null &&
nodeToUse.routes != null &&
nodeToUse.routes.length > 0) {
List<GetPage> routes = nodeToUse.routes;
GetPageMatch routeMatch = GetPageMatch(routes[0]);
routeMatch.parameters = match.parameters;
return routeMatch;
}
}
return null;
}
ParseRouteTreeNode _nodeForComponent(
String component, ParseRouteTreeNode parent) {
List<ParseRouteTreeNode> nodes = _nodes;
if (parent != null) {
nodes = parent.nodes;
}
for (ParseRouteTreeNode node in nodes) {
if (node.part == component) {
return node;
}
}
return null;
}
ParseRouteTreeNodeType _typeForComponent(String component) {
ParseRouteTreeNodeType type = ParseRouteTreeNodeType.component;
if (_isParameterComponent(component)) {
type = ParseRouteTreeNodeType.parameter;
}
return type;
}
bool _isParameterComponent(String component) {
return component.startsWith(":");
}
Map<String, String> parseQueryString(String query) {
var search = RegExp('([^&=]+)=?([^&]*)');
var params = Map<String, String>();
if (query.startsWith('?')) query = query.substring(1);
decode(String s) => Uri.decodeComponent(s.replaceAll('+', ' '));
for (Match match in search.allMatches(query)) {
String key = decode(match.group(1));
String value = decode(match.group(2));
params[key] = value;
}
return params;
}
}
class ParseRouteTreeNodeMatch {
ParseRouteTreeNodeMatch(this.node);
ParseRouteTreeNodeMatch.fromMatch(ParseRouteTreeNodeMatch match, this.node) {
parameters = <String, String>{};
if (match != null) {
parameters.addAll(match.parameters);
}
}
ParseRouteTreeNode node;
Map<String, String> parameters = <String, String>{};
}
class ParseRouteTreeNode {
ParseRouteTreeNode(this.part, this.type);
String part;
ParseRouteTreeNodeType type;
List<GetPage> routes = <GetPage>[];
List<ParseRouteTreeNode> nodes = <ParseRouteTreeNode>[];
ParseRouteTreeNode parent;
bool isParameter() {
return type == ParseRouteTreeNodeType.parameter;
}
}
enum ParseRouteTreeNodeType {
component,
parameter,
}
... ...
... ... @@ -3,6 +3,7 @@ import 'package:get/get.dart';
import 'package:get/src/routes/get_route.dart';
import 'package:get/src/routes/utils/parse_arguments.dart';
import '../get_instance.dart';
import 'parse_route.dart';
import 'root_controller.dart';
import 'smart_management.dart';
... ... @@ -43,12 +44,32 @@ class GetMaterialApp extends StatelessWidget {
this.routingCallback,
this.defaultTransition,
// this.actions,
this.getPages,
this.opaqueRoute,
this.enableLog,
this.popGesture,
this.transitionDuration,
this.defaultGlobalState,
this.namedRoutes,
// ignore: deprecated_member_use_from_same_package
@Deprecated(
"""Please, use new api getPages. You can now simply create a list of GetPages,
and enter your route name in the 'name' property.
Page now receives a function ()=> Page(), which allows more flexibility.
You can now decide which page you want to display, according to the parameters received on the page.
Example:
GetPage(
name: '/second',
page:(){
if (Get.parameters['id'] == null) {
return Login();
} else {
return Home();
}
});
""")
// ignore: deprecated_member_use_from_same_package
this.namedRoutes,
this.unknownRoute,
}) : assert(routes != null),
assert(navigatorObservers != null),
... ... @@ -100,11 +121,41 @@ class GetMaterialApp extends StatelessWidget {
final Bindings initialBinding;
final Duration transitionDuration;
final bool defaultGlobalState;
final Map<String, GetRoute> namedRoutes;
final List<GetPage> getPages;
final GetRoute unknownRoute;
Route<dynamic> generator(RouteSettings settings) {
final match = _routeTree.matchRoute(settings.name);
print(settings.name);
Get.parameters = match?.parameters;
return GetRouteBase(
page: null,
title: match.route.title,
route: match.route.page,
parameter: match.route.parameter,
settings:
RouteSettings(name: settings.name, arguments: settings.arguments),
maintainState: match.route.maintainState,
curve: match.route.curve,
alignment: match.route.alignment,
opaque: match.route.opaque,
binding: match.route.binding,
bindings: match.route.bindings,
transitionDuration: (transitionDuration == null
? match.route.transitionDuration
: transitionDuration),
transition: match.route.transition,
popGesture: match.route.popGesture,
fullscreenDialog: match.route.fullscreenDialog,
);
}
Route<dynamic> namedRoutesGenerate(RouteSettings settings) {
Get.setSettings(settings);
// Get.setSettings(settings);
/// onGenerateRoute to FlutterWeb is Broken on Dev/Master. This is a temporary
/// workaround until they fix it, because the problem is with the 'Flutter engine',
... ... @@ -129,7 +180,7 @@ class GetMaterialApp extends StatelessWidget {
});
if (newNamedRoutes.containsKey(settingsName)) {
Get.setParameter(parsedString.parameters);
Get.parameters = parsedString.parameters;
return GetRouteBase(
page: newNamedRoutes[settingsName].page,
... ... @@ -185,6 +236,12 @@ class GetMaterialApp extends StatelessWidget {
onDispose?.call();
},
initState: (i) {
if (getPages != null) {
_routeTree = ParseRouteTree();
getPages.forEach((element) {
_routeTree.addRoute(element);
});
}
initialBinding?.dependencies();
GetConfig.smartManagement = smartManagement;
onInit?.call();
... ... @@ -211,10 +268,40 @@ class GetMaterialApp extends StatelessWidget {
home: home,
routes: routes ?? const <String, WidgetBuilder>{},
initialRoute: initialRoute,
onGenerateRoute: (namedRoutes == null || onUnknownRoute != null
? onGenerateRoute
: namedRoutesGenerate),
onGenerateInitialRoutes: onGenerateInitialRoutes,
onGenerateRoute: (getPages != null
? generator
: namedRoutes != null ? namedRoutesGenerate : onGenerateRoute),
onGenerateInitialRoutes: onGenerateInitialRoutes ??
(getPages == null || home != null)
? null
: (st) {
final match = _routeTree.matchRoute(initialRoute);
print(initialRoute);
print(match.parameters);
Get.parameters = match.parameters;
return [
GetRouteBase(
page: null,
route: match.route.page,
title: match.route.title,
parameter: match.parameters,
settings:
RouteSettings(name: initialRoute, arguments: null),
maintainState: match.route.maintainState,
curve: match.route.curve,
alignment: match.route.alignment,
opaque: match.route.opaque,
binding: match.route.binding,
bindings: match.route.bindings,
transitionDuration: (transitionDuration == null
? match.route.transitionDuration
: transitionDuration),
transition: match.route.transition,
popGesture: match.route.popGesture,
fullscreenDialog: match.route.fullscreenDialog,
)
];
},
onUnknownRoute: onUnknownRoute,
navigatorObservers: (navigatorObservers == null
? <NavigatorObserver>[GetObserver(routingCallback)]
... ... @@ -246,3 +333,5 @@ class GetMaterialApp extends StatelessWidget {
});
}
}
ParseRouteTree _routeTree;
... ...
... ... @@ -31,6 +31,7 @@ class GetRouteBase<T> extends PageRoute<T> {
this.alignment,
this.parameter,
this.binding,
this.route,
this.bindings,
this.customBuildPageTransitions,
this.opaque = true,
... ... @@ -39,7 +40,7 @@ class GetRouteBase<T> extends PageRoute<T> {
this.transition,
// this.duration = const Duration(milliseconds: 400),
bool fullscreenDialog = false,
}) : assert(page != null),
}) : // assert(page != null),
assert(maintainState != null),
assert(fullscreenDialog != null),
// assert(opaque),
... ... @@ -56,6 +57,8 @@ class GetRouteBase<T> extends PageRoute<T> {
/// Builds the primary contents of the route.
final Widget page;
final GetPageBuilder route;
final Widget customBuildPageTransitions;
final bool popGesture;
... ... @@ -196,14 +199,13 @@ class GetRouteBase<T> extends PageRoute<T> {
@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
final Widget child = page;
final Widget result = Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: child,
child: (route == null ? page : route()),
);
assert(() {
if (child == null) {
if (route == null && page == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'The builder for route "${settings.name}" returned null.'),
... ...
... ... @@ -4,6 +4,7 @@ import 'transitions_type.dart';
class GetRoute {
final Widget page;
final String name;
final bool popGesture;
final Map<String, String> parameter;
final String title;
... ... @@ -11,6 +12,7 @@ class GetRoute {
final Curve curve;
final Alignment alignment;
final bool maintainState;
final GetPageBuilder route;
final bool opaque;
final Bindings binding;
final List<Bindings> bindings;
... ... @@ -22,10 +24,12 @@ class GetRoute {
const GetRoute({
@required this.page,
this.title,
this.name,
this.settings,
this.maintainState = true,
this.curve = Curves.linear,
this.alignment,
this.route,
this.parameter,
this.opaque = true,
this.transitionDuration = const Duration(milliseconds: 400),
... ... @@ -39,3 +43,45 @@ class GetRoute {
assert(maintainState != null),
assert(fullscreenDialog != null);
}
class GetPage {
final String name;
final GetPageBuilder page;
final bool popGesture;
final Map<String, String> parameter;
final String title;
final Transition transition;
final Curve curve;
final Alignment alignment;
final bool maintainState;
final bool opaque;
final Bindings binding;
final List<Bindings> bindings;
final Widget customTransition;
final Duration transitionDuration;
final bool fullscreenDialog;
final RouteSettings settings;
const GetPage({
@required this.name,
@required this.page,
this.title,
this.settings,
this.maintainState = true,
this.curve = Curves.linear,
this.alignment,
this.parameter,
this.opaque = true,
this.transitionDuration = const Duration(milliseconds: 400),
this.popGesture,
this.binding,
this.bindings,
this.transition,
this.customTransition,
this.fullscreenDialog = false,
}) : assert(page != null),
assert(name != null),
assert(maintainState != null),
assert(fullscreenDialog != null);
}
... ...
import 'package:flutter/widgets.dart';
enum Transition {
fade,
rightToLeft,
... ... @@ -12,3 +14,5 @@ enum Transition {
cupertino,
custom
}
typedef GetPageBuilder = Widget Function();
... ...
... ... @@ -32,8 +32,11 @@ class _RxImpl<T> implements RxInterface<T> {
});
}
bool firstRebuild = true;
set value(T val) {
if (_value == val) return;
if (_value == val && !firstRebuild) return;
firstRebuild = false;
_value = val;
subject.add(_value);
}
... ... @@ -240,10 +243,10 @@ class ListX<E> extends Iterable<E> implements RxInterface<E> {
Iterator<E> get iterator => _list.iterator;
@override
bool get isEmpty => _list.isEmpty;
bool get isEmpty => value.isEmpty;
@override
bool get isNotEmpty => _list.isNotEmpty;
bool get isNotEmpty => value.isNotEmpty;
StreamController<E> subject = StreamController<E>.broadcast();
Map<Stream<E>, StreamSubscription> _subscriptions = Map();
... ...
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version: 2.13.1
version: 2.14.0
homepage: https://github.com/jonataslaw/get
environment:
... ...
... ... @@ -20,11 +20,11 @@ void main() {
await tester.pumpWidget(
Wrapper(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: FirstScreen()),
'/second': GetRoute(page: SecondScreen()),
'/third': GetRoute(page: ThirdScreen())
},
namedRoutes: [
GetPage(page: () => FirstScreen(), name: '/'),
GetPage(page: () => SecondScreen(), name: '/second'),
GetPage(page: () => ThirdScreen(), name: '/third'),
],
child: Container(),
),
);
... ... @@ -58,12 +58,12 @@ void main() {
await tester.pumpWidget(
Wrapper(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: Container()),
'/first': GetRoute(page: FirstScreen()),
'/second': GetRoute(page: SecondScreen()),
'/third': GetRoute(page: ThirdScreen())
},
namedRoutes: [
GetPage(name: '/', page: () => Container()),
GetPage(name: '/first', page: () => FirstScreen()),
GetPage(name: '/second', page: () => SecondScreen()),
GetPage(name: '/third', page: () => ThirdScreen()),
],
child: Container(),
),
);
... ... @@ -109,12 +109,12 @@ void main() {
await tester.pumpWidget(
Wrapper(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: Container()),
'/first': GetRoute(page: FirstScreen()),
'/second': GetRoute(page: SecondScreen()),
'/third': GetRoute(page: ThirdScreen())
},
namedRoutes: [
GetPage(page: () => Container(), name: '/'),
GetPage(page: () => FirstScreen(), name: '/first'),
GetPage(page: () => SecondScreen(), name: '/second'),
GetPage(page: () => ThirdScreen(), name: '/third'),
],
child: Container(),
),
);
... ... @@ -142,12 +142,12 @@ void main() {
await tester.pumpWidget(
Wrapper(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: Container()),
'/first': GetRoute(page: FirstScreen()),
'/second': GetRoute(page: SecondScreen()),
'/third': GetRoute(page: ThirdScreen())
},
namedRoutes: [
GetPage(page: () => Container(), name: '/'),
GetPage(page: () => FirstScreen(), name: '/first'),
GetPage(page: () => SecondScreen(), name: '/second'),
GetPage(page: () => ThirdScreen(), name: '/third'),
],
child: Container(),
),
);
... ... @@ -191,12 +191,12 @@ void main() {
await tester.pumpWidget(
Wrapper(
initialRoute: '/',
namedRoutes: {
'/': GetRoute(page: Container()),
'/first': GetRoute(page: FirstScreen()),
'/second': GetRoute(page: SecondScreen()),
'/third': GetRoute(page: ThirdScreen())
},
namedRoutes: [
GetPage(page: () => Container(), name: '/'),
GetPage(page: () => FirstScreen(), name: '/first'),
GetPage(page: () => SecondScreen(), name: '/second'),
GetPage(page: () => ThirdScreen(), name: '/third'),
],
child: Container(),
),
);
... ... @@ -373,8 +373,6 @@ void main() {
expect(Get.isSnackbarOpen, true);
await tester.pump(const Duration(seconds: 1));
});
}
class FirstScreen extends StatelessWidget {
... ...
... ... @@ -3,7 +3,7 @@ import 'package:get/get.dart';
class Wrapper extends StatelessWidget {
final Widget child;
final Map<String, GetRoute> namedRoutes;
final List<GetPage> namedRoutes;
final String initialRoute;
final Transition defaultTransition;
... ... @@ -20,7 +20,7 @@ class Wrapper extends StatelessWidget {
return GetMaterialApp(
defaultTransition: defaultTransition,
initialRoute: initialRoute,
namedRoutes: namedRoutes,
getPages: namedRoutes,
home: Scaffold(
body: child,
),
... ...