router_generator 0.1.2

Dart native js
Flutter Android iOS web

router_generator is a flutter library for router generation.

example/lib/main.dart

import 'package:example/router.router_table.dart';
import 'package:example/model.dart';
import 'package:example/second_page.inject.dart';
import 'package:example/third_page.inject.dart' as third_page;
import 'package:flutter/material.dart';
import 'package:router_generator/router_generator.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
      onGenerateRoute: (RouteSettings settings) {
        String pageName = settings.name;
        var arguments = settings.arguments;
        if (arguments is Map<String, dynamic>) {
          deliverParams(pageName, arguments);
        }
        return MaterialPageRoute(builder: (_) {
          return getWidgetByPageName(pageName);
        });
      },
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text('Router Generator'),
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            InkWell(
              child: Text(
                'second page',
                style: TextStyle(fontSize: 20),
              ),
              onTap: () {
                Navigator.of(context).pushNamed('second',
                    arguments: createRouteArgs(name: 'bar'));
              },
            ),
            InkWell(
              child: Text('third page', style: TextStyle(fontSize: 20)),
              onTap: () {
                Navigator.of(context).pushNamed('third',
                    arguments: third_page.createRouteArgs(Person(23, 'kobe')));
              },
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
110
pub points
25%
popularity

router_generator is a flutter library for router generation.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

wjb18814888154@gmail.com

License

Apache 2.0 (LICENSE)

Dependencies

source_gen

More

Packages that depend on router_generator