apptomate_custom_date_picker 0.0.1
apptomate_custom_date_picker: ^0.0.1 copied to clipboard
CustomDatePicker is an enhanced date selection widget that provides more flexibility and customization options than Flutter's built-in date picker.
example/lib/main.dart
import 'package:apptomate_custom_date_picker/apptomate_custom_date_picker.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const CustomDatePickerWidget(),
);
}
}
class CustomDatePickerWidget extends StatefulWidget {
const CustomDatePickerWidget({super.key});
@override
State<CustomDatePickerWidget> createState() => _CustomDatePickerExampleState();
}
class _CustomDatePickerExampleState extends State<CustomDatePickerWidget> {
DateTime? _selectedDate;
void _handleDateSelected(DateTime? pickedDate) {
setState(() {
_selectedDate = pickedDate;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Custom atePicker')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
if (_selectedDate != null)
Text(
"Selected: ${DateFormat('MMMM dd, yyyy').format(_selectedDate!)}",
style: const TextStyle(fontSize: 18),
),
const SizedBox(height: 20),
// Example 1: Default TextField style
CustomDatePicker(
initialDate: _selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
dateFormat: 'MM/dd/yyyy',
onDateSelected: _handleDateSelected,
formattedDate: (date) => print("Formatted: $date"),
showClearButton: true,
hintText: 'Select a date',
margin: const EdgeInsets.only(bottom: 16),
),
// Example 2: With label
CustomDatePicker(
initialDate: _selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
dateFormat: 'yyyy-MM-dd',
onDateSelected: _handleDateSelected,
showLabel: true,
labelText: 'Birth Date',
margin: const EdgeInsets.only(bottom: 16),
),
// Example 3: Custom button style
CustomDatePicker(
dateWidget: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.calendar_month, color: Colors.white),
SizedBox(width: 8),
Text('Pick Date', style: TextStyle(color: Colors.white)),
],
),
),
initialDate: _selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
onDateSelected: _handleDateSelected,
),
],
),
),
);
}
}