app_date_picker_bottom_sheet 0.1.1
app_date_picker_bottom_sheet: ^0.1.1 copied to clipboard
A customizable Flutter date picker bottom sheet with smooth animations, custom themes, and an easy-to-use API.
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:app_date_picker_bottom_sheet/app_date_picker_bottom_sheet.dart';
void main() {
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App Date Picker Bottom Sheet Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF6750A4),
brightness: Brightness.light,
),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFFD0BCFF),
brightness: Brightness.dark,
),
useMaterial3: true,
),
themeMode: ThemeMode.system,
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
DateTime? _selectedDate;
Future<void> _openDatePicker({
Color? primaryColor,
String? title,
}) async {
final pickedDate = await showAppDatePickerBottomSheet(
context: context,
initialDate: _selectedDate ?? DateTime.now(),
firstDate: DateTime(2020, 1, 1),
lastDate: DateTime(2030, 12, 31),
title: title ?? 'Choose Date',
confirmText: 'Confirm Date',
primaryColor: primaryColor,
);
if (pickedDate != null) {
setState(() {
_selectedDate = pickedDate;
});
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final formattedDate = _selectedDate != null
? DateFormat('EEEE, MMMM d, yyyy').format(_selectedDate!)
: 'No date selected';
return Scaffold(
appBar: AppBar(
title: const Text('Date Picker Bottom Sheet'),
centerTitle: true,
elevation: 2,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 20,
),
child: Column(
children: [
Text(
'Selected Date',
style: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.outline,
),
),
const SizedBox(height: 8),
Text(
formattedDate,
textAlign: TextAlign.center,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
],
),
),
),
const SizedBox(height: 32),
FilledButton.icon(
onPressed: () => _openDatePicker(),
icon: const Icon(Icons.calendar_month_rounded),
label: const Text('Default Date Picker Sheet'),
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 14,
),
),
),
const SizedBox(height: 16),
OutlinedButton.icon(
onPressed: () => _openDatePicker(
primaryColor: Colors.teal,
title: 'Select Event Date',
),
icon: const Icon(Icons.palette_outlined),
label: const Text('Custom Teal Theme'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 14,
),
),
),
],
),
),
),
);
}
}