getx_binding_annotation 0.2.1 copy "getx_binding_annotation: ^0.2.1" to clipboard
getx_binding_annotation: ^0.2.1 copied to clipboard

A Code Generator Plugin to Generate Pages and Dependencies for GetX State Manager base on Annotation.

Getx Dependencies Binding Annotation Generator

PubVersion PubPoints build Star on Github Latest Dartdocs

android ios ios linux windows mac-os

A Code Generator Plugin to Generate Pages and Dependencies for GetX State Manager base on Annotation. This package designed to prevent adding dependencies one by one into the lists of the GetX. You can use it for pages or controllers or any other dependencies.

Contents: #

Getting Started #

Add dependencies in the pubspec.yaml:

dependencies:
  get: ^latest
  getx_binding_annotation: ^latest

dev_dependencies:
  build_runner: ^latest
  getx_binding_annotation_generator: ^latest

Get the Changes by:

flutter pub get

or

dart pub get

Usage #

import 'package:getx_binding_annotation/annotation.dart';

Add desired @Annotation on top of the desired class and set the desired Options.

Such as:

HomePage

@GetPut.page(isInitial: true)
class HomePage extends GetView<HomePageController> {}
@GetPut.controller()
class SettingsController extends GetxController {}

then you should run the build_runner to generate the codes and creating related file and include all the pages, controllers, components and repositories in one place and prepared to use. You can use

dart pub run build_runner build --delete-conflicting-outputs

After a successful generation then you would have the new main.get_put.dart file in the project root folder /lib beside main.dart then you can use the plugin to put variables in suitable places and use them.

import 'main.get_put.dart';
  • GetPutBindings() : for dependency injection
  • GetPutPages.pages : will set all pages into GetX
  • GetPutPages.initialRoute.name : will set the initial route
  • GetPutPages.unknownRoute : will set the unknown route for undetected routes in the app

Make change in main at 'main.dart':

void main() {
  GetPutBindings().dependencies();
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      /// You must set these four functions and variables in your Project
      initialBinding: GetPutBindings(), // Inject all dependencies
      getPages: GetPutPages.pages, // Add all the pages in GetX context
      initialRoute: GetPutPages.initialRoute.name, // Set initial route
      unknownRoute: GetPutPages.unknownRoute, // Set a route for any unknown or undefined route in the app
    );
  }
}

You can check the /example for a more complete example, more details and further information. #

Options #

You can set some annotations and its Options in the @Annotation Available Options:

  • @GetPut.page()
    • as: Change the Name of the Page in the dependencies and use it as another name.
    • route: The plugin will generate a default name based on the page's name, but also, you can set a String for the route and the new route will be used. If the route has not been set, the default generate route will use.
    • isInitial: You should set a initialRoute for the GetX and the app will start by that page and it's route, so it is mandatory. and you can set your initial page by this flag. The plugin would not throw an exception if you set two or more initial pages, but it will set the first page in the generate pages list that marked as initial page as the default initial route.
    • isUnknown: You can set a unknown route for the GetX and the app will show the page by it's route, if there was a change page without valid route. You can set your unknown page by this flag. The plugin would not throw an exception if you set two or more unknown pages, but it will set the first page in the generate pages list that marked as unknown page as the default unknown route.
  • @GetPut.controller()
    • as: Change the Name of the Controller in the dependencies and use it as another name.
  • @GetPut.component()
    • as: Change the Name of the Component in the dependencies and use it as another name.
  • @GetPut.repository()
    • as: Change the Name of Repository in the dependencies and use it as another name.

Some Examples:

Settings:

@GetPut.page()
class SettingsPage extends GetView<SettingsController> {}
@GetPut.controller()
class NotFoundController extends GetxController {}

NotFound: or Unknown:

@GetPut.page(isUnknown: true)
class NotFoundPage extends GetView<NotFoundController> {}
@GetPut.controller()
class NotFoundController extends GetxController {}

Storage Component:

abstract class StorageComponent {}

@GetPut.component(as: 'StorageComponent')
class StorageComponentImpl {}

Remote DataSource Repository:

@GetPut.repository()
class RemoteDataSourceRepository {}

Docs #

build

About Author #

Resam Taghipour #

Pub account Pub Pub

Packages and Dependencies #

Pub Pub Pub Pub Pub

License #

This project is licensed under the 'BSD-3-Clause' License - see the LICENSE for details.

Pub

2
likes
130
points
340
downloads

Publisher

verified publisherresam.site

Weekly Downloads

A Code Generator Plugin to Generate Pages and Dependencies for GetX State Manager base on Annotation.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

resam.site

License

BSD-3-Clause (license)

Dependencies

build_runner, dartdoc

More

Packages that depend on getx_binding_annotation