static_route

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

static route

static_route #
Static page navigation router template library.

Getting Started #

添加 static_route 到 pubspec.yaml 文件.
import 'package:static_route/static_route.dart';

在每个可导航页面中增加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();
}
copied to clipboard
在某个dart文件中,如pages.dart中注册每个可导航页面的route列表
final routeTable = <StaticRoute>[
HomePage.route,
NextPage.route,
...
];
copied to clipboard
在应用入口点MaterialApp的onGenerateRoute中调用Iterable<StaticRoute>的扩展方法generateRoute注册routeTable中的路由器
MaterialApp(
...
onGenerateRoute: routeTable.generateRoute,
...
);
copied to clipboard
Usage #
Navigator.pushNamed(context, NextPage.route.name, arguments: 'from HomePage');
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.