jonataslaw
Committed by GitHub

Add files via upload

... ... @@ -16,4 +16,12 @@
## [1.1.0]
- Add support to Push.named
\ No newline at end of file
- Add support to named routes
## [1.2.0]
- Add routes navigation with no context
## [1.2.1]
- Fix bug currentState = null
\ No newline at end of file
... ...
# Get
A consistent Flutter route navigation library that does not rebuild materialApp with each navigation.
A consistent Flutter route navigation library that navigate with no context and not rebuild materialApp with each navigation.
## Getting Started
Flutter's conventional navigation method has a route reconstruction bug that makes it inconsistent
for large applications with undefined routes.
Get came to solve this problem.
Plus, get makes navigation much clearer and more concise for beginners. The nomenclatures u
sed by Flutter routes often confuse those who start with the framework.
Get is friendly to those who came from Web programming, and those who never programmed,
with a clearer navigation system.
In addition, Get needs no context, also solving Flutter's biggest problem with patterns like BLoC.
Get also makes navigation much clearer and more concise for beginners and friendly to those who came from Web programming.
## How to use?
Add this to your package's pubspec.yaml file:
dependencies:
get:
And import it:
```dart
import 'package:get/get.dart';
```
Add GetKey to your MaterialApp and enjoy:
```dart
MaterialApp(
navigatorKey: Get.key,
home: MyHome(),
)
```
To navigate to a new screen:
```dart
Get.to(context, NextScreen());
Get.to(NextScreen());
```
To return to previous screen
```dart
Get.back(context);
Get.back();
```
To go to the next screen and no option to go back to the previous screen (for use in SplashScreens, login screens and etc.)
```dart
Get.off(context, NextScreen());
Get.off(NextScreen());
```
To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)
```dart
Get.offAll(context, NextScreen());
Get.offAll(NextScreen());
```
Is possible used default namedRoutes from flutter?
... ... @@ -48,6 +61,7 @@ void main() {
runApp(MaterialApp(
onGenerateRoute: Router.generateRoute,
initialRoute: "/",
navigatorKey: Get.key,
title: 'Navigation',
));
}
... ... @@ -80,7 +94,7 @@ class FirstRoute extends StatelessWidget {
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.pushNamed(context, "/second");
Get.toNamed("/second");
},
),
),
... ... @@ -98,7 +112,7 @@ class SecondRoute extends StatelessWidget {
body: Center(
child: RaisedButton(
onPressed: () {
Get.back(context);
Get.back();
},
child: Text('Go back!'),
),
... ...
... ... @@ -4,6 +4,7 @@ import 'package:get/get.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
navigatorKey: Get.key,
home: FirstRoute(),
));
}
... ... @@ -19,7 +20,7 @@ class FirstRoute extends StatelessWidget {
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Get.to(context, SecondRoute());
Get.to(SecondRoute());
},
),
),
... ... @@ -37,7 +38,7 @@ class SecondRoute extends StatelessWidget {
body: Center(
child: RaisedButton(
onPressed: () {
Get.back(context);
Get.back();
},
child: Text('Go back!'),
),
... ...
library get;
export 'src/getroute.dart';
export 'src/routes.dart';
... ...
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class GetRoute<T> extends PageRoute<T> {
/// Construct a MaterialPageRoute whose contents are defined by [builder].
///
/// The values of [builder], [maintainState], and [fullScreenDialog] must not
/// be null.
GetRoute({
@required this.builder,
RouteSettings settings,
this.opaque = false,
this.maintainState = true,
bool fullscreenDialog = false,
}) : assert(builder != null),
assert(maintainState != null),
assert(fullscreenDialog != null),
assert(opaque != null),
super(settings: settings, fullscreenDialog: fullscreenDialog);
/// Builds the primary contents of the route.
final WidgetBuilder builder;
@override
final bool maintainState;
/// Allows you to set opaque to false to prevent route reconstruction.
@override
final bool opaque;
@override
Duration get transitionDuration => const Duration(milliseconds: 300);
@override
Color get barrierColor => null;
@override
String get barrierLabel => null;
@override
bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) {
return previousRoute is GetRoute || previousRoute is CupertinoPageRoute;
}
@override
bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
// Don't perform outgoing animation if the next route is a fullscreen dialog.
return (nextRoute is GetRoute && !nextRoute.fullscreenDialog)
|| (nextRoute is CupertinoPageRoute && !nextRoute.fullscreenDialog);
}
@override
Widget buildPage(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
final Widget result = builder(context);
assert(() {
if (result == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The builder for route "${settings.name}" returned null.'),
ErrorDescription('Route builders must never return null.')
]);
}
return true;
}());
return Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: result,
);
}
@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme;
return theme.buildTransitions<T>(this, context, animation, secondaryAnimation, child);
}
@override
String get debugLabel => '${super.debugLabel}(${settings.name})';
}
... ...
import 'package:flutter/widgets.dart';
import 'getroute.dart';
class Get {
static Get _get;
static GlobalKey<NavigatorState> key = new GlobalKey<NavigatorState>();
factory Get() {
if (_get == null) _get = Get._();
return _get;
}
Get._();
static to(Widget page, {bool rebuildRoutes = false}) {
return key.currentState
.push(GetRoute(opaque: rebuildRoutes, builder: (_) => page));
}
static toNamed(String page, {arguments}) {
return key.currentState.pushNamed(page, arguments: arguments);
}
static offNamed(String page, {arguments}) {
return key.currentState
.pushReplacementNamed(page, arguments: arguments);
}
static offAllNamed(
String newRouteName,
RoutePredicate predicate, {
Object arguments,
}) {
return key.currentState
.pushNamedAndRemoveUntil(newRouteName, predicate, arguments: arguments);
}
static back() {
return key.currentState.pop();
}
static off(Widget page, {bool rebuildRoutes = false}) {
return key.currentState
.pushReplacement(GetRoute(opaque: rebuildRoutes, builder: (_) => page));
}
static offAll(Widget page, RoutePredicate predicate,
{bool rebuildRoutes = false}) {
return key.currentState.pushAndRemoveUntil(
GetRoute(opaque: rebuildRoutes, builder: (_) => page), predicate);
}
}
... ...
name: get
description: A consistent Flutter route navigation library that does not rebuild materialApp with each navigation..
version: 1.1.0
description: A consistent Flutter route navigation library that navigate with no context and not rebuild materialApp with each navigation.
version: 1.2.1
author: Jonny Borges <jonataborges01@gmail.com>
homepage: https://github.com/jonataslaw/get
... ...