1
1
import 'dart:io' ;
2
2
3
+ import 'package:blogapp/NetworkHandler.dart' ;
3
4
import 'package:flutter/material.dart' ;
4
5
import 'package:image_picker/image_picker.dart' ;
5
6
@@ -11,14 +12,23 @@ class CreatProfile extends StatefulWidget {
11
12
}
12
13
13
14
class _CreatProfileState extends State <CreatProfile > {
15
+ final networkHandler = NetworkHandler ();
16
+
14
17
PickedFile _imageFile;
18
+ final _globalkey = GlobalKey <FormState >();
19
+ TextEditingController _name = TextEditingController ();
20
+ TextEditingController _profession = TextEditingController ();
21
+ TextEditingController _dob = TextEditingController ();
22
+ TextEditingController _title = TextEditingController ();
23
+ TextEditingController _about = TextEditingController ();
15
24
final ImagePicker _picker = ImagePicker ();
16
25
@override
17
26
Widget build (BuildContext context) {
18
27
return Scaffold (
19
- body: Padding (
20
- padding : const EdgeInsets . symmetric (horizontal : 20 , vertical : 20 ) ,
28
+ body: Form (
29
+ key : _globalkey ,
21
30
child: ListView (
31
+ padding: const EdgeInsets .symmetric (horizontal: 20 , vertical: 30 ),
22
32
children: < Widget > [
23
33
imageProfile (),
24
34
SizedBox (
@@ -44,6 +54,42 @@ class _CreatProfileState extends State<CreatProfile> {
44
54
SizedBox (
45
55
height: 20 ,
46
56
),
57
+ InkWell (
58
+ onTap: () async {
59
+ if (_globalkey.currentState.validate ()) {
60
+ Map <String , String > data = {
61
+ "name" : _name.text,
62
+ "profession" : _profession.text,
63
+ "dob" : _dob.text,
64
+ "title" : _title.text,
65
+ "about" : _about.text,
66
+ };
67
+ var response =
68
+ await networkHandler.post ("/profile/add" , data);
69
+ print (response.statusCode);
70
+ }
71
+ },
72
+ child: Center (
73
+ child: Container (
74
+ width: 200 ,
75
+ height: 50 ,
76
+ decoration: BoxDecoration (
77
+ color: Colors .teal,
78
+ borderRadius: BorderRadius .circular (10 ),
79
+ ),
80
+ child: Center (
81
+ child: Text (
82
+ "Submit" ,
83
+ style: TextStyle (
84
+ color: Colors .white,
85
+ fontSize: 18 ,
86
+ fontWeight: FontWeight .bold,
87
+ ),
88
+ ),
89
+ ),
90
+ ),
91
+ ),
92
+ ),
47
93
],
48
94
),
49
95
),
@@ -131,6 +177,12 @@ class _CreatProfileState extends State<CreatProfile> {
131
177
132
178
Widget nameTextField () {
133
179
return TextFormField (
180
+ controller: _name,
181
+ validator: (value) {
182
+ if (value.isEmpty) return "Name can't be empty" ;
183
+
184
+ return null ;
185
+ },
134
186
decoration: InputDecoration (
135
187
border: OutlineInputBorder (
136
188
borderSide: BorderSide (
@@ -154,6 +206,12 @@ class _CreatProfileState extends State<CreatProfile> {
154
206
155
207
Widget professionTextField () {
156
208
return TextFormField (
209
+ controller: _profession,
210
+ validator: (value) {
211
+ if (value.isEmpty) return "Profession can't be empty" ;
212
+
213
+ return null ;
214
+ },
157
215
decoration: InputDecoration (
158
216
border: OutlineInputBorder (
159
217
borderSide: BorderSide (
@@ -177,6 +235,12 @@ class _CreatProfileState extends State<CreatProfile> {
177
235
178
236
Widget dobField () {
179
237
return TextFormField (
238
+ controller: _dob,
239
+ validator: (value) {
240
+ if (value.isEmpty) return "DOB can't be empty" ;
241
+
242
+ return null ;
243
+ },
180
244
decoration: InputDecoration (
181
245
border: OutlineInputBorder (
182
246
borderSide: BorderSide (
@@ -200,6 +264,12 @@ class _CreatProfileState extends State<CreatProfile> {
200
264
201
265
Widget titleTextField () {
202
266
return TextFormField (
267
+ controller: _title,
268
+ validator: (value) {
269
+ if (value.isEmpty) return "Title can't be empty" ;
270
+
271
+ return null ;
272
+ },
203
273
decoration: InputDecoration (
204
274
border: OutlineInputBorder (
205
275
borderSide: BorderSide (
@@ -223,6 +293,12 @@ class _CreatProfileState extends State<CreatProfile> {
223
293
224
294
Widget aboutTextField () {
225
295
return TextFormField (
296
+ controller: _about,
297
+ validator: (value) {
298
+ if (value.isEmpty) return "About can't be empty" ;
299
+
300
+ return null ;
301
+ },
226
302
maxLines: 4 ,
227
303
decoration: InputDecoration (
228
304
border: OutlineInputBorder (
0 commit comments