clean up
This commit is contained in:
151
lib/pages/contact/contact_editor.dart
Normal file
151
lib/pages/contact/contact_editor.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
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';
|
||||
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,
|
||||
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: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
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,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
127
lib/pages/contact/contact_page.dart
Normal file
127
lib/pages/contact/contact_page.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'package:fcs/domain/entities/setting.dart';
|
||||
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/contact_editor.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'widgets.dart';
|
||||
|
||||
class ContactPage extends StatefulWidget {
|
||||
@override
|
||||
_ContactPageState createState() => _ContactPageState();
|
||||
}
|
||||
|
||||
class _ContactPageState extends State<ContactPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Setting setting = Provider.of<MainModel>(context).setting;
|
||||
bool isEditable = context.select((MainModel m) => m.contactEditable());
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(
|
||||
Icons.close,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
'contact.title',
|
||||
color: primaryColor,
|
||||
fontSize: 20,
|
||||
),
|
||||
actions: isEditable
|
||||
? [
|
||||
IconButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) => ContactEditor(
|
||||
contact: Contact.fromSetting(setting)),
|
||||
)),
|
||||
icon: Icon(
|
||||
CupertinoIcons.pen,
|
||||
color: primaryColor,
|
||||
))
|
||||
]
|
||||
: [],
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
itemTitle(context, "contact.callus"),
|
||||
contactItem(context, setting.usaContactNumber, CupertinoIcons.phone,
|
||||
onTap: () => _call(setting.usaContactNumber),
|
||||
labelKey: "contact.usa.phone"),
|
||||
contactItem(
|
||||
context,
|
||||
setting.mmContactNumber,
|
||||
CupertinoIcons.phone,
|
||||
onTap: () => _call(
|
||||
setting.mmContactNumber,
|
||||
),
|
||||
labelKey: "contact.mm.phone",
|
||||
),
|
||||
itemTitle(context, "contact.findus"),
|
||||
contactItem(
|
||||
context,
|
||||
setting.usaAddress,
|
||||
CupertinoIcons.location,
|
||||
labelKey: "contact.usa.address",
|
||||
),
|
||||
contactItem(
|
||||
context,
|
||||
setting.mmAddress,
|
||||
CupertinoIcons.location,
|
||||
labelKey: "contact.mm.address",
|
||||
),
|
||||
itemTitle(context, "contact.emailus"),
|
||||
contactItem(
|
||||
context,
|
||||
setting.emailAddress,
|
||||
CupertinoIcons.mail,
|
||||
onTap: () => _email(setting.emailAddress),
|
||||
labelKey: "contact.fcs.email",
|
||||
),
|
||||
itemTitle(context, "contact.visitus"),
|
||||
contactItem(
|
||||
context,
|
||||
setting.facebookLink,
|
||||
FontAwesomeIcons.facebook,
|
||||
onTap: () => _opencontactItem(setting.facebookLink),
|
||||
labelKey: "contact.facebook",
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> getVersionNumber() async {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
String version = packageInfo.version + "+" + packageInfo.buildNumber;
|
||||
return version;
|
||||
}
|
||||
|
||||
_call(String phone) {
|
||||
launch("tel:$phone");
|
||||
}
|
||||
|
||||
_email(String email) {
|
||||
launch("mailto:$email");
|
||||
}
|
||||
|
||||
_opencontactItem(String contactItem) {
|
||||
launch("$contactItem");
|
||||
}
|
||||
}
|
||||
17
lib/pages/contact/model/contact_model.dart
Normal file
17
lib/pages/contact/model/contact_model.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/vo/contact.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class ContactModel extends BaseModel {
|
||||
final log = Logger('ContactModel');
|
||||
|
||||
Future<void> saveContact(Contact contact) async {
|
||||
await request("/contact", "PUT",
|
||||
payload: contact.toMap(),
|
||||
token: await Services.instance.authService.getToken());
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
103
lib/pages/contact/widgets.dart
Normal file
103
lib/pages/contact/widgets.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget itemTitle(BuildContext context, String textKey) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 18.0, top: 25, bottom: 5),
|
||||
child: Text(
|
||||
AppTranslations.of(context).text(textKey),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 0, top: 0, bottom: 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
iconData,
|
||||
color: primaryColor,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
AppTranslations.of(context).text(textKey),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700, fontSize: 15, color: primaryColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget contactItem(BuildContext context, String text, IconData iconData,
|
||||
{Function() onTap, String labelKey}) {
|
||||
return Material(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 18.0, bottom: 10, right: 18),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey, width: 0.8),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(5.0) // <--- border radius here
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => onTap != null ? onTap() : null,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
iconData,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
labelKey == null
|
||||
? Container()
|
||||
: Padding(
|
||||
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
|
||||
child: LocalText(context, labelKey,
|
||||
color: primaryColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 18),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
text == null ? "" : text,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 5,
|
||||
style: TextStyle(
|
||||
fontSize: 14.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
onTap == null
|
||||
? Container()
|
||||
: Icon(
|
||||
Icons.open_in_new,
|
||||
color: Colors.grey,
|
||||
size: 15,
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user