Skip to content

A customizable Flutter widget for selecting birth dates with auto-formatting and platform-specific UI.

License

Notifications You must be signed in to change notification settings

intelryzen/birth_picker

Repository files navigation

BirthPicker Flutter Package

pub package Score Platform GitHub stars GitHub forks GitHub issues GitHub pull requests

A customizable date picker widget for Flutter applications, designed specifically for selecting birth dates. It offers a seamless user experience by supporting platform-specific date pickers (Cupertino for iOS and Material for Android) and customizable UI components.

Simulator Screen Recording

Keyboard Input Example iOS Date Picker Example Android Date Picker Example
s1 s2 Screenshot3

Features

  • Supports both iOS-style (Cupertino) and Android-style (Material) date pickers.
  • Auto-formats date fields (year, month, day) and validates input.
  • Supports localization with customizable date field order.
  • Flexible input options:
    • Allows users to enter the date directly using the keyboard.
    • Provides an icon button to easily select the date using a platform-specific date picker.

Installation

  1. Add the following line to your pubspec.yaml under dependencies:

    birth_picker: ^1.1.1
  2. Run the following command to install the package:

    flutter pub get
  3. Import it:

    import 'package:birth_picker/birth_picker.dart';

Usage

Before using the BirthPicker widget, initialize date formatting by calling initializeDateFormatting() in your main function, as it depends on the intl package for handling localized date formats:

import 'package:birth_picker/birth_picker.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initializeDateFormatting(); // Important: Initialize date formatting
  runApp(const MyApp());
}

Props

Props Types Default Description
decoration BoxDecoration? Decoration for the widget container (e.g., border, background).
padding EdgeInsets? Padding for the entire widget.
focusColor Color? Color of the background when the field is focused.
focusPadding EdgeInsets? Padding when the field is focused
textStyle TextStyle? Text style for the input fields.
locale String? Locale for date formatting (e.g., "en_US").
autofocus bool false Whether the first field should get focus automatically on load.
icon Widget? User-customized icon to display next to the input fields.
iconColor Color? Color of the icon.
iconSize double 20 Size of the icon.
onChanged void Function(DateTime?)? null Callback function triggered when the date changes. Passes null if the dateTime is invalid.

Example

import 'package:birth_picker/birth_picker.dart';
...
BirthPicker(
  onChanged: (dateTime) {
    if (dateTime != null) {
      print('Selected Date: ${dateTime.toIso8601String()}');
    } else {
      print('Invalid Date');
    }
  },
)

Contributions

Contributions are welcome! Please open issues and pull requests to improve this package.


About

A customizable Flutter widget for selecting birth dates with auto-formatting and platform-specific UI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published