162 lines
5.4 KiB
Dart
162 lines
5.4 KiB
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 'package:fcs/model/main_model.dart';
|
|
import 'package:fcs/pages/util.dart';
|
|
import 'package:fcs/theme/theme.dart';
|
|
import 'package:fcs/widget/local_text.dart';
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
import 'contact_editor.dart';
|
|
|
|
class Contact extends StatefulWidget {
|
|
@override
|
|
_ContactState createState() => _ContactState();
|
|
}
|
|
|
|
class _ContactState extends State<Contact> {
|
|
bool _isLoading = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
bool isOwner = mainModel.user != null && mainModel.user.isOwner();
|
|
bool hasAdmin = mainModel.user != null && mainModel.user.hasAdmin();
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.white,
|
|
iconTheme: IconThemeData(
|
|
color: Colors.grey,
|
|
),
|
|
elevation: 0,
|
|
centerTitle: true,
|
|
title: Image(
|
|
height: 30,
|
|
fit: BoxFit.scaleDown,
|
|
image: new AssetImage('assets/img/logo.png')),
|
|
actions: <Widget>[
|
|
isOwner || hasAdmin
|
|
? IconButton(
|
|
icon: Icon(Icons.edit),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
ContactEditor(setting: mainModel.setting)),
|
|
);
|
|
},
|
|
)
|
|
: Container()
|
|
],
|
|
),
|
|
body: ListView(
|
|
children: <Widget>[
|
|
Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(top: 5.0, bottom: 5),
|
|
child: LocalText(
|
|
context,
|
|
"contact.title",
|
|
fontSize: 25,
|
|
)),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 15.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children:
|
|
List.generate(mainModel.setting.phones.length, (index) {
|
|
return link(mainModel.setting.phones[index], Icons.phone,
|
|
onTap: () => _call(mainModel.setting.phones[index]));
|
|
}),
|
|
),
|
|
),
|
|
link(mainModel.setting.deliveryPhone, Icons.phone_forwarded,
|
|
onTap: () => _call(mainModel.setting.deliveryPhone),
|
|
label: LocalText(context, "contact.delivery.phone")),
|
|
link(mainModel.setting.email, Icons.email,
|
|
onTap: () => _email(mainModel.setting.email)),
|
|
link(mainModel.setting.facebook, FontAwesomeIcons.facebook,
|
|
onTap: () => _openLink(mainModel.setting.facebook)),
|
|
link(mainModel.setting.website, FontAwesomeIcons.chrome,
|
|
onTap: () => _openLink(mainModel.setting.website)),
|
|
link(mainModel.setting.address, Icons.location_on),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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,
|
|
color: primaryColor,
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
label == null ? Container() : label,
|
|
Text(
|
|
text == null ? "" : text,
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 5,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 5,
|
|
),
|
|
onTap == null
|
|
? Container()
|
|
: Icon(
|
|
Icons.open_in_new,
|
|
color: Colors.grey,
|
|
size: 15,
|
|
)
|
|
],
|
|
),
|
|
)),
|
|
);
|
|
}
|
|
|
|
Future<String> getVersionNumber() async {
|
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
|
String version = packageInfo.version + "+" + packageInfo.buildNumber;
|
|
return version;
|
|
}
|
|
|
|
_call(String phone) {
|
|
showConfirmDialog(
|
|
context, "contact.phone.confim", () => launch("tel:$phone"),
|
|
translationVariables: ["$phone"]);
|
|
}
|
|
|
|
_email(String email) {
|
|
showConfirmDialog(
|
|
context, "contact.email.configm", () => launch("mailto:$email"),
|
|
translationVariables: ["$email"]);
|
|
}
|
|
|
|
_openLink(String link) {
|
|
showConfirmDialog(context, "contact.open.confrim", () => launch("$link"),
|
|
translationVariables: ["$link"]);
|
|
}
|
|
}
|