-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathwheel.dart
61 lines (57 loc) · 1.86 KB
/
wheel.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
import 'package:flutter/material.dart';
import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:fortune_wheel_demo/common/common.dart';
class FortuneWheelPage extends HookWidget {
@override
Widget build(BuildContext context) {
final alignment = useState(Alignment.topCenter);
final selected = useStreamController<int>();
final selectedIndex = useStream(selected.stream, initialData: 0).data ?? 0;
final isAnimating = useState(false);
final alignmentSelector = AlignmentSelector(
selected: alignment.value,
onChanged: (v) => alignment.value = v!,
);
void handleRoll() {
selected.add(
roll(Constants.fortuneValues.length),
);
}
return AppLayout(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
alignmentSelector,
SizedBox(height: 8),
RollButtonWithPreview(
selected: selectedIndex,
items: Constants.fortuneValues,
onPressed: isAnimating.value ? null : handleRoll,
),
SizedBox(height: 8),
Expanded(
child: FortuneWheel(
selected: selected.stream,
onAnimationStart: () => isAnimating.value = true,
onAnimationEnd: () => isAnimating.value = false,
onFling: handleRoll,
indicators: [
FortuneIndicator(
alignment: alignment.value,
child: TriangleIndicator(),
),
],
items: [
for (var it in Constants.fortuneValues)
FortuneItem(child: Text(it))
],
),
),
],
),
),
);
}
}