birth_date_input 1.0.1 copy "birth_date_input: ^1.0.1" to clipboard
birth_date_input: ^1.0.1 copied to clipboard

Three-field (day / month / year) date input widget for Flutter forms — a lightweight alternative to date pickers for birth date / date of birth entry. Built-in validation, auto-advance, paste support, [...]

example/lib/main.dart

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

void main() => runApp(const ExampleApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'birth_date_input demo',
      theme: ThemeData(useMaterial3: true),
      darkTheme: ThemeData(useMaterial3: true, brightness: Brightness.dark),
      home: const DemoPage(),
    );
  }
}

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

  @override
  State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  final _formKey = GlobalKey<FormState>();
  DateTime? _selectedDate;

  static const _locales = <String, BirthDateLocalizations>{
    'EN': BirthDateLocalizations.en(),
    'CS': BirthDateLocalizations.cs(),
    'RU': BirthDateLocalizations.ru(),
    'PL': BirthDateLocalizations.pl(),
    'LT': BirthDateLocalizations.lt(),
  };

  static const _orders = <String, BirthDateFieldOrder>{
    'DMY': BirthDateFieldOrder.dmy,
    'MDY': BirthDateFieldOrder.mdy,
    'YMD': BirthDateFieldOrder.ymd,
  };

  String _currentLocale = 'EN';
  String _currentOrder = 'DMY';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('birth_date_input demo')),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // -- Locale switcher --
              Wrap(
                spacing: 8,
                children: _locales.keys.map((code) {
                  return ChoiceChip(
                    label: Text(code),
                    selected: _currentLocale == code,
                    onSelected: (_) => setState(() => _currentLocale = code),
                  );
                }).toList(),
              ),
              const SizedBox(height: 16),

              // -- Field order switcher --
              Wrap(
                spacing: 8,
                children: _orders.keys.map((label) {
                  return ChoiceChip(
                    label: Text(label),
                    selected: _currentOrder == label,
                    onSelected: (_) => setState(() => _currentOrder = label),
                  );
                }).toList(),
              ),
              const SizedBox(height: 24),

              // -- Birth date field --
              BirthDateFormField(
                key: ValueKey('$_currentLocale-$_currentOrder'),
                localizations: _locales[_currentLocale]!,
                fieldOrder: _orders[_currentOrder]!,
                labelText: _locales[_currentLocale]!.defaultLabel,
                labelPadding: const EdgeInsets.only(bottom: 12),
                minAgeYears: 18,
                onChanged: (date) => setState(() => _selectedDate = date),
              ),
              const SizedBox(height: 24),

              // -- Submit --
              ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    _formKey.currentState!.save();
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('Valid: $_selectedDate')),
                    );
                  }
                },
                child: const Text('Submit'),
              ),

              if (_selectedDate != null) ...[
                const SizedBox(height: 16),
                Text('Selected: ${_selectedDate!.toIso8601String().split('T').first}'),
              ],
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
145
points
134
downloads

Publisher

unverified uploader

Weekly Downloads

Three-field (day / month / year) date input widget for Flutter forms — a lightweight alternative to date pickers for birth date / date of birth entry. Built-in validation, auto-advance, paste support, and multi-language localization.

Repository (GitHub)
View/report issues

Topics

#date-input #birthday #form #widget #date

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on birth_date_input