-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinishedquestion3.dart
173 lines (169 loc) · 8.6 KB
/
finishedquestion3.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import 'package:flutter/material.dart';
import 'package:rewardprocessing/questionnaire/finishpage.dart';
import 'package:percent_indicator/percent_indicator.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class FinishedQuestion3 extends StatefulWidget {
final String id;
final String day;
const FinishedQuestion3({super.key, required this.id, required this.day});
@override
State<FinishedQuestion3> createState() => _FinishedQuestion3State();
}
class _FinishedQuestion3State extends State<FinishedQuestion3> {
bool activeButton = false;
bool isOverLimit = false;
final TextEditingController _textEditingController = TextEditingController();
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return false; // disable back page
},
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Center(
child: SingleChildScrollView(
keyboardDismissBehavior:
ScrollViewKeyboardDismissBehavior.onDrag,
physics: const AlwaysScrollableScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
child: Container(
margin: const EdgeInsets.only(bottom: 40, left: 30, right: 30),
width: 380,
height: 110,
decoration: const BoxDecoration(
color: Color(0xFFFFD9A0),
borderRadius:
BorderRadius.all(Radius.circular(30)
)
),
alignment: Alignment.center,
child: Container(
margin: const EdgeInsets.only(
left: 10, right: 10),
child: const Text(
'Please provide any feedback on this study that you think may be useful to our research:',
overflow: TextOverflow.visible,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
height: 1.45
)
)
)
)
),
Container(
padding: const EdgeInsets.only(left: 25, right: 25),
child: TextFormField(
controller: _textEditingController,
maxLines: 7,
validator: (val) {
if (RegExp('[A-Z a-z 0-9 ]').hasMatch(val!)) {
return null;
} else {
return 'Request body length over limit';
}
},
cursorColor: const Color(0xFF00A8AF),
decoration: const InputDecoration(
hintText: 'Type your answer here',
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20)
),
borderSide: BorderSide(
width: 2,
color: Colors.grey,
style: BorderStyle.solid
)
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20)
),
borderSide: BorderSide(
width: 2,
color: Color(0xFF00A8AF),
style: BorderStyle.solid
)
)
),
onChanged: (value) {
setState(() {
isOverLimit = value.trim().split(' ').length >500;
activeButton = value.trim().split(' ').length <= 500 && value.isNotEmpty;
});
})
),
Container(
margin: const EdgeInsets.only(left: 30, right: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text
('${_textEditingController.text.trim().isEmpty ? 0 : _textEditingController.text.trim().split(' ').where((element) => element.isNotEmpty).length}/500')
],
)
),
Container(
margin: const EdgeInsets.only(top: 40),
child: ElevatedButton(
onPressed: activeButton ? () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => FinishPage(id: widget.id, day: widget.day)
)
);
await FirebaseFirestore.instance
.collection('participants')
.doc(widget.id)
.collection(widget.day)
.doc('feedback')
.set({'02. Feedback': _textEditingController.text},
SetOptions(merge: true)
);
} : null,
style: ElevatedButton.styleFrom(
fixedSize: const Size(160, 60),
backgroundColor: const Color(0xFF00A8AF),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(100)
),
elevation: 2.0
),
child: const Text('Continue',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w300)
)
)
)
]
)
)
),
bottomSheet:
Padding(
padding: const EdgeInsets.only(left: 25, right: 25, bottom: 80),
child: LinearPercentIndicator(
animateFromLastPercent: true,
lineHeight: 20,
animationDuration: 1000,
percent: 1,
center: const Text('2/2'),
barRadius: const Radius.circular(30),
backgroundColor: const Color(0xFFDCDCDC),
progressColor: const Color(0xFF32BEC4)
)
)
)
);
}
}