Code Monkey home page Code Monkey logo

Comments (2)

kauemurakami avatar kauemurakami commented on June 28, 2024 1

@kevin4dhd
Let's contextualize the scenario.
Assuming you have a registration dialog in a registration module.
in the module you have the possibility to create components in the widgets folder of this module.
You can place the dialog on one component by calling the form from another component.
I usually use a textformfield, button, in global widgets, so you can use that component inside any module without depending on another module.
An example :

class CustomTextFormField extends StatelessWidget {
  final Function(String value) onSaved;
  final Function(String value) onChanged;
  final Function(String value) validator;
  final bool emailCheck;
  final String text;
  final Widget sufixIcon;
  final Widget prefixIcon;
  final TextInputAction action;
  final TextInputType type;
  final bool obscure;
  final TextEditingController controller;
  final TextDirection direction;
  final int max;
  final int maxLines;
  final String initialValue;
  final String hintText;
  final formatter;
  final Color color;
  final bool enable;

  CustomTextFormField(
      {this.maxLines = 1,
      this.enable = true,
      this.formatter = const <TextInputFormatter>[],
      this.initialValue,
      this.emailCheck,
      this.text,
      this.onChanged,
      this.onSaved,
      this.validator,
      this.sufixIcon,
      this.action,
      this.color,
      this.type,
      this.obscure = false,
      this.controller,
      this.direction = TextDirection.ltr,
      this.max,
      this.prefixIcon,
      this.hintText});

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      enabled: this.enable,
      inputFormatters: this.formatter,
      maxLines: this.maxLines,
      initialValue: this.initialValue,
      maxLength: this.max,
      textDirection: this.direction,
      controller: this.controller,
      obscureText: this.obscure,
      style: TextStyle(fontSize: 16),
      keyboardType: this.type,
      cursorColor: customPrimary,
      decoration: InputDecoration(
          hintText: this.hintText,
          hintStyle: TextStyle(color: this.color),
          //contentPadding: EdgeInsets.only(top: 5),
          border: UnderlineInputBorder(
              borderSide: BorderSide(color: customPrimary)),
          labelText: this.text,
          suffixIcon: this.sufixIcon,
          prefixIcon: this.prefixIcon),
      onChanged: (value) => this.onChanged(value),
      onSaved: (value) => this.onSaved(value),
      validator: (value) => this.validator(value),
      textInputAction: this.action,
    );
  }
}

Could be used in :
...

  /app
    /widgets
       - custom_tff.dart
    /modules
      /registration
        /widgets
          - dialog.dart
        - controller.dart
        - repository.dart
        - page.dart
      /another
        /widgets
          - another_widget_using_custom_tff.dart
        - controller.dart
        - repository.dart
        - page.dart

Where your text form field can be used in several modules as stated, or you can add it exclusively as part of that module
...

  /app
    /widgets
    /modules
      /registration
        /widgets
          - custom_tff.dart
          - dialog.dart
        - controller.dart
        - repository.dart
        - page.dart

And call it with Get.dialog (MyDialog ())

from getx_pattern.

kevin4dhd avatar kevin4dhd commented on June 28, 2024 1

Thanks 👏

from getx_pattern.

Related Issues (20)

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.