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

outdated

Provide statically registered page navigation template library.

static_route #

Static page navigation router template library.

pub package

Getting Started #

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

class HomePage extends StatelessWidget {

  static final route = StaticRoute(
    name: 'HomePage',
    builder: (RouteSettings settings) {
      return MaterialPageRoute(
        settings: settings,
        builder: (context) => 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();
}

在某个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
0
pub points
31%
popularity

Publisher

unverified uploader

Provide statically registered page navigation template library.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on static_route