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

Provide statically registered page navigation template library.

static_route #

Static page navigation router template library.

pub package

Getting Started #

在每个可导航页面中增加StaticRouteFactory类型的静态route变量

class HomePage extends StatelessWidget {

  static final route = StaticRouteFactory(
    name: 'HomePage',
    builder: (BuildContext context, Object? arguments) {
      return HomePage();
    },
  );

  ...
}

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

  final String content;

  static final route = StaticRouteFactory(
    name: 'NextPage',
    builder: (BuildContext context, Object? arguments) {
      return NextPage(arguments as String);
    },
  );

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

在某个dart文件中,如pages.dart中注册每个可导航页面的route列表

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

在应用入口点MaterialApponGenerateRoute中调用Iterable<StaticRoute>的扩展方法generateRoute注册routeTable中的路由器

MaterialApp(
      ...
      onGenerateRoute: routeTable.generateRoute,
      ...
    );

Usage #

 Navigator.pushNamed(context, NextPage.route.name, arguments: 'from HomePage');
0
likes
160
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

Provide statically registered page navigation template library.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on static_route