11import 'dart:io' ;
22
3+ import 'package:blogapp/NetworkHandler.dart' ;
34import 'package:flutter/material.dart' ;
45import 'package:image_picker/image_picker.dart' ;
56
@@ -11,14 +12,23 @@ class CreatProfile extends StatefulWidget {
1112}
1213
1314class _CreatProfileState extends State <CreatProfile > {
15+ final networkHandler = NetworkHandler ();
16+
1417 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 ();
1524 final ImagePicker _picker = ImagePicker ();
1625 @override
1726 Widget build (BuildContext context) {
1827 return Scaffold (
19- body: Padding (
20- padding : const EdgeInsets . symmetric (horizontal : 20 , vertical : 20 ) ,
28+ body: Form (
29+ key : _globalkey ,
2130 child: ListView (
31+ padding: const EdgeInsets .symmetric (horizontal: 20 , vertical: 30 ),
2232 children: < Widget > [
2333 imageProfile (),
2434 SizedBox (
@@ -44,6 +54,42 @@ class _CreatProfileState extends State<CreatProfile> {
4454 SizedBox (
4555 height: 20 ,
4656 ),
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+ ),
4793 ],
4894 ),
4995 ),
@@ -131,6 +177,12 @@ class _CreatProfileState extends State<CreatProfile> {
131177
132178 Widget nameTextField () {
133179 return TextFormField (
180+ controller: _name,
181+ validator: (value) {
182+ if (value.isEmpty) return "Name can't be empty" ;
183+
184+ return null ;
185+ },
134186 decoration: InputDecoration (
135187 border: OutlineInputBorder (
136188 borderSide: BorderSide (
@@ -154,6 +206,12 @@ class _CreatProfileState extends State<CreatProfile> {
154206
155207 Widget professionTextField () {
156208 return TextFormField (
209+ controller: _profession,
210+ validator: (value) {
211+ if (value.isEmpty) return "Profession can't be empty" ;
212+
213+ return null ;
214+ },
157215 decoration: InputDecoration (
158216 border: OutlineInputBorder (
159217 borderSide: BorderSide (
@@ -177,6 +235,12 @@ class _CreatProfileState extends State<CreatProfile> {
177235
178236 Widget dobField () {
179237 return TextFormField (
238+ controller: _dob,
239+ validator: (value) {
240+ if (value.isEmpty) return "DOB can't be empty" ;
241+
242+ return null ;
243+ },
180244 decoration: InputDecoration (
181245 border: OutlineInputBorder (
182246 borderSide: BorderSide (
@@ -200,6 +264,12 @@ class _CreatProfileState extends State<CreatProfile> {
200264
201265 Widget titleTextField () {
202266 return TextFormField (
267+ controller: _title,
268+ validator: (value) {
269+ if (value.isEmpty) return "Title can't be empty" ;
270+
271+ return null ;
272+ },
203273 decoration: InputDecoration (
204274 border: OutlineInputBorder (
205275 borderSide: BorderSide (
@@ -223,6 +293,12 @@ class _CreatProfileState extends State<CreatProfile> {
223293
224294 Widget aboutTextField () {
225295 return TextFormField (
296+ controller: _about,
297+ validator: (value) {
298+ if (value.isEmpty) return "About can't be empty" ;
299+
300+ return null ;
301+ },
226302 maxLines: 4 ,
227303 decoration: InputDecoration (
228304 border: OutlineInputBorder (
0 commit comments