Files
fcs/lib/fcs/common/pages/contact.dart
2020-09-07 00:47:02 +06:30

189 lines
7.0 KiB
Dart

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: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';
class Contact extends StatefulWidget {
@override
_ContactState createState() => _ContactState();
}
class _ContactState extends State<Contact> {
bool _isLoading = false;
@override
Widget build(BuildContext context) {
Setting setting = Provider.of<MainModel>(context).setting;
bool isEng = Provider.of<LanguageModel>(context).isEng;
return LocalProgress(
inAsyncCall: _isLoading,
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)),
],
),
),
),
);
}
Widget link(String text, IconData iconData,
{Function() onTap, Widget label}) {
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>[
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,
)
],
),
)),
),
),
);
}
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),
),
);
}
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");
}
_openLink(String link) {
launch("$link");
}
}