You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/settings/profile_setting.dart

253 lines
9.6 KiB
Dart

4 years ago
import 'package:diplomaticquarterapp/config/config.dart';
4 years ago
import 'package:diplomaticquarterapp/core/viewModels/dashboard_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
4 years ago
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ProfileSettings extends StatefulWidget {
4 years ago
@override
_ProfileSettings createState() => _ProfileSettings();
}
class _ProfileSettings extends State<ProfileSettings>
with TickerProviderStateMixin {
4 years ago
bool smsAlert = true;
bool emailAlert = true;
int language = 1;
final authService = new AuthProvider();
TextEditingController emergencyContact = new TextEditingController();
TextEditingController emailController = new TextEditingController();
TextEditingController emergencyContactName = new TextEditingController();
@override
void initState() {
Future.delayed(new Duration(seconds: 0), () {
getSettings(context);
});
super.initState();
}
Widget build(BuildContext context) {
4 years ago
4 years ago
return BaseView<DashboardViewModel>(
4 years ago
onModelReady: (model) =>{},
4 years ago
builder: (_, model, wi) => Container(
child:
ListView(scrollDirection: Axis.vertical, children: <Widget>[
Container(
padding: EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(
TranslationBase.of(context).fileNo,
color: Colors.black,
),
AppText(
model.user.patientID.toString(),
color: Colors.black,
),
],
),
),
SizedBox(
height: 1,
width: MediaQuery.of(context).size.width,
child: Container(
color: Colors.grey[300],
4 years ago
),
4 years ago
),
Padding(
child: AppText(TranslationBase.of(context).languageSetting,
fontWeight: FontWeight.bold),
padding: EdgeInsets.all(10),
),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).english),
new Radio(
value: 2,
groupValue: language,
onChanged: (value) {
4 years ago
setState(() {
language = value;
});
4 years ago
},
)
],
)),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).arabic),
new Radio(
value: 1,
groupValue: language,
onChanged: (value) {
4 years ago
setState(() {
language = value;
});
4 years ago
},
)
],
)),
Padding(
child: AppText(TranslationBase.of(context).alert),
padding: EdgeInsets.all(10),
),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).emailAlert),
Switch(
4 years ago
value: emailAlert,
4 years ago
onChanged: (value) {
setState(() {
4 years ago
emailAlert = value;
4 years ago
});
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
)),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).smsAlert),
Switch(
4 years ago
value: smsAlert,
4 years ago
onChanged: (value) {
setState(() {
4 years ago
smsAlert = value;
4 years ago
});
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
)),
Padding(
child: AppText(TranslationBase.of(context).contactInfo),
padding: EdgeInsets.all(10),
),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(TranslationBase.of(context).email),
TextField(
4 years ago
controller: emailController,
4 years ago
decoration: InputDecoration(
suffixIcon: Icon(Icons.edit),
))
],
)),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(TranslationBase.of(context).emergencyName),
TextField(
4 years ago
controller: emergencyContactName,
4 years ago
decoration: InputDecoration(
suffixIcon: Icon(Icons.edit),
))
],
)),
Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 0, left: 10, right: 10, bottom: 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(TranslationBase.of(context).emergencyContact),
TextField(
4 years ago
controller: emergencyContact,
4 years ago
decoration: InputDecoration(
suffixIcon: Icon(Icons.edit),
),
)
],
)),
Container(
padding: EdgeInsets.all(10),
child: Row(
children: <Widget>[
Expanded(
child: DefaultButton(
TranslationBase.of(context).submit,
() {
4 years ago
saveSettings();
4 years ago
},
)),
],
))
])));
}
4 years ago
getSettings(context){
GifLoaderDialogUtils.showMyDialog(context);
authService.getSettings().then((result)=>{
GifLoaderDialogUtils.hideDialog(context),
setValue(result["PateintInfoForUpdateList"][0])
});
}
setValue(value){
setState(() {
this.language = int.parse(value["PreferredLanguage"]);
this.emailAlert = value["IsEmailAlertRequired"];
this.smsAlert = value["IsSMSAlertRequired"];
this.emailController.text = value["EmailAddress"];
this.emergencyContact.text = value["EmergencyContactNo"];
this.emergencyContactName.text = value["EmergencyContactName"];
});
}
saveSettings(){
GifLoaderDialogUtils.showMyDialog(context);
Map<String, dynamic> request = {};
request["EmailAddress"] =this.emailController.text;
request["EmergencyContactName"] = this.emergencyContactName.text;
request["EmergencyContactNo"] = this.emergencyContact.text;
request["IsEmailAlertRequired"] = this.emailAlert;
request["IsSMSAlertRequired"] = this.smsAlert;
request["PreferredLanguage"] = this.language.toString();
authService.saveSettings(request).then((result)=>{
print(result),
GifLoaderDialogUtils.hideDialog(context)
});
}
}