-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_measure_page.dart
144 lines (131 loc) · 4.17 KB
/
audio_measure_page.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
132
133
134
135
136
137
138
139
140
141
142
143
144
part of pulmonary_monitor_app;
/// A UI widget that can handle a [AudioUserTask].
class AudioMeasurePage extends StatefulWidget {
static const String routeName = '/study/audio';
final AudioUserTask? audioUserTask;
const AudioMeasurePage({super.key, this.audioUserTask});
@override
AudioMeasurePageState createState() => AudioMeasurePageState(audioUserTask);
}
class AudioMeasurePageState extends State<AudioMeasurePage> {
AudioUserTask? audioUserTask;
AudioMeasurePageState(this.audioUserTask) : super();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Audio Measure'),
),
body: Center(
child: ListView(
children: [
image,
titleSection,
countDownSection,
bottomSection,
],
)));
}
Widget get image => Image.asset(
'assets/images/audio.png',
width: 600,
fit: BoxFit.cover,
);
Widget get titleSection {
return Container(
padding: const EdgeInsets.only(top: 30, left: 8, bottom: 8),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
audioUserTask!.title,
style: const TextStyle(
fontSize: 21,
fontWeight: FontWeight.bold,
),
),
Text(audioUserTask!.description),
Container(
padding: const EdgeInsets.all(10),
child: Text(
audioUserTask!.instructions,
softWrap: true,
style: const TextStyle(
fontStyle: FontStyle.italic,
),
),
),
]));
}
Widget get countDownSection {
return Container(
padding: const EdgeInsets.only(top: 80),
alignment: FractionalOffset.center,
child: StreamBuilder<int>(
stream: audioUserTask!.countDownEvents,
initialData: audioUserTask!.recordingDuration,
builder: (context, AsyncSnapshot<int> snapshot) =>
Text('00:${snapshot.data.toString().padLeft(2, '0')}',
style: const TextStyle(
fontSize: 45,
fontWeight: FontWeight.bold,
))));
}
Widget get bottomSection {
return Container(
alignment: FractionalOffset.center,
child: StreamBuilder<UserTaskState>(
stream: audioUserTask!.stateEvents,
builder: (context, AsyncSnapshot<UserTaskState> snapshot) {
switch (snapshot.data) {
case UserTaskState.enqueued:
case UserTaskState.started:
case UserTaskState.canceled:
return buttonSection;
case UserTaskState.done:
return finishedSection;
default:
return buttonSection;
}
}));
}
Widget get buttonSection {
return Container(
padding: const EdgeInsets.only(top: 80),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
(audioUserTask!.state == UserTaskState.started)
? const Text('RECORDING...')
: const Text('Press here to start recording...'),
IconButton(
iconSize: 80,
color: CACHET.RED,
icon: const Icon(Icons.radio_button_checked),
onPressed: () {
// callback to audio user task
audioUserTask!.onRecord();
},
),
],
));
}
Widget get finishedSection {
return Container(
padding: const EdgeInsets.only(top: 80),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('DONE!',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
)),
OutlinedButton(
child: const Text('PRESS HERE TO GO BACK'),
onPressed: () {
Navigator.pop(context);
},
),
],
));
}
}