155 lines
4.8 KiB
Dart
155 lines
4.8 KiB
Dart
import 'package:fcs/domain/vo/contact.dart';
|
|
import 'package:fcs/helpers/theme.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_app_bar.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
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;
|
|
bool isNew = false;
|
|
|
|
Contact? _contact;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if (widget.contact != null) {
|
|
isNew = false;
|
|
_contact = widget.contact;
|
|
initContact();
|
|
} else {
|
|
isNew = true;
|
|
}
|
|
}
|
|
|
|
initContact() {
|
|
_usaPhone.text = _contact?.usaContactNumber ?? '';
|
|
_mmPhone.text = _contact?.mmContactNumber ?? '';
|
|
_usaAddress.text = _contact?.usaAddress ?? '';
|
|
_mmAddress.text = _contact?.mmAddress ?? '';
|
|
_email.text = _contact?.emailAddress ?? '';
|
|
_facebook.text = _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,
|
|
maxLines: 3,
|
|
controller: _usaAddress);
|
|
final mmAddressBox = InputText(
|
|
labelTextKey: 'contact.mm.address',
|
|
iconData: CupertinoIcons.location,
|
|
maxLines: 3,
|
|
controller: _mmAddress);
|
|
final emailBox = InputText(
|
|
labelTextKey: 'contact.email',
|
|
iconData: CupertinoIcons.mail,
|
|
controller: _email);
|
|
final faceBookBox = InputText(
|
|
labelTextKey: 'contact.facebook',
|
|
iconData: FontAwesomeIcons.facebook,
|
|
controller: _facebook);
|
|
|
|
final saveBox = fcsButton(context, getLocalString(context, "btn.save"),
|
|
callack: _submit);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: LocalAppBar(
|
|
labelKey: 'contact.edit.title',
|
|
backgroundColor: Colors.white,
|
|
labelColor: primaryColor,
|
|
arrowColor: primaryColor),
|
|
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,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
));
|
|
}
|
|
|
|
_submit() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
});
|
|
try {
|
|
_contact?.usaContactNumber = _usaPhone.text;
|
|
_contact?.mmContactNumber = _mmPhone.text;
|
|
_contact?.usaAddress = _usaAddress.text;
|
|
_contact?.mmAddress = _mmAddress.text;
|
|
_contact?.emailAddress = _email.text;
|
|
_contact?.facebookLink = _facebook.text;
|
|
if (this._contact != null) {
|
|
var contactModel = Provider.of<ContactModel>(context, listen: false);
|
|
await contactModel.saveContact(_contact!);
|
|
}
|
|
|
|
Navigator.pop(context);
|
|
} catch (e) {
|
|
showMsgDialog(context, "Error", e.toString());
|
|
} finally {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|