CircularProgressIndicator is not showing

376 views
Skip to first unread message

Kamran Ali

unread,
May 27, 2019, 11:31:35 AM5/27/19
to Flutter Dev
In RaisedButton onPressed method when i call setState for the first time it doesn't call the build method but the second 
setState method call build method successfully that's why it doesn't show me the circular progress indicator anyone can please 
tell where i go wrong?
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:flutter_multiselect/flutter_multiselect.dart';
import 'package:dio/dio.dart';
import 'package:iamflexi_app/account_components/AboutApps.dart';
import 'package:iamflexi_app/account_components/CallCenter.dart';
import 'package:iamflexi_app/account_components/Message.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';
import 'dart:io';

class EditProfilePage extends StatefulWidget {
@override
_EditProfilePageState createState() => _EditProfilePageState();
}

/// Custom Font
var _txt = TextStyle(
color: Colors.black,
fontFamily: "Sans",
);

/// Get _txt and custom value of Variable for Name User
var _txtName = _txt.copyWith(fontWeight: FontWeight.w700, fontSize: 17.0);

/// Get _txt and custom value of Variable for Edit text
var _txtEdit = _txt.copyWith(color: Colors.black26, fontSize: 15.0);

/// Get _txt and custom value of Variable for Category Text
var _txtCategory = _txt.copyWith(
fontSize: 14.5, color: Colors.black54, fontWeight: FontWeight.w500);

class _EditProfilePageState extends State<EditProfilePage> {
Map<String, Object> userData;
String authToken;
final userBio = TextEditingController();
final skills = TextEditingController();
final coverLetter1 = TextEditingController();
final coverLetter2 = TextEditingController();
final coverLetter3 = TextEditingController();
final cV = TextEditingController();
final daysAvailable = TextEditingController();
final socialMedia = TextEditingController();
final scaffoldKey = new GlobalKey<ScaffoldState>();
final formKey = new GlobalKey<FormState>();
String _fileName;
String _path;
String _extension;
FileType _pickingType = FileType.ANY;
String name = "Upload CV";
bool isLoading = false;

void _openFileExplorer() async {
try {
_path = await FilePicker.getFilePath(
type: _pickingType, fileExtension: _extension);
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
}
if (!mounted) return;
setState(() {
_fileName = _path != null ? _path.split('/').last : 'Upload CV';
name = _fileName;
});
}

void performLogin() {
final snackbar = new SnackBar(
content: new Text("Email : , password : "),
);
scaffoldKey.currentState.showSnackBar(snackbar);
}

void _submit() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
//print(firstName.text);
putData();
}
}

putData() async {
SharedPreferences tokenInstance = await SharedPreferences.getInstance();
authToken = "JWT " + tokenInstance.getString("authToken");
Response response;
Dio dio = new Dio();

dio.interceptors
.add(InterceptorsWrapper(onRequest: (Options options) async {
//...If no token, request token firstly.
//Response response = await dio.get("/token");
//Set the token to headers
options.headers["Authorization"] = authToken;
return options; //continue
}));

FormData formData = new FormData.from({
"user_bio": userBio.text,
"cV": UploadFileInfo(File(_path), _fileName),
"skills[]": skills.text,
"daysAvailable[]": "fri",
"cover_letter.coverletter1": coverLetter1.text,
"cover_letter.coverletter2": coverLetter2.text,
"cover_letter.coverletter3": coverLetter3.text
});
response = await dio.put("my url",
data: formData);
print("Response:: " + response.toString());
print("Response status code:: " + response.statusCode.toString());
print("Response status Message:: " + response.statusMessage);
}

@override
void initState() {
// TODO: implement initState
super.initState();
}

@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
/// Declare MediaQueryData
MediaQueryData mediaQueryData = MediaQuery.of(context);

return Scaffold(
key: scaffoldKey,
appBar: AppBar(),
body: SingleChildScrollView(
padding: const EdgeInsets.all(20.0),
child: Form(
key: formKey,
child: isLoading
? Center(
child: CircularProgressIndicator(),
)
: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: "User Biography",
hintText: "Tell us a bit about yourself."),
onSaved: (val) => print(val),
keyboardType: TextInputType.multiline,
maxLines: null,
controller: userBio,
),
TextFormField(
decoration: InputDecoration(
labelText: "skills", hintText: "Enter your skills"),
onSaved: (val) => print(val),
keyboardType: TextInputType.text,
controller: skills,
),
SizedBox(
height: 30,
),
MultiSelect(
autovalidate: false,
titleText: "Days available to work",
// validator: (value) {
// if (value == null) {
// return 'Please select one or more option(s)2';
// }
// },
// errorText: 'Please select one or more option(s)1',
dataSource: [
{"display": "Monday", "value": "mon"},
{"display": "Tuesday", "value": "tue"},
{"display": "Wednesday", "value": "wed"},
{"display": "Thursday", "value": "thu"},
{"display": "Friday", "value": "fri"},
{"display": "Saturday", "value": "sat"},
{"display": "Sunday", "value": "sun"},
],
textField: 'display',
valueField: 'value',
filterable: false,
required: false,
onSaved: (value) {
print('The value is $value');
},
),
TextFormField(
decoration: InputDecoration(
labelText: "Cover letter 1",
hintText:
"Save a cover letter template for a faster application process."),
onSaved: (val) => print(val),
keyboardType: TextInputType.multiline,
maxLines: null,
controller: coverLetter1,
),
TextFormField(
decoration: InputDecoration(
labelText: "Cover letter 2",
hintText:
"Save a cover letter template for a faster application process."),
onSaved: (val) => print(val),
keyboardType: TextInputType.multiline,
maxLines: null,
controller: coverLetter2,
),
TextFormField(
decoration: InputDecoration(
labelText: "Cover letter 3",
hintText:
"Save a cover letter template for a faster application process."),
onSaved: (val) => print(val),
keyboardType: TextInputType.multiline,
maxLines: null,
controller: coverLetter3,
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(name),
IconButton(
color: Colors.blue,
icon: Icon(Icons.file_upload),
onPressed: () {
_openFileExplorer();
//name = 'File : ' + _fileName;
}),
],
),
new RaisedButton(
child: new Text(
"Update",
style: new TextStyle(color: Colors.white),
),
color: Colors.blue,
onPressed:() {
setState(() {
isLoading = true;
});
_submit();
setState(() {
isLoading = false;
});
}
)
],
),
),
),
);
}
}

Kamran Ali

unread,
May 27, 2019, 11:43:23 AM5/27/19
to Flutter Dev
issue is solved by putting 2nd setState method in putData method

FormData formData = new FormData.from({
"user_bio": userBio.text,
"cV": UploadFileInfo(File(_path), _fileName),
"skills[]": skills.text,
"daysAvailable[]": "fri",
"cover_letter.coverletter1": coverLetter1.text,
"cover_letter.coverletter2": coverLetter2.text,
"cover_letter.coverletter3": coverLetter3.text
});
response = await dio.put("my url",
data: formData);
setState(() {
isLoading = false;
});
print("Response:: " + response.toString());
print("Response status code:: " + response.statusCode.toString());
print("Response status Message:: " + response.statusMessage);
Reply all
Reply to author
Forward
0 new messages