/
main.dart
109 lines (101 loc) · 3.07 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import 'package:interval_time_picker/interval_time_picker.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Interval Time Picker Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(colorScheme: const ColorScheme.light()),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TimeOfDay _time = const TimeOfDay(hour: 7, minute: 15);
int _interval = 5;
VisibleStep _visibleStep = VisibleStep.fifths;
void _selectTime() async {
final TimeOfDay? newTime = await showIntervalTimePicker(
context: context,
initialTime: _time,
interval: _interval,
visibleStep: _visibleStep,
);
if (newTime != null) {
setState(() {
_time = newTime;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _selectTime,
child: const Text('SELECT TIME'),
),
const SizedBox(height: 8),
Text(
'Selected time: ${_time.format(context)}',
),
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Slider(
value: _interval.toDouble(),
min: 1,
max: 60,
divisions: 60,
label: _interval.toString(),
onChanged: (double value) {
setState(() {
_interval = value.toInt();
});
},
),
DropdownButton<VisibleStep>(
value: _visibleStep,
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (VisibleStep? newValue) {
if (newValue != null) {
setState(() {
_visibleStep = newValue;
});
}
},
items: VisibleStep.values.map((VisibleStep visibleStep) {
return DropdownMenuItem<VisibleStep>(
value: visibleStep,
child: Text(visibleStep.toString()));
}).toList(),
),
],
),
],
),
),
);
}
}