get 1.2.1 copy "get: ^1.2.1" to clipboard
get: ^1.2.1 copied to clipboard

outdated

A consistent Flutter route navigation library that navigate with no context and not rebuild materialApp with each navigation.

Get #

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. 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:

import 'package:get/get.dart';

Add GetKey to your MaterialApp and enjoy:

MaterialApp(
    navigatorKey: Get.key,
    home: MyHome(),
  )

To navigate to a new screen:

Get.to(NextScreen());

To return to previous screen

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.)

Get.off(NextScreen());

To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)

Get.offAll(NextScreen());

Is possible used default namedRoutes from flutter? Yes, and with no navigation bug Example:

void main() {
  runApp(MaterialApp(
    onGenerateRoute: Router.generateRoute,
    initialRoute: "/",
    navigatorKey: Get.key,
    title: 'Navigation',
  ));
}

class Router {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case '/':
        return GetRoute(builder: (_) => FirstRoute());
      case '/second':
        return GetRoute(builder: (_) => SecondRoute());
      default:
        return GetRoute(
            builder: (_) => Scaffold(
                  body: Center(
                      child: Text('No route defined for ${settings.name}')),
                ));
    }
  }
}

class FirstRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open route'),
          onPressed: () {
            Get.toNamed("/second");
          },
        ),
      ),
    );
  }
}

class SecondRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Get.back();
          },
          child: Text('Go back!'),
        ),
      ),
    );
  }
}
15k
likes
0
points
649k
downloads

Publisher

verified publishergetx.site

Weekly Downloads

A consistent Flutter route navigation library that navigate with no context and not rebuild materialApp with each navigation.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on get