You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
330 lines
14 KiB
330 lines
14 KiB
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:healthcare_pharmacy/dashboard.dart';
|
|
import 'package:healthcare_pharmacy/settings.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'dart:io';
|
|
|
|
|
|
class UpdateProfile extends StatefulWidget {
|
|
const UpdateProfile({Key? key}) : super(key: key);
|
|
@override
|
|
State<UpdateProfile> createState() => _UpdateprofileState();
|
|
}
|
|
|
|
class _UpdateprofileState extends State<UpdateProfile> {
|
|
|
|
bool isPwdObscureText=true;
|
|
bool isConfirmPwdObscureText=true;
|
|
TextEditingController nameController = TextEditingController();
|
|
TextEditingController emailController = TextEditingController();
|
|
TextEditingController mobileNumberController = TextEditingController();
|
|
TextEditingController descriptionController = TextEditingController();
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
isPwdObscureText=true;
|
|
isConfirmPwdObscureText=true;
|
|
nameController.text=AppSettings.pharmacyName;
|
|
mobileNumberController.text=AppSettings.phoneNumber;
|
|
emailController.text=AppSettings.email;
|
|
descriptionController.text=AppSettings.pharmacyDescription;
|
|
|
|
super.initState();
|
|
}
|
|
final ImagePicker _picker = ImagePicker();
|
|
Future pickImageFromGallery() async {
|
|
try {
|
|
final image = await _picker.pickImage(source: ImageSource.gallery);
|
|
if (image == null) return;
|
|
final imageTemp = File(image.path);
|
|
setState(() {
|
|
AppSettings.updatedImage = imageTemp;
|
|
});
|
|
//uploadProfileApi(AppSettings.updatedImage);
|
|
AppSettings.saveProfile(image.path);
|
|
|
|
|
|
} on PlatformException catch (e) {
|
|
print('Failed to pick image: $e');
|
|
}
|
|
}
|
|
|
|
Future takeImageFromCamera() async {
|
|
try {
|
|
final image = await _picker.pickImage(source: ImageSource.camera);
|
|
if (image == null) return;
|
|
final imageTemp = File(image.path);
|
|
setState(() {
|
|
AppSettings.updatedImage = imageTemp;
|
|
});
|
|
|
|
// uploadProfileApi(AppSettings.updatedImage);
|
|
AppSettings.saveProfile(image.path);
|
|
|
|
} on PlatformException catch (e) {
|
|
print('Failed to pick image: $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
appBar:AppSettings.appBar('Edit Profile'),
|
|
body: Stack(children: <Widget>[
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
/* image: DecorationImage(
|
|
image: AssetImage("images/backgroundimage.png"),
|
|
fit: BoxFit.cover,
|
|
),*/
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
FocusScope.of(context).requestFocus(new FocusNode());
|
|
},
|
|
child: SafeArea(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 40,
|
|
),
|
|
/*Container(
|
|
child: Image(
|
|
image: AssetImage('images/logo.png'),
|
|
height: MediaQuery.of(context).size.height * .10,
|
|
)),*/
|
|
Container(child: GestureDetector(
|
|
child: Container(
|
|
width: MediaQuery.of(context).size.width * .60,
|
|
height:
|
|
MediaQuery.of(context).size.height * .15,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.rectangle,
|
|
border: Border.all(width: 5, color: Colors.blueGrey),
|
|
image: DecorationImage(
|
|
image: (AppSettings.updatedImage !=
|
|
null)
|
|
? FileImage(
|
|
AppSettings.updatedImage!)
|
|
as ImageProvider
|
|
: AssetImage(
|
|
"images/mobilebg.png"), // picked file
|
|
fit: BoxFit.cover)),
|
|
),
|
|
onTap: () {
|
|
showModalBottomSheet<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return SizedBox(
|
|
height: 200,
|
|
child: Center(
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
GestureDetector(
|
|
child: Icon(
|
|
Icons.camera_alt_outlined,
|
|
size: 100,
|
|
color: greyColor,
|
|
),
|
|
onTap: () async {
|
|
await takeImageFromCamera();
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
SizedBox(
|
|
width: MediaQuery.of(context)
|
|
.size
|
|
.width *
|
|
.20,
|
|
),
|
|
GestureDetector(
|
|
child: Icon(
|
|
Icons.photo,
|
|
size: 100,
|
|
color: greyColor,
|
|
),
|
|
onTap: () async {
|
|
await pickImageFromGallery();
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
});
|
|
},
|
|
),),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
child: TextFormField(
|
|
cursorColor: greyColor,
|
|
controller: nameController,
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(
|
|
Icons.person,
|
|
color: greyColor,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
labelText: 'Username',
|
|
labelStyle: TextStyle(
|
|
color: greyColor, //<-- SEE HERE
|
|
),
|
|
),
|
|
),
|
|
),//name
|
|
const SizedBox(
|
|
height: 15,
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
child: TextFormField(
|
|
cursorColor: greyColor,
|
|
controller: emailController,
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(
|
|
Icons.email,
|
|
color: greyColor,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
labelText: 'Enter email ID',
|
|
labelStyle: TextStyle(
|
|
color: greyColor, //<-- SEE HERE
|
|
),
|
|
),
|
|
),
|
|
), //email
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
child: TextFormField(
|
|
cursorColor: greyColor,
|
|
readOnly: true,
|
|
controller: mobileNumberController,
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(
|
|
Icons.phone_android,
|
|
color: greyColor,
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
labelText: 'Enter Mobile Number',
|
|
labelStyle: TextStyle(
|
|
color: greyColor, //<-- SEE HERE
|
|
),
|
|
),
|
|
),
|
|
), //mobile
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
child: TextFormField(
|
|
cursorColor: greyColor,
|
|
controller: descriptionController,
|
|
keyboardType: TextInputType.multiline,
|
|
maxLines: null,
|
|
decoration: const InputDecoration(
|
|
prefixIcon: Icon(
|
|
Icons.description,
|
|
color:greyColor,
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 60.0, horizontal: 30.0),
|
|
border: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: greyColor),
|
|
),
|
|
labelText: 'Enter Description',
|
|
labelStyle: TextStyle(
|
|
color: greyColor, //<-- SEE HERE
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
|
|
Container(
|
|
width: 400,
|
|
height: 55,
|
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
primary: buttonColor,// background
|
|
onPrimary: Colors.white,// foreground
|
|
),
|
|
onPressed: () async{
|
|
var payload = new Map<String, dynamic>();
|
|
payload["pharmacyname"] = nameController.text.toString();
|
|
payload["phone"] = mobileNumberController.text.toString();
|
|
payload["emails"] = [{"email":emailController.text.toString()}];
|
|
payload["description"] = descriptionController.text.toString();
|
|
bool signUpStatus = await AppSettings.updatePharmaData(payload);
|
|
try{
|
|
if (signUpStatus) {
|
|
Navigator.pop(context);
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => Dashboard()),
|
|
);
|
|
AppSettings.longSuccessToast("Pharmacy Profile Updated !!");
|
|
} else {
|
|
AppSettings.longFailedToast("Pharmacy Profile Not Updated !!");
|
|
}
|
|
}
|
|
catch(exception){
|
|
print(exception);
|
|
AppSettings.longFailedToast("Please enter valid details");
|
|
}
|
|
},
|
|
child: Text('Update'),
|
|
)
|
|
),
|
|
],
|
|
),
|
|
)),
|
|
),
|
|
]));
|
|
}
|
|
}
|