-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate-team.dart
400 lines (304 loc) · 10.5 KB
/
create-team.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import 'dart:convert';
import 'package:brl_task4/create&join-Team/Domain-team.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:multi_select_flutter/multi_select_flutter.dart';
import '../screens/login.dart';
class Domain {
final int id;
final String name;
Domain({required this.id, required this.name});
}
class CreateTeamScreen extends StatefulWidget {
const CreateTeamScreen({super.key});
@override
_CreateTeamScreenState createState() => _CreateTeamScreenState();
}
class _CreateTeamScreenState extends State<CreateTeamScreen> {
TextEditingController teamNameController = TextEditingController();
List<Domain> domains = [
Domain(id: 1, name: 'Backend'),
Domain(id: 2, name: 'Frontend'),
Domain(id: 3, name: 'Machine Learning'),
Domain(id: 4, name: 'App Development'),
];
List<Domain> selectedDomains = [];
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment(0.98, -0.21),
end: Alignment(-0.98, 0.21),
colors: [Color(0xFF150218), Color(0xFF65386C)],
),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const SizedBox(
height: 20,
),
Row(
children: [
const SizedBox(
width: 10,
),
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(
Icons.arrow_back_outlined,
color: Colors.white,
),
),
const SizedBox(
width: 20,
),
const Text(
' Create Team',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 30,
color: Color(0xffffffff),
fontWeight: FontWeight.w700,
),
textAlign: TextAlign.left,
),
],
),
const SizedBox(
height: 20,
),
Container(
width: 303,
height: 395,
decoration: ShapeDecoration(
color: Colors.white.withOpacity(0.15000000596046448),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
),
child: Column(
children: [
const SizedBox(height: 20),
MyTextField(
hintText: 'Enter Team Name',
inputType: TextInputType.name,
labelText2: 'Team Name',
secure1: false,
capital: TextCapitalization.none,
nameController1: teamNameController
),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.all(12.0),
child: MultiSelectDialogField(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.transparent,
),
checkColor: Colors.white,
barrierColor: Colors.black,
selectedColor: Colors.black,
backgroundColor: const Color.fromARGB(255, 234, 167, 235),
items: domains
.map((domain) =>
MultiSelectItem<Domain>(domain, domain.name))
.toList(),
title: const Text('Select Domains',
style: TextStyle(color: Colors.black)),
buttonText: const Text('Select Domains',
style: TextStyle(color: Colors.white)),
onConfirm: (values) {
selectedDomains = values;
},
),
),
const SizedBox(height: 16),
Buttonki(
buttonName: 'Create Team',
onTap: () {
if (teamNameController.text.isEmpty) {
_showErrorSnackBar('Team name cannot be empty');
return;
}
createTeam();
},
bgColor: const Color.fromARGB(255, 225, 169, 229),
textColor: Colors.black,
)
],
),
),
],
),
),
),
);
}
Future<void> createTeam() async {
dynamic storedValue = await secureStorage.readSecureData(key);
var headers = <String, String>{
'Authorization' :storedValue,
'Content-Type': 'application/json'
};
print(storedValue);
var request = http.Request(
'POST',
Uri.parse(
'https://hive-backend-d0zr.onrender.com/team/createTeam'),
);
// List<Map<String, dynamic>> domainList = selectedDomains.map((domain) {
// return {
// "name": domain.name,
// "members": [],
// };
// }).toList();
List<Map<String, dynamic>> domainList = selectedDomains.map((domain){
return {
"name": domain.name,
"members": [],
};
}).toList();
request.body = json.encode({
"teamName": teamNameController.text,
"domains": domainList,
});
request.headers.addAll(headers);
try {
print ("hii");
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
final Map<String, dynamic> responseData =
jsonDecode(await response.stream.bytesToString());
final String teamId = responseData['team']['_id'];
print(teamId);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TeamDetailsScreen(teamNameController.text, selectedDomains, teamId), // passing team name, selected domains and team id to team details screen
),
);
_showErrorSnackBar('Team created successfully');
print(await response.stream.bytesToString());
} else {
_showErrorSnackBar(response.reasonPhrase!);
print(response.reasonPhrase);
}
} catch (error) {
_showErrorSnackBar('Error creating team: $error');
print('Error creating team: $error');
}
}
void _showErrorSnackBar(String errorMessage) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(errorMessage),
duration: const Duration(seconds: 3),
action: SnackBarAction(
label: 'Dismiss',
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
),
);
}
}
// pub.dev me mere khud ke package me se copy kiya hai ye code
class Buttonki extends StatelessWidget {
const Buttonki({
Key? key,
required this.buttonName,
required this.onTap,
required this.bgColor,
required this.textColor,
}) : super(key: key);
final String buttonName;
final VoidCallback onTap;
final Color bgColor;
final Color textColor;
@override
Widget build(BuildContext context) {
return Container(
height: 40,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: bgColor,
),
child: TextButton(
style: ButtonStyle(
elevation: MaterialStateProperty.all(12),
shadowColor:
MaterialStateProperty.all(const Color.fromARGB(255, 227, 152, 217)),
overlayColor: MaterialStateProperty.resolveWith(
(states) => Colors.transparent,
),
),
onPressed: onTap,
child: Text(
buttonName,
style: TextStyle(fontSize: 15, color: textColor),
),
),
);
}
}
// pub.dev me mere khud ke package me se copy kiya hai ye code
class MyTextField extends StatelessWidget {
const MyTextField({
super.key,
required this.hintText,
required this.inputType,
required this.labelText2,
required this.secure1,
required this.capital,
required this.nameController1,
});
final String hintText;
final TextInputType inputType;
final String labelText2;
final bool secure1;
final TextCapitalization capital;
final TextEditingController nameController1;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextFormField(
style: const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
controller: nameController1,
keyboardType: inputType,
obscureText: secure1,
textInputAction: TextInputAction.next,
textCapitalization: capital,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(20),
hintText: hintText,
hintStyle: const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
enabledBorder: const OutlineInputBorder(
borderSide:
BorderSide(color: Color.fromARGB(255, 234, 167, 235), width: 1),
borderRadius: BorderRadius.all(Radius.circular(16)),
),
focusedBorder: const OutlineInputBorder(
borderSide:
BorderSide(color: Color.fromARGB(255, 234, 167, 235), width: 1),
borderRadius: BorderRadius.all(Radius.circular(16)),
),
labelText: labelText2,
labelStyle:
const TextStyle(color: Color.fromARGB(255, 255, 255, 255)),
),
),
);
}
}