2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/entities/payment_method.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/pages/main/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/pages/payment_methods/model/payment_method_model.dart';
|
|
|
|
|
import 'package:fcs/pages/payment_methods/payment_method_editor.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-09-18 04:04:21 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class PaymentMethodPage extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_PaymentMethodPageState createState() => _PaymentMethodPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PaymentMethodPageState extends State<PaymentMethodPage> {
|
|
|
|
|
GlobalKey key = GlobalKey();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
PaymentMethodModel mainModel = Provider.of<PaymentMethodModel>(context);
|
2020-09-18 21:33:41 +06:30
|
|
|
bool isEditable =
|
|
|
|
|
context.select((MainModel m) => m.paymentMethodsEditable());
|
2020-09-18 04:04:21 +06:30
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
key: key,
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(
|
|
|
|
|
Icons.close,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"pm.title",
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
actions: <Widget>[],
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
separatorBuilder: (context, index) => Divider(
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
itemCount: mainModel.paymentMethods.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
var method = mainModel.paymentMethods[index];
|
2020-09-18 21:33:41 +06:30
|
|
|
return _item(method, isEditable);
|
2020-09-18 04:04:21 +06:30
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-09-18 21:33:41 +06:30
|
|
|
floatingActionButton: isEditable
|
|
|
|
|
? FloatingActionButton.extended(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
BottomUpPageRoute(PaymentMethodEditor()),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.add),
|
|
|
|
|
label: LocalText(context, "pm.new", color: Colors.white),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
2020-09-18 04:04:21 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 21:33:41 +06:30
|
|
|
_item(PaymentMethod method, bool isEditable) {
|
2020-09-18 04:04:21 +06:30
|
|
|
final accountName = _itemRow(method.accountName, "pm.account.name",
|
|
|
|
|
iconData: MaterialCommunityIcons.bank);
|
|
|
|
|
final accountNumber = _itemRow(method.account, "pm.account.no",
|
|
|
|
|
iconData: MaterialCommunityIcons.checkbook);
|
|
|
|
|
final phone = _itemRow(method.phone, "pm.phone", iconData: Icons.phone);
|
|
|
|
|
final email = _itemRow(method.email, "pm.email", iconData: Icons.mail);
|
|
|
|
|
final link = _itemRow(method.link, "pm.link", iconData: Icons.link);
|
|
|
|
|
|
|
|
|
|
return InkWell(
|
2020-09-18 21:33:41 +06:30
|
|
|
onTap: isEditable
|
|
|
|
|
? () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
BottomUpPageRoute(PaymentMethodEditor(
|
|
|
|
|
paymentMethod: method,
|
|
|
|
|
)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
: null,
|
2020-09-18 04:04:21 +06:30
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
method.name,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 18),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
accountName,
|
|
|
|
|
accountNumber,
|
|
|
|
|
phone,
|
|
|
|
|
email,
|
|
|
|
|
link
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_itemRow(String text, String labelKey, {IconData iconData}) {
|
|
|
|
|
return text == null || text == ""
|
|
|
|
|
? Container()
|
|
|
|
|
: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: DisplayText(
|
|
|
|
|
text: text,
|
2020-10-08 03:32:52 +06:30
|
|
|
labelTextKey: getLocalString(context, labelKey),
|
2020-09-18 04:04:21 +06:30
|
|
|
iconData: iconData,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.content_copy, color: Colors.grey),
|
|
|
|
|
onPressed: () => _copy(getLocalString(context, labelKey), text),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_copy(String title, String data) {
|
|
|
|
|
Clipboard.setData(ClipboardData(text: data));
|
|
|
|
|
_showToast(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showToast(String title) {
|
|
|
|
|
final ScaffoldState scaffold = key.currentState;
|
|
|
|
|
scaffold.showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text('copied "$title" data to clipboard'),
|
|
|
|
|
backgroundColor: secondaryColor,
|
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|