time_picker_sheet 0.0.2+1 time_picker_sheet: ^0.0.2+1 copied to clipboard
Time picker sheet library, allows you to have beauty time picker sheet with customable design to align with your requirements.
import 'package:flutter/material.dart';
import 'package:time_picker_sheet/widget/sheet.dart';
import 'package:time_picker_sheet/widget/time_picker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DateTime dateTimeSelected = DateTime.now();
void _openTimePickerSheet(BuildContext context) async {
final result = await TimePicker.show<DateTime?>(
context: context,
sheet: TimePickerSheet(
sheetTitle: 'Select meeting schedule',
minuteTitle: 'Minute',
hourTitle: 'Hour',
saveButtonText: 'Save',
),
);
if (result != null) {
setState(() {
dateTimeSelected = result;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => _openTimePickerSheet(context),
child: Text('show time picker sheet'),
),
Text('Time ${dateTimeSelected.hour}:${dateTimeSelected.minute}'),
],
),
),
);
}
}