update edit profile and getpro file(not finish yet waiting for api fix about user profile photo).

parent f29f2aad
......@@ -22,6 +22,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
......
......@@ -19,7 +19,7 @@ class Api<T> {
final _headerApi = {
"Authorization":
"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYmFja2VuZC11YXQuZmVlbHZlci5jb21cL2FwaVwvbG9naW4iLCJpYXQiOjE1OTQ5NzIzMjYsImV4cCI6MTYwMjE3MjMyNiwibmJmIjoxNTk0OTcyMzI2LCJqdGkiOiJsM1BldUJVcTdDNldSbzVGIiwic3ViIjo1LCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.fwFqcbzG2T_ZHtIcGF13Ek7nIxxwbnaE9ZXGomo-nzY",
"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYmFja2VuZC11YXQuZmVlbHZlci5jb21cL2FwaVwvbG9naW4iLCJpYXQiOjE1OTYxMDAzNTgsImV4cCI6MTYwMzMwMDM1OCwibmJmIjoxNTk2MTAwMzU4LCJqdGkiOiJ2YjA2S0FHR1JtZDFseEw1Iiwic3ViIjozNzMsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.UkY70AshvW5O4M63XY_Iv2IPBohSUUwnRF1oi46p2zs",
};
Future<Response<T>> getprofile(Object body) async {
......@@ -41,6 +41,26 @@ class Api<T> {
});
return result;
}
Future<Response<T>> editProfile(Object body) async {
var _model;
var _fail;
var result;
print("This is body "+body.toString());
await _httpConnection(
"${this._baseApi}/customer/edit", this._headerApi, body)
.then((response) {
print("ผลลัพ เท่ากับบบบ " + "${response.body}");
if (response.statusCode == 200) {
_model = FogetPasswordModel.fromJson(json.decode(response.body));
} else {
_fail = FailModel.fromJson(json.decode(response.body));
}
result = new Response<T>(_model, _fail);
});
return result;
}
Future<Response<T>> forgetPassword(Object body) async {
var _model;
var _fail;
......
......@@ -28,6 +28,7 @@ class _EditProfileState extends State<EditProfile> {
ImagePickerUtil(context, (img) {
setState(() {
image = img;
presenter.imageFile=img;
});
});
}
......@@ -75,7 +76,7 @@ class _EditProfileState extends State<EditProfile> {
height: SizeConfig.getWidth(100),
),
)
: Stack(
:presenter.getmodel.result[0].image==null? Stack(
children: <Widget>[
Container(
height: SizeConfig.getWidth(80),
......@@ -108,7 +109,19 @@ class _EditProfileState extends State<EditProfile> {
),
)
],
):
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(SizeConfig.getWidth(56))),
child: Image.network(
presenter.getmodel.result[0].image,
fit: BoxFit.contain,
width: SizeConfig.getWidth(100),
height: SizeConfig.getWidth(100),
),
),
),
Container(
alignment: Alignment.topLeft,
......@@ -317,6 +330,8 @@ class _EditProfileState extends State<EditProfile> {
padding: EdgeInsets.all(0.0),
splashColor: Colors.blueAccent,
onPressed: () {
presenter.letCheckData();
print('name= ${presenter.nameCtrl.text}');
print('lastname= ${presenter.lnameCtrl.text}');
print('email= ${presenter.emailCtrl.text}');
......
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:feelverapp/model/Login/login_model.dart';
import 'package:feelverapp/model/editprofile/getprofilemodel.dart';
import 'package:feelverapp/model/forgetpassword/forgetpassModel.dart';
import 'package:feelverapp/service/Loading.dart';
import 'package:feelverapp/service/api.dart';
......@@ -20,135 +21,178 @@ import 'package:rflutter_alert/rflutter_alert.dart';
import 'edit_profile.dart';
class EditprofilePresenter extends BasePresenter<EditProfile> {
Api _api;
File imageFile;
String uid = "16";
final formKey = GlobalKey<FormState>();
String age,lastname,firstname,sex,address,email,phone;
GetprofileModel getmodel;
TextEditingController addresCtrl =TextEditingController() ;
TextEditingController ageCtrl =TextEditingController() ;
TextEditingController selectedSex =TextEditingController() ;
TextEditingController nameCtrl = TextEditingController();
String age, lastname, firstname, sex, address, email, phone;
GetprofileModel getmodel;
TextEditingController addresCtrl = TextEditingController();
TextEditingController ageCtrl = TextEditingController();
TextEditingController selectedSex = TextEditingController();
TextEditingController nameCtrl = TextEditingController();
TextEditingController phoneCtrl = TextEditingController();
TextEditingController emailCtrl = TextEditingController();
TextEditingController lnameCtrl = TextEditingController();
EditprofilePresenter(State<EditProfile> state) : super(state);
letCheckData() async {
try {
Pattern pattern =
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+";
RegExp regex = new RegExp(pattern);
if (!regex.hasMatch(emailCtrl.text)) throw ('รูปแบบอีเมล์\nไม่ถูกต้อง');
Pattern pattern2 = r'(^(?:[+0]9)?[0-9]{10,12}$)';
RegExp regex2 = new RegExp(pattern2);
if (!regex2.hasMatch(phoneCtrl.text))
throw ('รูปแบบเบอร์โทรศัพท์\nไม่ถูกต้อง');
if (selectedSex.text != "ชาย") {
if (selectedSex.text != "หญิง") throw ('กรุณาระบุเพศ\nชาย/หญิง');
else {
await letedit();
print("completeee");
}
} else {
await letedit();
print("completeee");
}
} catch (e) {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: '$e',
content: Icon(
Icons.warning,
color: Colors.orange,
size: 80,
),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ตกลง",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
}
letedit() async {
_api = Api<FogetPasswordModel>();
LoadingView(state.context).show();
var res = await _api.editProfile({
'id': getmodel.result[0].id.toString(),
'name': nameCtrl.text,
'lastname': lnameCtrl.text,
'phone': phoneCtrl.text,
'email': emailCtrl.text,
'sex': selectedSex.text == "ชาย" ? 'm' : 'w',
'image': imageFile != null ? _getImageBase64() : " ",
});
LoadingView(state.context).hide();
if (res.fail == null) {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: "สำเร็จ",
content: Icon(
Icons.check_circle,
color: Color.fromRGBO(106, 179, 170, 1),
size: 80,
),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ยืนยัน",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
} else {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: "ไม่สำเร็จ",
content: Icon(
Icons.warning,
color: Colors.orange,
size: 80,
),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ลองอีกครั้ง",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
}
letCheckData() async {
try {
if (emailCtrl.text.isEmpty ) throw ('กรุณากรอก\nอีเมล์');
Pattern pattern =
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+";
RegExp regex = new RegExp(pattern);
if (!regex.hasMatch(emailCtrl.text))
throw ('รูปแบบอีเมล์\nไม่ถูกต้อง');
else {
await getprofile();
}
} catch (e) {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: '$e',
content: Icon(Icons.warning,color: Colors.orange,size: 80,),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ตกลง",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
}
_getImageBase64() {
return base64.encode(imageFile.readAsBytesSync());
}
getprofile() async {
_api = Api<GetprofileModel>();
var res = await _api.getprofile({
"id":"16"
});
var res = await _api.getprofile({"id": "16"});
if (res.fail == null) {
setState((){
getmodel = res.success;
ageCtrl.text=getmodel.result[0].age.toString();
nameCtrl.text=getmodel.result[0].name;
lnameCtrl.text=getmodel.result[0].lastname;
selectedSex.text= getmodel.result[0].sex=='m'?"ชาย":"หญิง";
addresCtrl.text=getmodel.result[0].address.toString();
emailCtrl.text=getmodel.result[0].email;
phoneCtrl.text=getmodel.result[0].phone.toString();
});
} else {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: "ไม่สามารถติดต่อ\nเซิร์ฟเวอร์ได้",
content: Icon(Icons.warning,color: Colors.orange,size: 80,),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ลองอีกครั้ง",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
setState(() {
getmodel = res.success;
ageCtrl.text = getmodel.result[0].age.toString();
nameCtrl.text = getmodel.result[0].name;
lnameCtrl.text = getmodel.result[0].lastname;
selectedSex.text = getmodel.result[0].sex == 'm' ? "ชาย" : "หญิง";
addresCtrl.text = getmodel.result[0].address.toString();
emailCtrl.text = getmodel.result[0].email;
phoneCtrl.text = getmodel.result[0].phone.toString();
});
} else {
Alert(
style: AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
),
context: state.context,
title: "ไม่สามารถติดต่อ\nเซิร์ฟเวอร์ได้",
content: Icon(
Icons.warning,
color: Colors.orange,
size: 80,
),
buttons: [
DialogButton(
color: Color.fromRGBO(106, 179, 170, 1),
onPressed: () => Navigator.pop(state.context),
child: Text(
"ลองอีกครั้ง",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment