property_ui_generator 1.0.4 copy "property_ui_generator: ^1.0.4" to clipboard
property_ui_generator: ^1.0.4 copied to clipboard

generate GUI code for edit on class fields from class.

Generator for property_ui_annotation
This is useful when you need to arrange a large number of widgets, such as in a configuration screen, and you want each value to be synchronized with the class.
This package generates code that inspects the fields marked with annotations and places the appropriate editing widgets.
For example, a TextField will be generated for a String type, and a Switch for a bool type.

Below is the source code and the corresponding actual widget placement example.

import 'package:property_ui_annotation/property_ui_annotation.dart';

class Example {
  @Property(readonly: true, hintText: "enter your name.")
  String name;
  @Property()
  double height;
  @Property()
  int age;
  @Property()
  bool die;
  @Property(debug: true)
  bool debugParameter;

  Example() {
    this.name = "user";
    this.height = 180;
    this.age = 20;
    this.die = false;
    this.debugParameter = false;
  }
}

screenshot

The code to place this widget itself looks like this Although it is not excerpted here, the classes ExampleUI and ExampleUIState are actually generated.

class _MyHomePageState extends State<MyHomePage> {
  Example _example;

  @override
  void initState() {
    super.initState();
    this._example = Example();
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(children: [ExampleUI(_example), Spacer()]),
      ),
    );
  }
}

example project is here.

Usage #

Add packages to your pubspec.yaml.

dependencies:
  property_ui_annotation: ^1.0.1

dev_dependencies:
  build_runner: ^1.10.11
  property_ui_generator: ^1.0.4

Add @Property annotation to your class.

import 'package:property_ui_annotation/property_ui_annotation.dart';

class Example {
  @Property(readonly: true, hintText: "enter your name.")
  String name;
  @Property()
  double height;
  @Property()
  int age;
  @Property()
  bool die;
  @Property(debug: true)
  bool debugParameter;

  Example() {
    this.name = "user";
    this.height = 180;
    this.age = 20;
    this.die = false;
    this.debugParameter = false;
  }
}

Run build_runner on your project.

flutter packages pub run build_runner build

Supported data types #

  • String
  • int
  • double
  • bool
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

generate GUI code for edit on class fields from class.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

analyzer, build, code_builder, property_ui_annotation, source_gen

More

Packages that depend on property_ui_generator