simple_router 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

example #

A new Flutter project.

Using #

The easiest way to use the router is to set the navigatorKey provided by the Router to the material app. Using that you can navigate from anywhere on your app (including places that don't have a BuildContext), including BloC's (not saying you have to do that by any means).

class MyApp extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
      return MaterialApp(  
          navigatorKey: SimpleRouter.getKey(),  
          title: 'Flutter Demo',  
          theme: ThemeData(  
              primarySwatch: Colors.blue,  
          ),  
          home: MyHomePage(title: 'Flutter Router Example'),  
      );  
  }  
}

Another great thing you can do is implement to functions of the Router: onBeforePush and onAfterPush, those functions are called before and after the navigation occurs. They are good to implement some kind of logging when entering or leaving the page for example.

You can choose beetwen Material or Cupertino transitions. To pick cupertino just set the useCupertinoTransition of the SimpleRouter to true (default is false).

[0.1.0] #

Fully usable api

[0.0.3+2] - Improve #

Correcting to named parameter

[0.0.3+1] - Added New Features #

Add the possibility to pass a name to the route

[0.0.3] - Added New Features #

Add the possibility to add middlewares on transitions

[0.0.2] - Added Documentation #

Added some documentation on how to use the package and the licensing

[0.0.1] - First release #

The first release has common features like navigating without context, and appending actions on before and after the push of the route.

example/lib/main.dart

import 'package:example/page2.dart';
import 'package:flutter/material.dart';
import 'package:simple_router/simple_router.dart';

void main() {
  SimpleRouter.onBeforePush = (widget) {
    print('[Router]: Navigated to ${widget.toString()}');
  };
  SimpleRouter.onAfterPush = (widget) {
    print('[Router]: Navigated out of ${widget.toString()}');
  };
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: SimpleRouter.getKey(),
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Router Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Home page',
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => SimpleRouter.forward(Page2()),
        child: Icon(Icons.chevron_right),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  simple_router: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:simple_router/simple_router.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test