GithubHelp home page GithubHelp logo

jy02404353 / getx_route_generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from panyiho/getx_route_generator

0.0 0.0 0.0 19 KB

getx_route_generator is a code generation library based on build_runner, designed to generate a route table for pages using the GetX library

License: Apache License 2.0

Dart 100.00%

getx_route_generator's Introduction

getx_route_generator

Language: English | δΈ­ζ–‡

getx_route_generator 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.

Usage

Add the latest version of getx_route_generator to your dependencies.

  dependencies: 
    getx_route_annotations: [latest-version]

  dev_dependencies:                    
    getx_route_generator: [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 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!

getx_route_generator's People

Contributors

panyiho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.