apptomate_custom_time_picker 0.0.1
apptomate_custom_time_picker: ^0.0.1 copied to clipboard
CustomTimePicker is an enhanced time selection widget that extends Flutter's built-in time picker with additional customization options and features.
example/lib/main.dart
import 'package:apptomate_custom_time_picker/apptomate_custom_time_picker.dart';
import 'package:flutter/material.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 TimePickerExample(),
);
}
}
// Example Usage
class TimePickerExample extends StatefulWidget {
const TimePickerExample({super.key});
@override
State<TimePickerExample> createState() => _TimePickerExampleState();
}
class _TimePickerExampleState extends State<TimePickerExample> {
TimeOfDay? _selectedTime;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Time Picker Examples')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (_selectedTime != null)
Text(
'Selected Time: ${_selectedTime!.format(context)}',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 30),
// Example 1: Icon Button
CustomTimePicker(
initialTime: _selectedTime,
onTimeSelected: (time) => setState(() => _selectedTime = time),
child: const Icon(Icons.access_time, size: 50),
),
const SizedBox(height: 20),
// Example 2: Text Button
CustomTimePicker(
initialTime: _selectedTime,
onTimeSelected: (time) => setState(() => _selectedTime = time),
child: const Text(
'Pick a Time',
style: TextStyle(fontSize: 18, decoration: TextDecoration.underline),
),
),
const SizedBox(height: 20),
// Example 3: Custom Styled Button
CustomTimePicker(
initialTime: _selectedTime,
primaryColor: Colors.purple,
backgroundColor: Colors.grey[100],
onTimeSelected: (time) => setState(() => _selectedTime = time),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: Colors.purple,
borderRadius: BorderRadius.circular(8),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.schedule, color: Colors.white),
SizedBox(width: 8),
Text('Select Time', style: TextStyle(color: Colors.white)),
],
),
),
),
const SizedBox(height: 20),
// Example 4: 24-hour format
CustomTimePicker(
initialTime: _selectedTime,
use24HourFormat: true,
onTimeSelected: (time) => setState(() => _selectedTime = time),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'24-hour Time',
style: TextStyle(color: Colors.white),
),
),
),
],
),
),
);
}
}