glade_forms 3.0.0 copy "glade_forms: ^3.0.0" to clipboard
glade_forms: ^3.0.0 copied to clipboard

A universal way to define form validators with support of translations.

example/lib/example.dart

import 'package:flutter/material.dart';
import 'package:glade_forms/glade_forms.dart';

// ! When updating dont forget to update README.md quickstart as well
class _Model extends GladeModel {
  late StringInput name;
  late IntInput age;
  late StringInput email;
  late IntInput income;

  @override
  List<GladeInput<Object?>> get inputs => [name, age, email, income];

  @override
  void initialize() {
    name = GladeInput.stringInput(inputKey: 'name');
    age = GladeInput.intInput(value: 0, inputKey: 'age');
    email = GladeInput.stringInput(validator: (validator) => (validator..isEmail()).build(), inputKey: 'email');
    income = GladeInput.intInput(
        value: 10000, validator: (validator) => (validator..isMin(min: 1000)).build(), inputKey: 'income');

    super.initialize();
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    return GladeFormBuilder.create(
      create: (context) => _Model(),
      builder: (context, model, _) => Padding(
        padding: const EdgeInsets.all(32),
        child: Form(
          autovalidateMode: AutovalidateMode.onUserInteraction,
          child: Column(
            children: [
              TextFormField(
                controller: model.name.controller,
                validator: model.name.textFormFieldInputValidator,
                decoration: const InputDecoration(labelText: 'Name'),
              ),
              TextFormField(
                controller: model.age.controller,
                validator: model.age.textFormFieldInputValidator,
                decoration: const InputDecoration(labelText: 'Age'),
              ),
              TextFormField(
                controller: model.email.controller,
                validator: model.email.textFormFieldInputValidator,
                decoration: const InputDecoration(labelText: 'Email'),
              ),
              TextFormField(
                controller: model.income.controller,
                validator: model.income.textFormFieldInputValidator,
                decoration: const InputDecoration(labelText: 'income'),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: model.isValid ? () {} : null,
                child: const Text('Save'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
17
likes
150
pub points
61%
popularity
screenshot

Publisher

verified publishernetglade.cz

A universal way to define form validators with support of translations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, equatable, flutter, meta, provider

More

Packages that depend on glade_forms