Files
fcs/lib/pages/contact/contact_editor.dart

160 lines
5.1 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
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_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 {
2021-09-10 12:02:08 +06:30
final Contact? contact;
2020-09-07 16:05:28 +06:30
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;
2021-09-10 12:02:08 +06:30
bool isNew = false;
2020-09-07 16:05:28 +06:30
2021-09-10 12:02:08 +06:30
Contact? _contact;
2020-09-07 16:05:28 +06:30
@override
void initState() {
2021-09-10 12:02:08 +06:30
if (widget.contact != null) _contact = widget.contact!;
2020-09-07 16:05:28 +06:30
super.initState();
2021-09-10 12:02:08 +06:30
isNew = widget.contact == null;
}
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 ?? '';
2020-09-07 16:05:28 +06:30
}
@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(
icon: new Icon(CupertinoIcons.back, color: primaryColor),
onPressed: () {
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 {
2021-09-10 12:02:08 +06:30
_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!);
}
2020-09-07 16:05:28 +06:30
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}