getx_route_generator_q1 1.1.9
getx_route_generator_q1: ^1.1.9 copied to clipboard
getx_route_generator is a code generation library based on build_runner, designed to generate a route table for pages using the GetX library.
getx_route_generator_q1 #
Language: English | 中文
getx_route_generator_q1
is a code generation library based on build_runner
, designed to generate a route table for pages using the GetX library. Say goodbye to manually writing route paths and GetPage mappings.
New #
You can enable static model in pubspec.yaml like this.
...
getx_route_generator_q1:
static_to_page: true
flutter:
uses-material-design: true
...
which generate static toPage method extension like:
extension ChatVideoPreviewPageToPage on ChatVideoPreviewPage {
static Future<void>? toPage({
required final String userId,
required final CallType callType,
required final bool isFree,
final CallChannel? channel,
final bool preventDuplicates = true,
int? id,
}) {
return Get.toNamed<void>(
RouteTable.chatVideoPreviewPage,
preventDuplicates: preventDuplicates,
id: id,
arguments: {
'userId': userId,
'callType': callType,
'isFree': isFree,
'channel': channel,
},
);
}
static Future<void>? offAndToPage({
required final String userId,
required final CallType callType,
required final bool isFree,
final CallChannel? channel,
int? id,
}) {
return Get.offAndToNamed<void>(
RouteTable.chatVideoPreviewPage,
id: id,
arguments: {
'userId': userId,
'callType': callType,
'isFree': isFree,
'channel': channel,
},
);
}
}
Usage #
Add the latest version of getx_route_generator_q1
to your dependencies.
dependencies:
getx_route_annotations_q1: [latest-version]
dev_dependencies:
getx_route_generator_q1: [latest-version]
Add the GetXRoutePage annotation above the class of the specific route page.
@GetXRoutePage("/home")
class HomePage extends StatefulWidget {}
(PS: GetXRoutePage requires passing a path. In the generated route table class, a global variable like the one below will be automatically generated and can be used directly.)
static const String home = '/home';
Then run the following command in the terminal:
flutter pub run build_runner build
getx_route_generator_q1 will automatically generate a route_table.dart file in the lib/generated directory based on the annotations you added. The generated code looks like this:
import 'package:get/get.dart';
import 'package:xxx/page/home_page.dart';
class RouteTable {
static const String home = '/home';
static final List<GetPage> pages = [
GetPage(name: '/home', page: () => HomePage()),
];
}
Certainly, you can also use the watch command, so you don't have to rerun the build command every time you make changes to the route pages.
flutter pub run build_runner watch
Bindings #
If you need to add a binding for the GetPage, you can use the following method to add the required controllers or objects. Add the dependencies parameter within the GetXRoutePage annotation, passing an array.
@GetXRoutePage("/home",, dependencies:[XController,XXController,XXXController])
class HomePage extends StatefulWidget {}
The generated code looks like this:
class RouteTable {
static const String home = '/home';
static final List<GetPage> pages = [
GetPage(
name: '/home',
page: () => HomePage(),
binding: BindingsBuilder(() {
Get.lazyPut<XController>(() => XController());
Get.lazyPut<XXController>(() => XXController());
Get.lazyPut<XXXController>(() => XXXController());
}),
),
];
}
That's it!