add contact page

This commit is contained in:
Sai Naw Wun
2020-09-07 00:47:02 +06:30
parent 9423df2cd1
commit a35d222696
6 changed files with 488 additions and 110 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:fcs/fcs/common/helpers/theme.dart';
import 'package:fcs/fcs/common/localization/app_translations_delegate.dart';
import 'package:fcs/fcs/common/localization/transalation.dart';
import 'package:fcs/fcs/common/pages/model/language_model.dart';
@@ -19,6 +20,7 @@ import 'package:fcs/model_fcs/message_model.dart';
import 'package:fcs/model_fcs/package_model.dart';
import 'package:fcs/pages/email_page.dart';
import 'package:fcs/pages/login_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
@@ -242,18 +244,36 @@ class _AppState extends State<App> {
ChangeNotifierProvider.value(value: testModel),
ChangeNotifierProvider.value(value: mainModel2),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'FCS',
routes: route(context),
theme: ThemeData(accentColor: Colors.black),
localizationsDelegates: [
_newLocaleDelegate,
//provides localised strings
GlobalMaterialLocalizations.delegate,
//provides RTL support
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: Translation().supportedLocales()));
child: Consumer<LanguageModel>(
builder: (context, value, child) {
return CupertinoApp(
debugShowCheckedModeBanner: false,
title: 'FCS',
theme: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
navActionTextStyle: TextStyle(color: Colors.white),
navTitleTextStyle: TextStyle(
color: Colors.white,
fontSize: value.isEng ? 20 : 18,
fontWeight: FontWeight.bold),
navLargeTitleTextStyle: TextStyle(
color: Colors.white,
fontSize: value.isEng ? 40 : 24,
fontWeight: FontWeight.bold),
primaryColor: primaryColor,
textStyle: TextStyle(color: Colors.white),
actionTextStyle: TextStyle(color: Colors.white),
)),
routes: route(context),
localizationsDelegates: [
_newLocaleDelegate,
//provides localised strings
GlobalMaterialLocalizations.delegate,
//provides RTL support
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: Translation().supportedLocales());
},
));
}
}

View File

@@ -1,9 +1,12 @@
import 'package:fcs/fcs/common/domain/entities/setting.dart';
import 'package:fcs/fcs/common/helpers/theme.dart';
import 'package:fcs/fcs/common/localization/app_translations.dart';
import 'package:fcs/fcs/common/pages/contact_editor.dart';
import 'package:fcs/fcs/common/pages/model/language_model.dart';
import 'package:fcs/fcs/common/pages/model/main_model.dart';
import 'package:fcs/fcs/common/pages/widgets/local_text.dart';
import 'package:fcs/fcs/common/pages/widgets/progress.dart';
import 'package:fcs/fcs/common/pages/util.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';
@@ -21,53 +24,69 @@ class _ContactState extends State<Contact> {
@override
Widget build(BuildContext context) {
Setting setting = Provider.of<MainModel>(context).setting;
bool isEng = Provider.of<LanguageModel>(context).isEng;
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
elevation: 0,
centerTitle: true,
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
child: CupertinoPageScaffold(
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
CupertinoSliverNavigationBar(
backgroundColor: primaryColor,
actionsForegroundColor: Colors.white,
largeTitle: Text(
AppTranslations.of(context).text('contact.title'),
),
trailing: GestureDetector(
onTap: () =>
Navigator.of(context).push<void>(CupertinoPageRoute(
builder: (context) => ContactEditor(
setting: setting,
),
)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
CupertinoIcons.pen,
size: 23,
color: Colors.white,
),
)),
),
];
},
body: ListView(
children: <Widget>[
itemTitle("contact.callus"),
link(setting.usaContactNumber, Icons.phone_forwarded,
onTap: () => _call(setting.usaContactNumber),
label: LocalText(context, "contact.usa.phone",
color: primaryColor, fontWeight: FontWeight.bold)),
link(setting.mmContactNumber, Icons.phone_forwarded,
onTap: () => _call(
setting.mmContactNumber,
),
label: LocalText(context, "contact.mm.phone",
color: primaryColor, fontWeight: FontWeight.bold)),
itemTitle("contact.findus"),
link(setting.usaAddress, Icons.location_on,
label: LocalText(context, "contact.usa.address",
color: primaryColor, fontWeight: FontWeight.bold)),
link(setting.mmAddress, Icons.location_on,
label: LocalText(context, "contact.mm.address",
color: primaryColor, fontWeight: FontWeight.bold)),
itemTitle("contact.emailus"),
link(setting.emailAddress, Icons.email,
onTap: () => _email(setting.emailAddress),
label: LocalText(context, "contact.fcs.email",
color: primaryColor, fontWeight: FontWeight.bold)),
itemTitle("contact.visitus"),
link(setting.facebookLink, FontAwesomeIcons.facebook,
onTap: () => _openLink(setting.facebookLink),
label: LocalText(context, "contact.facebook",
color: primaryColor, fontWeight: FontWeight.bold)),
],
),
title: LocalText(
context,
"contact",
fontSize: 25,
color: Colors.white,
),
),
body: ListView(
children: <Widget>[
link(setting.usaContactNumber, Icons.phone_forwarded,
onTap: () => _call(setting.usaContactNumber),
label: LocalText(
context,
"contact.usa.phone",
color: primaryColor,
)),
link(setting.mmContactNumber, Icons.phone_forwarded,
onTap: () => _call(
setting.mmContactNumber,
),
label: LocalText(
context,
"contact.mm.phone",
color: primaryColor,
)),
link(
setting.usaAddress,
Icons.location_on,
),
link(setting.mmAddress, Icons.location_on),
link(setting.emailAddress, Icons.email,
onTap: () => _email(setting.emailAddress)),
link(setting.facebookLink, FontAwesomeIcons.facebook,
onTap: () => _openLink(setting.facebookLink)),
],
),
),
);
@@ -75,53 +94,77 @@ class _ContactState extends State<Contact> {
Widget link(String text, IconData iconData,
{Function() onTap, Widget label}) {
return Padding(
padding: const EdgeInsets.only(left: 18.0, bottom: 5),
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,
),
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
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
),
child: InkWell(
onTap: () => onTap != null ? onTap() : null,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
label == null
? Container()
: Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: label,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
text == null ? "" : text,
overflow: TextOverflow.ellipsis,
maxLines: 5,
style: TextStyle(fontSize: 14.0),
child: Icon(
iconData,
color: primaryColor,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
label == null
? Container()
: Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: label,
),
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,
)
],
),
SizedBox(
width: 5,
),
onTap == null
? Container()
: Icon(
Icons.open_in_new,
color: Colors.grey,
size: 15,
)
],
),
)),
)),
),
),
);
}
Widget itemTitle(String textKey) {
return Padding(
padding: const EdgeInsets.only(left: 18.0, top: 15, bottom: 5),
child: Text(
AppTranslations.of(context).text(textKey),
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black54),
),
);
}
@@ -132,19 +175,14 @@ class _ContactState extends State<Contact> {
}
_call(String phone) {
showConfirmDialog(
context, "contact.phone.confim", () => launch("tel:$phone"),
translationVariables: ["$phone"]);
launch("tel:$phone");
}
_email(String email) {
showConfirmDialog(
context, "contact.email.configm", () => launch("mailto:$email"),
translationVariables: ["$email"]);
launch("mailto:$email");
}
_openLink(String link) {
showConfirmDialog(context, "contact.open.confrim", () => launch("$link"),
translationVariables: ["$link"]);
launch("$link");
}
}

View File

@@ -0,0 +1,297 @@
import 'package:fcs/fcs/common/domain/entities/setting.dart';
import 'package:fcs/fcs/common/helpers/theme.dart';
import 'package:fcs/fcs/common/localization/app_translations.dart';
import 'package:fcs/fcs/common/pages/model/language_model.dart';
import 'package:fcs/fcs/common/pages/model/main_model.dart';
import 'package:fcs/fcs/common/pages/util.dart';
import 'package:fcs/fcs/common/pages/widgets/local_text.dart';
import 'package:fcs/fcs/common/pages/widgets/progress.dart';
import 'package:fcs/pages/phone_input.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';
class ContactEditor extends StatefulWidget {
final Setting setting;
const ContactEditor({this.setting});
@override
_ContactEditorState createState() => _ContactEditorState();
}
class _ContactEditorState extends State<ContactEditor> {
TextEditingController _email = new TextEditingController();
TextEditingController _facebook = new TextEditingController();
TextEditingController _website = new TextEditingController();
TextEditingController _address = new TextEditingController();
TextEditingController _deliveryPhone = new TextEditingController();
final _formKey = GlobalKey<FormState>();
bool _isLoading = false;
List<String> phones = new List();
List<String> _initPhones = new List();
@override
void initState() {
super.initState();
if (widget.setting != null) {
this._initPhones = widget.setting.phones;
_email.text = widget.setting.emailAddress;
_facebook.text = widget.setting.facebookLink;
_website.text = widget.setting.website;
_deliveryPhone.text = widget.setting.deliveryPhone;
_address.text = widget.setting.address;
phones.clear();
// _initPhones.forEach((p) {
// phones.add(p);
// });
}
}
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
final emailBox = TextFormField(
controller: _email,
autofocus: false,
cursorColor: primaryColor,
style: textStyle,
decoration: new InputDecoration(
labelText: AppTranslations.of(context).text('contact.email'),
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
icon: Icon(
Icons.email,
color: primaryColor,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
),
validator: (value) {
if (value.isEmpty) {
return AppTranslations.of(context).text('contact.email.empty');
}
return null;
},
);
final faceBookBox = TextFormField(
controller: _facebook,
autofocus: false,
cursorColor: primaryColor,
style: textStyle,
decoration: new InputDecoration(
labelText: AppTranslations.of(context).text('contact.facebook'),
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
icon: Icon(
FontAwesomeIcons.facebook,
color: primaryColor,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
),
validator: (value) {
if (value.isEmpty) {
return AppTranslations.of(context).text('contact.facebook.empty');
}
return null;
},
);
final googleBox = TextFormField(
controller: _website,
autofocus: false,
cursorColor: primaryColor,
style: textStyle,
decoration: new InputDecoration(
labelText: AppTranslations.of(context).text('contact.google'),
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
icon: Icon(
FontAwesomeIcons.chrome,
color: primaryColor,
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
),
validator: (value) {
if (value.isEmpty) {
return AppTranslations.of(context).text('contact.google.empty');
}
return null;
},
);
final addPhoneNumber = ListTile(
contentPadding: EdgeInsets.only(top: 15),
title: ButtonTheme(
height: 45,
child: RaisedButton(
color: Colors.white,
onPressed: () async {
var phone = await showDialog(
context: context, builder: (_) => PhoneEditor());
_save(phone);
},
child: Text("Add Phone",
style: TextStyle(
fontSize: 18,
)),
),
));
return LocalProgress(
inAsyncCall: _isLoading,
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(
AppTranslations.of(context).text('contact.edit.title'),
style: TextStyle(color: CupertinoColors.activeBlue),
),
),
// child: NestedScrollView(
// headerSliverBuilder:
// (BuildContext context, bool innerBoxIsScrolled) {
// return <Widget>[
// // CupertinoNavigationBar(),
// CupertinoSliverNavigationBar(
// largeTitle: Text(
// AppTranslations.of(context).text('contact.edit.title'),
// ),
// trailing: CupertinoButton(
// onPressed: () => {},
// child: Icon(
// CupertinoIcons.pen,
// )),
// )
// ];
// },
// body: Text("text"),
// appBar: AppBar(
// backgroundColor: primaryColor,
// title: LocalText(
// context,
// "contact.title",
// fontSize: 20,
// color: Colors.white,
// ),
// actions: <Widget>[
// IconButton(
// icon: Icon(Icons.send),
// onPressed: () {
// if (!_formKey.currentState.validate()) return;
// showConfirmDialog(context, "contact.confrim", () {
// _submit();
// });
// })
// ],
// ),
child: Form(
key: _formKey,
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.only(left: 24.0, right: 24.0),
children: <Widget>[
// this.phones.isNotEmpty
// ? ConstrainedBox(
// constraints: BoxConstraints(maxHeight: 1000),
// child: ListView.builder(
// shrinkWrap: true,
// itemBuilder: (context, index) {
// return Stack(
// alignment: const Alignment(1.0, 1.0),
// children: <Widget>[
// new TextField(
// controller: new TextEditingController(
// text: this.phones[index]),
// cursorColor: primaryColor,
// readOnly: true,
// decoration: new InputDecoration(
// border: InputBorder.none,
// focusedBorder: InputBorder.none,
// icon: Icon(
// Icons.phone,
// color: primaryColor,
// ),
// ),
// ),
// new FlatButton(
// onPressed: () {
// setState(() {
// this.phones.remove(this.phones[index]);
// });
// },
// child: new Icon(
// Icons.cancel,
// size: 25,
// ))
// ],
// );
// },
// itemCount: this.phones.length,
// ),
// )
// : Container(),
// addPhoneNumber,
// LocalTextField(
// textEditingController: _deliveryPhone,
// icon: Icon(
// Icons.phone_forwarded,
// color: primaryColor,
// ),
// labelKey: "contact.delivery.phone",
// ),
// emailBox,
// faceBookBox,
// googleBox,
// LocalTextField(
// textEditingController: _address,
// icon: Icon(
// Icons.location_on,
// color: primaryColor,
// ),
// labelKey: "contact.address",
// maxLines: 3,
// ),
],
),
)));
}
_save(String phone) {
if (phone == null) return;
setState(() {
this.phones.add(phone);
});
}
_submit() async {
setState(() {
_isLoading = true;
});
try {
widget.setting.emailAddress = _email.text;
widget.setting.facebookLink = _facebook.text;
widget.setting.website = _website.text;
widget.setting.phones = this.phones;
widget.setting.address = _address.text;
widget.setting.deliveryPhone = _deliveryPhone.text;
var mainModel = Provider.of<MainModel>(context);
// await mainModel.updateContact(widget.setting);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

View File

@@ -2,6 +2,7 @@ import 'package:fcs/fcs/common/pages/contact.dart';
import 'package:fcs/fcs/common/pages/term.dart';
import 'package:fcs/fcs/common/helpers/theme.dart';
import 'package:fcs/widget/bottom_up_page_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_icons/flutter_icons.dart';
@@ -14,13 +15,18 @@ class BottomWidgets extends StatelessWidget {
children: <Widget>[
InkWell(
onTap: () {
Navigator.of(context).push(BottomUpPageRoute(Contact()));
Navigator.of(context).push<void>(CupertinoPageRoute(
fullscreenDialog: true,
builder: (context) => Contact(),
));
},
child: _buildSmallButton("Contact Us", SimpleLineIcons.support),
),
InkWell(
onTap: () {
Navigator.of(context).push(BottomUpPageRoute(Term()));
Navigator.of(context).push<void>(CupertinoPageRoute(
builder: (context) => Term(),
));
},
child: _buildSmallButton("Terms of service", Icons.info_outline),
),