static_route 1.0.0 copy "static_route: ^1.0.0" to clipboard
static_route: ^1.0.0 copied to clipboard

outdated

Static page navigation router template library.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      onGenerateRoute: routeTable.generateRoute,
      initialRoute: HomePage.route.name,
    );
  }
}

final routeTable = <StaticRoute>[
  HomePage.route,
  NextPage.route,
];

class HomePage extends StatelessWidget {

  static final route = StaticRoute(
    name: 'HomePage',
    builder: (RouteSettings settings) {
      return MaterialPageRoute(
        settings: settings,
        builder: (context) => HomePage(),
      );
    },
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('HomePage')),
      body: Center(
        child: RaisedButton(
          child: Text('Next page'),
          onPressed: () {
            Navigator.pushNamed(context, NextPage.route.name, arguments: 'from HomePage');
          },
        ),
      ),
    );
  }
}

class NextPage extends StatefulWidget {
  NextPage(this.content);

  final String content;

  static final route = StaticRoute(
    name: 'NextPage',
    builder: (RouteSettings settings) {
      return MaterialPageRoute(
        settings: settings,
        builder: (context) => NextPage(settings.arguments),
      );
    },
  );

  @override
  State createState() => _NextPageState();
}

class _NextPageState extends State<NextPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('NextPage')),
      body: Center(
        child: Text(widget.content),
      ),
    );
  }
}
0
likes
0
pub points
31%
popularity

Publisher

unverified uploader

Static page navigation router template library.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on static_route