2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/vo/contact.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/pages/contact/model/contact_model.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-09-07 16:05:28 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'widgets.dart';
|
|
|
|
|
|
|
|
|
|
class ContactEditor extends StatefulWidget {
|
|
|
|
|
final Contact contact;
|
|
|
|
|
const ContactEditor({this.contact});
|
|
|
|
|
@override
|
|
|
|
|
_ContactEditorState createState() => _ContactEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ContactEditorState extends State<ContactEditor> {
|
|
|
|
|
TextEditingController _usaPhone = new TextEditingController();
|
|
|
|
|
TextEditingController _mmPhone = new TextEditingController();
|
|
|
|
|
TextEditingController _usaAddress = new TextEditingController();
|
|
|
|
|
TextEditingController _mmAddress = new TextEditingController();
|
|
|
|
|
TextEditingController _email = new TextEditingController();
|
|
|
|
|
TextEditingController _facebook = new TextEditingController();
|
|
|
|
|
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if (widget.contact != null) {
|
|
|
|
|
_usaPhone.text = widget.contact.usaContactNumber;
|
|
|
|
|
_mmPhone.text = widget.contact.mmContactNumber;
|
|
|
|
|
_usaAddress.text = widget.contact.usaAddress;
|
|
|
|
|
_mmAddress.text = widget.contact.mmAddress;
|
|
|
|
|
_email.text = widget.contact.emailAddress;
|
|
|
|
|
_facebook.text = widget.contact.facebookLink;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final usaPhoneBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.usa.phone',
|
|
|
|
|
iconData: CupertinoIcons.phone,
|
|
|
|
|
controller: _usaPhone);
|
|
|
|
|
final mmPhoneBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.mm.phone',
|
|
|
|
|
iconData: CupertinoIcons.phone,
|
|
|
|
|
controller: _mmPhone);
|
|
|
|
|
final usaAddreesBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.usa.address',
|
|
|
|
|
iconData: CupertinoIcons.location,
|
2020-09-20 05:34:49 +06:30
|
|
|
maxLines: 3,
|
2020-09-07 16:05:28 +06:30
|
|
|
controller: _usaAddress);
|
|
|
|
|
final mmAddressBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.mm.address',
|
|
|
|
|
iconData: CupertinoIcons.location,
|
2020-09-20 05:34:49 +06:30
|
|
|
maxLines: 3,
|
2020-09-07 16:05:28 +06:30
|
|
|
controller: _mmAddress);
|
|
|
|
|
final emailBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.email',
|
|
|
|
|
iconData: CupertinoIcons.mail,
|
|
|
|
|
controller: _email);
|
|
|
|
|
final faceBookBox = InputText(
|
|
|
|
|
labelTextKey: 'contact.facebook',
|
|
|
|
|
iconData: FontAwesomeIcons.facebook,
|
|
|
|
|
controller: _facebook);
|
|
|
|
|
|
2020-09-15 07:13:41 +06:30
|
|
|
final saveBox = fcsButton(context, getLocalString(context, "btn.save"),
|
|
|
|
|
callack: _submit);
|
|
|
|
|
|
2020-09-07 16:05:28 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
2020-09-11 16:14:36 +06:30
|
|
|
child: Scaffold(
|
2020-09-18 04:04:21 +06:30
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
2020-12-04 17:28:21 +06:30
|
|
|
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showConfirmDialog(context, "back.button_confirm", () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
});
|
|
|
|
|
}),
|
2020-09-18 04:04:21 +06:30
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'contact.edit.title',
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
)),
|
|
|
|
|
body: ListView(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 18.0, right: 18),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
itemTitle(context, "contact.callus"),
|
|
|
|
|
usaPhoneBox,
|
|
|
|
|
mmPhoneBox,
|
|
|
|
|
Divider(),
|
|
|
|
|
itemTitle(context, "contact.findus"),
|
|
|
|
|
usaAddreesBox,
|
|
|
|
|
mmAddressBox,
|
|
|
|
|
Divider(),
|
|
|
|
|
itemTitle(context, "contact.emailus"),
|
|
|
|
|
emailBox,
|
|
|
|
|
Divider(),
|
|
|
|
|
itemTitle(context, "contact.visitus"),
|
|
|
|
|
faceBookBox,
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
|
|
|
|
),
|
|
|
|
|
saveBox,
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
)
|
|
|
|
|
],
|
2020-09-11 16:14:36 +06:30
|
|
|
),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2020-09-11 16:14:36 +06:30
|
|
|
));
|
2020-09-07 16:05:28 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_submit() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
widget.contact.usaContactNumber = _usaPhone.text;
|
|
|
|
|
widget.contact.mmContactNumber = _mmPhone.text;
|
|
|
|
|
widget.contact.usaAddress = _usaAddress.text;
|
|
|
|
|
widget.contact.mmAddress = _mmAddress.text;
|
|
|
|
|
widget.contact.emailAddress = _email.text;
|
|
|
|
|
widget.contact.facebookLink = _facebook.text;
|
|
|
|
|
var contactModel = Provider.of<ContactModel>(context, listen: false);
|
|
|
|
|
await contactModel.saveContact(widget.contact);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|