Files
fcs/lib/pages/customer/customer_editor.dart

153 lines
4.7 KiB
Dart
Raw Normal View History

2020-10-17 01:40:24 +06:30
import 'package:fcs/domain/constants.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
2020-10-17 01:40:24 +06:30
import 'package:fcs/pages/widgets/local_button.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-14 13:54:42 +06:30
import 'package:flutter/cupertino.dart';
2020-09-11 16:14:36 +06:30
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
typedef void FindCallBack();
class CustomerEditor extends StatefulWidget {
2021-09-10 12:00:08 +06:30
final User? customer;
2020-09-11 16:14:36 +06:30
const CustomerEditor({this.customer});
@override
_CustomerEditorState createState() => _CustomerEditorState();
}
class _CustomerEditorState extends State<CustomerEditor> {
bool _isLoading = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var phoneNumberBox = Row(
children: <Widget>[
Expanded(
2020-09-13 21:49:39 +06:30
child: DisplayText(
2021-09-10 12:00:08 +06:30
text: widget.customer!.phoneNumber,
2020-10-13 07:50:25 +06:30
labelTextKey: "customer.phone",
2020-09-13 21:49:39 +06:30
iconData: Icons.phone,
)),
IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor),
2021-09-10 16:33:52 +06:30
onPressed: () => call(context, widget.customer?.phoneNumber ?? "")),
2020-09-11 16:14:36 +06:30
],
);
2021-09-10 12:00:08 +06:30
final enabled = widget.customer!.status != user_disabled_status;
2020-10-17 01:40:24 +06:30
final enableBox = LocalButton(
textKey: enabled ? "customer.disable.btn" : "customer.enable.btn",
iconData: enabled ? Icons.lock : Icons.lock_open,
color: enabled ? primaryColor : Colors.grey,
callBack: () => _enable(!enabled),
);
2020-09-11 16:14:36 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
2020-09-13 21:49:39 +06:30
child: SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
centerTitle: true,
leading: new IconButton(
icon: new Icon(
2020-10-17 01:40:24 +06:30
CupertinoIcons.back,
2020-09-13 21:49:39 +06:30
color: primaryColor,
size: 30,
),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
2021-09-10 16:33:52 +06:30
widget.customer?.name ?? "",
2020-09-13 21:49:39 +06:30
style: TextStyle(
fontSize: 20,
color: primaryColor,
),
),
2020-09-11 16:14:36 +06:30
),
2020-09-13 21:49:39 +06:30
body: Padding(
padding: const EdgeInsets.all(8.0),
2020-09-15 07:13:41 +06:30
child: ListView(
2020-09-13 21:49:39 +06:30
children: <Widget>[
2020-09-15 07:13:41 +06:30
phoneNumberBox,
DisplayText(
2021-09-10 12:00:08 +06:30
text: widget.customer!.fcsID,
2020-10-13 07:50:25 +06:30
labelTextKey: "customer.fcs.id",
2020-09-18 04:04:21 +06:30
icon: FcsIDIcon(),
2020-09-15 07:13:41 +06:30
),
2020-09-20 08:06:14 +06:30
DisplayText(
2021-09-10 12:00:08 +06:30
text: widget.customer!.status,
2020-10-13 07:50:25 +06:30
labelTextKey: "customer.status",
2020-09-20 08:06:14 +06:30
iconData: Icons.add_alarm,
),
2020-09-15 07:13:41 +06:30
SizedBox(
height: 20,
2020-09-13 21:49:39 +06:30
),
2021-09-10 12:00:08 +06:30
widget.customer!.requested
2020-09-13 21:49:39 +06:30
? fcsButton(
context,
getLocalString(
context, "customer.invitation.request.confirm"),
callack: _add)
2020-10-17 01:40:24 +06:30
: Container(),
2021-09-10 12:00:08 +06:30
widget.customer!.joined || widget.customer!.disabled
2020-10-17 01:40:24 +06:30
? enableBox
2020-09-13 21:49:39 +06:30
: Container()
],
),
2020-09-11 16:14:36 +06:30
),
),
));
}
2020-09-13 21:49:39 +06:30
_add() async {
showConfirmDialog(context, "customer.invitation.request.confirm", () async {
setState(() {
_isLoading = true;
});
if (widget.customer == null) return;
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
2021-09-10 16:33:52 +06:30
await customerModel.acceptRequest(widget.customer?.id ?? "");
2020-09-13 21:49:39 +06:30
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
2020-09-11 16:14:36 +06:30
});
}
2020-10-17 01:40:24 +06:30
_enable(bool enabled) async {
setState(() {
_isLoading = true;
});
if (widget.customer == null) return;
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
try {
2021-09-10 12:00:08 +06:30
await customerModel.enableUser(widget.customer!, enabled);
2020-10-17 01:40:24 +06:30
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
2020-09-11 16:14:36 +06:30
}