router_management 1.3.2 copy "router_management: ^1.3.2" to clipboard
router_management: ^1.3.2 copied to clipboard

outdated

Router Management is a package with powered tools for routing your flutter application

Router Management #


Instructions #

Define your Route Management class

class AppRoutes {
  AppRoutes._();

  //A controller to manage the app routes
  static final router = RouterController();

  //Variables that contains screen's name
  static const intro = '/';

  static const home = '/home';

  //Function that add routes to RouterController manage routes
  static void setRoutes() {
    //Create app routes
    router.addRoute(
      //Screen name
      intro,
      //WidgetBuilder
      (context) => IntroScreen(),
      //Define if the screen will be a fullscreenDialog (Default false)
      fullscreenDialog: false,
      //Define a custom transition duration. Native transitions won't be affected (Default 250 milliseconds)
      transitionDuration: const Duration(milliseconds: 300),
      //Define a custom transition. A custom transition only works if useNativeTransitions is false or the platform is Web (Default right to left with fade in)
      transitionsBuilder: (
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        Widget child,
      ) {
        return FadeTransition(
          opacity: animation,
          child: child,
        );
      },
      //Define if you want or don't want use native transitions (Default true)
      useNativeTransitions: !kIsWeb || Platform.isIOS,
    );
  }
}

Configure your MaterialApp

void main() {
  //initialize the routes
  AppRoutes.setRoutes();
  //initialize your app
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //Initialize the generator into a material app
      onGenerateRoute: AppRoutes.router.onGenerateRoute,
      //Define the app initial route
      initialRoute: AppRoutes.intro,
    );
  }
}
//Navigate to your named screen with params
Map<String,dynamic> params = <String,dynamic>{};
Navigator.pushNamed(context, AppRoutes.home, arguments: params);
Navigator.pushReplacementNamed(context, AppRoutes.home, arguments: params);

//Get params in the build (not recommended)
@override
Widget build(BuildContext context) {
  final Map<String,dynamic> params = ModalRoute.of(context).settings.arguments;
  return Container(
    color: Colors.blue,
  );
}

//Get params in the didChangeDependencies (recommended)
@override
void didChangeDependencies() {
  super.didChangeDependencies();
  final Map<String,dynamic> params = ModalRoute.of(context).settings.arguments;
}
9
likes
0
pub points
57%
popularity

Publisher

verified publishervegasdevelopments.com

Router Management is a package with powered tools for routing your flutter application

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on router_management