dart_ng_forms 0.2.6 copy "dart_ng_forms: ^0.2.6" to clipboard
dart_ng_forms: ^0.2.6 copied to clipboard

Reactive Forms architecture in Flutter inspired by Angular's FormGroup/FormControl pattern and integration with TextEditingController.

example/main.dart

import 'package:flutter/material.dart';

import 'example_custom_text_field.dart';
import 'example_form.dart';

class ExampleFormScreen extends StatefulWidget {
  const ExampleFormScreen({super.key});

  @override
  State<ExampleFormScreen> createState() => _ExampleFormScreenState();
}

class _ExampleFormScreenState extends State<ExampleFormScreen> {
  late ExampleForm form;

  @override
  void initState() {
    super.initState();
    form = ExampleForm();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Reactive Form Example')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            // Campo Name
            CustomTextField(
              formGroup: form,
              name: 'name',
            ),
            const SizedBox(height: 16),
            // Campo Email
            CustomTextField(
              formGroup: form,
              name: 'email',
            ),
            const SizedBox(height: 32),
            ElevatedButton(
              onPressed: () {
                if (form.valid) {
                  final data = form.toModel();
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text('Data: $data')),
                  );
                } else {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Form inválido')),
                  );
                }
              },
              child: const Text('Submit'),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
37
downloads

Publisher

unverified uploader

Weekly Downloads

Reactive Forms architecture in Flutter inspired by Angular's FormGroup/FormControl pattern and integration with TextEditingController.

Homepage
Repository (GitHub)
View/report issues

Topics

#form #state-management #validation #flutter #reactive-forms

Documentation

API reference

License

MIT (license)

Dependencies

flutter, result_dart

More

Packages that depend on dart_ng_forms