plus_router 1.0.0-dev.7 copy "plus_router: ^1.0.0-dev.7" to clipboard
plus_router: ^1.0.0-dev.7 copied to clipboard

Easy Router for web application. This package using Navigator 2.0 system for routing easy in web application

example/main.dart

import 'package:flutter/material.dart';
import 'package:plus_router/plus_router.dart';

void main() {
  runApp(MyApp());
}

List<PlusRoute> routes = [
  PlusRoute(
    path: "/",
    builder: (state, args) => HomePage(routerState: state)
  ),
  PlusRoute(
    path: "/home/list",
    builder: (state, args) => WelcomePage(routerState: state)
  ),
  PlusRoute(
    path: "/home/list/:id",
    builder: (state, args) => HomeDetailPage(routerState: state, args: args)
  )
];

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Demo Route',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),

      // routeInformationParser: PlusRouteInformationParser(newRoutes, 
      //   initialRoute: "/home" // Custom initialRoute
      // ),
      routeInformationParser: PlusRouteInformationParser(routes),

      // routerDelegate: PlusRouterDelegate(routes, 
      //   loadPage: CustomLoadingPage()
      // )
      routerDelegate: PlusRouterDelegate(routes)
    );
  }
}

class HomePage extends StatelessWidget {
  final PlusRouterState routerState;
  HomePage({ Key? key, required this.routerState }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(child: Column(
        children: [
          Container(child: Text("Home Page")),
          Container(
            child: ElevatedButton(
              onPressed: () { 
                this.routerState.navigateByUrl("/home/list");
              },
              child: Text("Click"),
            )
          )
        ],
      )),
    );
  }
}

class WelcomePage extends StatelessWidget {
  final PlusRouterState routerState;
  const WelcomePage({ Key? key, required this.routerState }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
       body: Center(child: Column(
        children: [
          Container(child: Text("Welcome Page")),
          Container(
            child: ElevatedButton(
              onPressed: () { 
                this.routerState.navigateByUrl("/home/list/100");
              },
              child: Text("Click"),
            )
          )
        ],
      )),
    );
  }
}

class HomeDetailPage extends StatelessWidget {
  final PlusRouterState routerState;
  final Map<String, dynamic> args;
  const HomeDetailPage({ Key? key, required this.routerState, required this.args }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String arg = args["id"] ?? "None";

    return Scaffold(
       body: Center(child: Column(
        children: [
          Container(child: Text("Detail Page $arg")),
          Container(
            child: ElevatedButton(
              onPressed: () {
                this.routerState.back();
              },
              child: Text("Click"),
            )
          )
        ],
      )),
    );
  }
}
2
likes
140
points
35
downloads

Publisher

verified publisherwritecode.dev

Weekly Downloads

Easy Router for web application. This package using Navigator 2.0 system for routing easy in web application

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on plus_router