-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.dart
131 lines (118 loc) · 3.33 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'package:flutter/material.dart';
import 'package:wheel_picker/wheel_picker.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData.dark(useMaterial3: true),
home: const Scaffold(
body: Center(
child: WheelPickerExample(),
),
),
);
}
}
class WheelPickerExample extends StatefulWidget {
const WheelPickerExample({super.key});
@override
State<WheelPickerExample> createState() => _WheelPickerExampleState();
}
class _WheelPickerExampleState extends State<WheelPickerExample> {
final now = TimeOfDay.now();
late final _hoursWheel = WheelPickerController(
itemCount: 12,
initialIndex: now.hour % 12,
);
late final _minutesWheel = WheelPickerController(
itemCount: 60,
initialIndex: now.minute,
mounts: [_hoursWheel],
);
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 26.0, height: 1.5);
final wheelStyle = WheelPickerStyle(
itemExtent: textStyle.fontSize! * textStyle.height!, // Text height
squeeze: 1.25,
diameterRatio: .8,
surroundingOpacity: .25,
magnification: 1.2,
);
Widget itemBuilder(BuildContext context, int index) {
return Text("$index".padLeft(2, '0'), style: textStyle);
}
final timeWheels = <Widget>[
for (final wheelController in [_hoursWheel, _minutesWheel])
Expanded(
child: WheelPicker(
builder: itemBuilder,
controller: wheelController,
looping: wheelController == _minutesWheel,
style: wheelStyle,
selectedIndexColor: Colors.redAccent,
),
),
];
timeWheels.insert(1, const Text(":", style: textStyle));
final amPmWheel = Expanded(
child: WheelPicker(
itemCount: 2,
builder: (context, index) {
return Text(["AM", "PM"][index], style: textStyle);
},
initialIndex: (now.period == DayPeriod.am) ? 0 : 1,
looping: false,
style: wheelStyle.copyWith(
shiftAnimationStyle: const WheelShiftAnimationStyle(
duration: Duration(seconds: 1),
curve: Curves.bounceOut,
),
),
),
);
return Center(
child: SizedBox(
width: 200.0,
height: 200.0,
child: Stack(
fit: StackFit.expand,
children: [
_centerBar(context),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
children: [
...timeWheels,
const SizedBox(width: 6.0),
amPmWheel,
],
),
),
],
),
),
);
}
@override
void dispose() {
// Don't forget to dispose the controllers at the end.
_hoursWheel.dispose();
_minutesWheel.dispose();
super.dispose();
}
Widget _centerBar(BuildContext context) {
return Center(
child: Container(
height: 38.0,
decoration: BoxDecoration(
color: const Color(0xFFC3C9FA).withAlpha(26),
borderRadius: BorderRadius.circular(8.0),
),
),
);
}
}