smart_form_guard 2.2.2 copy "smart_form_guard: ^2.2.2" to clipboard
smart_form_guard: ^2.2.2 copied to clipboard

A smart Flutter form wrapper that validates fields, auto-focuses & scrolls to the first invalid field, and provides pleasant visual feedback.

smart_form_guard #

Pub Version Flutter Platform License

πŸ›‘οΈ Forms that guide users instead of punishing them.

A smart Flutter form wrapper that validates fields, auto-focuses & scrolls to the first invalid field, and provides pleasant visual feedback with shake animations, soft glow effects, and real-time validation states.


🎬 Demo #

Smart Form Guard Demo


✨ Why smart_form_guard? #

❌ Traditional Forms βœ… Smart Form Guard
Shows all errors at once Progressive validation (one at a time)
User hunts for invalid fields Auto-focuses & scrolls to errors
Static error messages Shake animation + glow effects
No positive feedback βœ… Green checkmarks when valid
Manual state management Zero configuration needed

πŸš€ Features #

Feature Description
🎯 Auto-focus Instantly focuses the first invalid field
πŸ“œ Auto-scroll Smoothly scrolls to off-screen errors
🌊 Shake Animation Eye-catching shake on validation failure
✨ Glow Effects Red glow for errors, green glow for valid
βœ… Valid State Green borders & checkmarks when correct
πŸ“³ Haptic Feedback Subtle vibration on errors
πŸ”„ Real-time Validation Optional autovalidate mode
πŸ—‚οΈ Rich Field Types Text, Email, Password, Phone, Dropdown, Checkbox, DatePicker
πŸ“¦ Zero Config Works out of the box

πŸ“¦ Installation #

dependencies:
  smart_form_guard: ^2.2.2
flutter pub get

🎯 Quick Start #

import 'package:smart_form_guard/smart_form_guard.dart';

SmartForm(
  onValid: () => print("Form is valid πŸŽ‰"),
  child: Column(
    children: [
      SmartField.email(
        controller: emailController,
        label: "Email",
      ),
      SmartField.password(
        controller: passwordController,
        label: "Password",
      ),
      SmartSubmitButton(
        text: "Create Account",
        icon: Icons.arrow_forward,
      ),
    ],
  ),
);

That's it! No boilerplate. No manual focus management. No manual scroll logic.


πŸ“– Available Widgets #

SmartField Constructors #

Widget Description
SmartField.email() Email with validation
SmartField.password() Password with toggle & strength rules
SmartField.required() Required text field
SmartField.phone() Phone number validation

Additional Smart Widgets #

Widget Description
SmartDropdown<T>() Dropdown with validation & icons
SmartCheckbox() Checkbox for terms/agreements
SmartDatePicker() Date selection with validation
SmartRadioGroup<T>() Animated radio group with validation
SmartSubmitButton() Submit with loading state

🎨 Customization Examples #

Custom Validators #

SmartField(
  controller: usernameController,
  label: 'Username',
  validator: SmartValidators.compose([
    SmartValidators.required('Username is required'),
    SmartValidators.minLength(3, 'At least 3 characters'),
    SmartValidators.pattern(
      RegExp(r'^[a-zA-Z0-9_]+$'),
      'Only letters, numbers, and underscores',
    ),
  ]),
  prefixIcon: Icons.person_outline,
)

Password with Custom Rules #

SmartField.password(
  controller: passwordController,
  label: 'Password',
  minLength: 10,
  requireUppercase: true,
  requireLowercase: true,
  requireDigit: true,
  requireSpecialChar: true,
  autovalidateMode: AutovalidateMode.onUserInteraction,
)

Styled Dropdown #

SmartDropdown<String>(
  label: 'Country',
  hint: 'Select your country',
  prefixIcon: Icons.public,
  value: selectedCountry,
  items: countries.map((c) => DropdownMenuItem(
    value: c.code,
    child: Row(children: [
      Text(c.flag),
      SizedBox(width: 8),
      Text(c.name),
    ]),
  )).toList(),
  validator: (v) => v == null ? 'Required' : null,
  onChanged: (v) => setState(() => selectedCountry = v),
)

Async Validation #

SmartField(
  label: 'Username',
  validator: (v) => v!.isEmpty ? 'Required' : null,
  asyncValidator: (v) async {
    await Future.delayed(Duration(seconds: 1)); // Simulate API
    if (v == 'admin') return 'Username taken';
    return null;
  },
)

Smart Radio Group #

SmartRadioGroup<String>(
  label: 'Role',
  options: [
    SmartRadioOption(value: 'dev', label: 'Developer', icon: Icons.code),
    SmartRadioOption(value: 'des', label: 'Designer', icon: Icons.brush),
  ],
  onChanged: (val) => print(val),
  validator: (v) => v == null ? 'Select a role' : null,
)

βš™οΈ SmartForm Options #

Property Type Description
child Widget Form content (required)
onValid VoidCallback? Called when form passes validation
onInvalid VoidCallback? Called when validation fails
controller SmartFormController? External controller for advanced use
enableHapticFeedback bool Enable/disable haptics (default: true)

πŸ”§ SmartValidators #

Pre-built validators with customizable messages:

SmartValidators.required([message])
SmartValidators.email([message])
SmartValidators.phone([message])
SmartValidators.minLength(length, [message])
SmartValidators.maxLength(length, [message])
SmartValidators.pattern(regex, [message])
SmartValidators.password(
  minLength: 8,
  requireUppercase: true,
  requireLowercase: true,
  requireDigit: true,
  requireSpecialChar: false,
)

// Combine multiple:
SmartValidators.compose([...validators])

πŸ§ͺ Testing #

flutter test

All core functionality is covered with unit tests.


πŸ“‹ Version 2.2.2 & 2.2.0 Highlights #

  • βœ… Static Analysis Fixes: Resolved deprecated API usage for better stability (v2.2.1).
  • βœ… Granular Email Validation: Real-time feedback for specific errors (e.g. missing '@', invalid domain).
  • βœ… Persistent Valid State: Green glow now appears whenever a field is valid, ensuring clear positive feedback.
  • βœ… Real-time Validation: SmartField.email() now defaults to AutovalidateMode.onUserInteraction for immediate feedback.
  • βœ… UI Fixes: Enhanced SmartRadioGroup error states with red outlines and labels.

πŸ“‹ Version 2.1.0 Highlights #

  • βœ… Async Validation: Validate fields asynchronously with built-in loading spinners.
  • βœ… New Widget: SmartRadioGroup - A premium, animated radio group.
  • βœ… New Field: SmartField.confirmPassword() - Built-in password confirmation logic.
  • βœ… Enhanced Widgets: Loading indicators added to all fields.

πŸ“‹ Version 2.0.0 Highlights #

  • βœ… New Widgets: SmartDropdown, SmartCheckbox, SmartDatePicker
  • βœ… Valid State UI: Green borders, glows, and checkmarks
  • βœ… Haptic Feedback: Subtle vibrations on validation errors
  • βœ… Autovalidate Mode: Real-time validation support
  • βœ… Generic Validators: Type-safe validation for any field type
  • βœ… Premium Dropdown: Icons, elevation, and smooth animations

πŸ“„ License #

MIT License - see LICENSE for details.


Made with ❀️ for the Flutter community

⭐ Star on GitHub β€’ πŸ› Report Bug β€’ πŸ“¦ View on pub.flutter-io.cn

7
likes
150
points
659
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A smart Flutter form wrapper that validates fields, auto-focuses & scrolls to the first invalid field, and provides pleasant visual feedback.

Repository (GitHub)
View/report issues

Topics

#form #validation #form-validation #ux #flutter-package

License

MIT (license)

Dependencies

flutter, intl

More

Packages that depend on smart_form_guard