The App I’m working on is a punch card App designed to help users stick to their goals and stick to what they set out to do.
As the project is only in its early stages, the following structures have been established as needed:
Refer to some of the official plug-ins and the directories suggested in the official getX documentation:
There is no idea to separate a layer of state for the time being. Here are the details of each layer:
Final Controller = get.put (CounterController()); If every interface has to be instantiated once, it’s a bit of a hassle. Get. Find () : GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController: GetxController
- Routing, state manager, and dependency manager can be fully integrated
- This section describes two ways to use getX. The first way is recommended
- No binding has any effect on functionality.
- The first is Binding using named routes
Class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) {return GetMaterialApp(initialRoute: RouteConfig.onePage, getPages: RouteConfig.getPages, ); Class RouteConfig {static const String onePage = "/onePage"; static const String twoPage = "/twoPage"; static final List<GetPage> getPages = [ GetPage( name: onePage, page: () => const OnePage(), binding: OnePageBinding(), ), // GetPage( // name: twoPage, // page: () => TwoPage(), // binding: TwoPageBinding(), // ), ]; } {@override void dependencies() {get.lazyput (() => CounterController()); }} class CounterController extends GetxController{var count = 0; Void increase(){count++; update(); }}Copy the code
- Second: initialize all bindings using initialBinding
Class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key); Override Widget Build (BuildContext Context) {return GetMaterialApp(/// initialize all Binding initialBinding: AllControllerBinding(), home: const OnePage(), ); }} Class AllControllerBinding extends Bindings {@override void dependencies() {get.lazyput (() => CounterController()); ///Get.lazyPut(() => OneController()); ///Get.lazyPut(() => TwoController()); }}Copy the code