smart_multi_form_fields 1.0.0 copy "smart_multi_form_fields: ^1.0.0" to clipboard
smart_multi_form_fields: ^1.0.0 copied to clipboard

A single, production-grade Flutter form field widget rendering text, password, phone, OTP, date, dropdown, and file inputs via sealed configurations.

example/lib/main.dart

// example/lib/main.dart
//
// Complete working example for package:smart_multi_form_fields.
// Rendered on pub.dev's Example tab.

import 'package:flutter/material.dart';
import 'package:smart_multi_form_fields/smart_multi_form_fields.dart';
import 'screens/all_field_demo_screen.dart';

void main() {
  runApp(const SmartFormFieldExampleApp());
}

/// Root widget for the example application.
class SmartFormFieldExampleApp extends StatelessWidget {
  const SmartFormFieldExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Smart Form Field Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF02569B)),
        useMaterial3: true,
      ),
      home: const ExampleFormScreen(),
    );
  }
}

/// A complete, working form demonstrating SmartFormField usage.
class ExampleFormScreen extends StatefulWidget {
  const ExampleFormScreen({super.key});

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

class _ExampleFormScreenState extends State<ExampleFormScreen> {
  final _nameKey = GlobalKey<SmartBaseShellState>();
  final _emailKey = GlobalKey<SmartBaseShellState>();
  final _bioKey = GlobalKey<SmartBaseShellState>();

  String? _submittedData;

  void _submitForm() {
    final nameError = _nameKey.currentState?.validate();
    final emailError = _emailKey.currentState?.validate();
    final bioError = _bioKey.currentState?.validate();

    if (nameError == null && emailError == null && bioError == null) {
      setState(() {
        _submittedData =
            'Name: ${_nameKey.currentState?.value}\n'
            'Email: ${_emailKey.currentState?.value}\n'
            'Bio: ${_bioKey.currentState?.value}';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SmartFormField Demo'),
        actions: [
          IconButton(
            icon: const Icon(Icons.tune),
            tooltip: 'All Demos',
            onPressed: () => Navigator.push(
              context,
              MaterialPageRoute<void>(
                builder: (_) => const AllFieldsDemoScreen(),
              ),
            ),
          ),
        ],
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            SmartFormField(
              key: _nameKey,
              config: SmartTextConfig(
                label: 'Full Name',
                hint: 'John Doe',
                isRequired: true,
                autoCapitalizeWords: true,
                prefixIcon: const Icon(Icons.person),
              ),
            ),
            const SizedBox(height: 16),
            SmartFormField(
              key: _emailKey,
              config: SmartTextConfig(
                label: 'Email Address',
                hint: 'name@example.com',
                isRequired: true,
                validators: [SmartValidators.email],
                prefixIcon: const Icon(Icons.email),
              ),
            ),
            const SizedBox(height: 16),
            SmartFormField(
              key: _bioKey,
              config: SmartTextConfig(
                label: 'Bio',
                hint: 'Tell us about yourself...',
                maxLength: 150,
                maxLines: 3,
                minLines: 2,
                prefixIcon: const Icon(Icons.info),
              ),
            ),
            const SizedBox(height: 24),
            ElevatedButton(
              onPressed: _submitForm,
              child: const Text('Submit Form'),
            ),
            if (_submittedData != null) ...[
              const SizedBox(height: 24),
              Card(
                color: Theme.of(context).colorScheme.primaryContainer,
                child: Padding(
                  padding: const EdgeInsets.all(16),
                  child: Text(
                    'Submitted Values:\n\n$_submittedData',
                    style: TextStyle(
                      color: Theme.of(context).colorScheme.onPrimaryContainer,
                    ),
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
157
downloads
screenshot

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A single, production-grade Flutter form field widget rendering text, password, phone, OTP, date, dropdown, and file inputs via sealed configurations.

Repository (GitHub)

License

MIT (license)

Dependencies

cupertino_icons, file_picker, flutter, flutter_gap, flutter_intl_phone_field, image_picker, intl

More

Packages that depend on smart_multi_form_fields