1
1
import 'dart:io' ;
2
2
3
3
import 'package:blogapp/NetworkHandler.dart' ;
4
+ import 'package:blogapp/Pages/HomePage.dart' ;
5
+ import 'package:blogapp/Screen/HomeScreen.dart' ;
4
6
import 'package:flutter/material.dart' ;
5
7
import 'package:image_picker/image_picker.dart' ;
6
8
@@ -13,7 +15,7 @@ class CreatProfile extends StatefulWidget {
13
15
14
16
class _CreatProfileState extends State <CreatProfile > {
15
17
final networkHandler = NetworkHandler ();
16
-
18
+ bool circular = false ;
17
19
PickedFile _imageFile;
18
20
final _globalkey = GlobalKey <FormState >();
19
21
TextEditingController _name = TextEditingController ();
@@ -56,6 +58,9 @@ class _CreatProfileState extends State<CreatProfile> {
56
58
),
57
59
InkWell (
58
60
onTap: () async {
61
+ setState (() {
62
+ circular = true ;
63
+ });
59
64
if (_globalkey.currentState.validate ()) {
60
65
Map <String , String > data = {
61
66
"name" : _name.text,
@@ -66,7 +71,28 @@ class _CreatProfileState extends State<CreatProfile> {
66
71
};
67
72
var response =
68
73
await networkHandler.post ("/profile/add" , data);
69
- print (response.statusCode);
74
+ if (response.statusCode == 200 ||
75
+ response.statusCode == 201 ) {
76
+ if (_imageFile.path != null ) {
77
+ var imageResponse = await networkHandler.patchImage (
78
+ "/profile/add/image" , _imageFile.path);
79
+ if (imageResponse.statusCode == 200 ) {
80
+ setState (() {
81
+ circular = false ;
82
+ });
83
+ Navigator .of (context).pushAndRemoveUntil (
84
+ MaterialPageRoute (builder: (context) => HomePage ()),
85
+ (route) => false );
86
+ }
87
+ } else {
88
+ setState (() {
89
+ circular = false ;
90
+ });
91
+ Navigator .of (context).pushAndRemoveUntil (
92
+ MaterialPageRoute (builder: (context) => HomePage ()),
93
+ (route) => false );
94
+ }
95
+ }
70
96
}
71
97
},
72
98
child: Center (
@@ -78,14 +104,16 @@ class _CreatProfileState extends State<CreatProfile> {
78
104
borderRadius: BorderRadius .circular (10 ),
79
105
),
80
106
child: Center (
81
- child: Text (
82
- "Submit" ,
83
- style: TextStyle (
84
- color: Colors .white,
85
- fontSize: 18 ,
86
- fontWeight: FontWeight .bold,
87
- ),
88
- ),
107
+ child: circular
108
+ ? CircularProgressIndicator ()
109
+ : Text (
110
+ "Submit" ,
111
+ style: TextStyle (
112
+ color: Colors .white,
113
+ fontSize: 18 ,
114
+ fontWeight: FontWeight .bold,
115
+ ),
116
+ ),
89
117
),
90
118
),
91
119
),
0 commit comments