2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/entities/discount.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-07 18:49:28 +06:30
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/input_text.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-06-26 16:04:40 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
|
|
|
|
|
class DiscountEditor extends StatefulWidget {
|
|
|
|
|
final Discount discount;
|
|
|
|
|
|
|
|
|
|
const DiscountEditor({Key key, this.discount}) : super(key: key);
|
|
|
|
|
@override
|
|
|
|
|
_DiscountEditorState createState() => _DiscountEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _DiscountEditorState extends State<DiscountEditor> {
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
Discount _discount = new Discount();
|
|
|
|
|
TextEditingController _codeController = new TextEditingController();
|
|
|
|
|
TextEditingController _amountController = new TextEditingController();
|
|
|
|
|
TextEditingController _statusController = new TextEditingController();
|
|
|
|
|
TextEditingController _customerController = new TextEditingController();
|
|
|
|
|
|
|
|
|
|
bool isNew = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if (widget.discount != null) {
|
|
|
|
|
_discount = widget.discount;
|
|
|
|
|
_codeController.text = _discount.code;
|
|
|
|
|
_amountController.text = _discount.amount.toString();
|
|
|
|
|
_statusController.text = _discount.status;
|
|
|
|
|
_customerController.text = 'Ko Nyi';
|
|
|
|
|
} else {
|
|
|
|
|
isNew = true;
|
|
|
|
|
_customerController.text = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-07 18:49:28 +06:30
|
|
|
final codeBox = InputText(
|
|
|
|
|
labelTextKey: 'discount.code',
|
|
|
|
|
iconData: FontAwesomeIcons.algolia,
|
|
|
|
|
controller: _codeController);
|
|
|
|
|
final nameBox = InputText(
|
|
|
|
|
labelTextKey: 'discount.name',
|
|
|
|
|
iconData: Feather.user,
|
|
|
|
|
controller: _customerController);
|
|
|
|
|
final amountBox = InputText(
|
|
|
|
|
labelTextKey: 'discount.amount',
|
|
|
|
|
iconData: FontAwesomeIcons.moneyBill,
|
|
|
|
|
controller: _amountController);
|
|
|
|
|
final statusBox = DisplayText(
|
|
|
|
|
text: _statusController.text,
|
2020-10-08 03:32:52 +06:30
|
|
|
labelTextKey: getLocalString(context, "discount.status"),
|
2020-10-07 18:49:28 +06:30
|
|
|
iconData: Icons.av_timer,
|
|
|
|
|
);
|
|
|
|
|
|
2020-06-26 16:04:40 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
appBar: AppBar(
|
2020-06-30 16:11:58 +06:30
|
|
|
centerTitle: true,
|
2020-06-26 16:04:40 +06:30
|
|
|
title: Text(
|
2020-06-30 16:11:58 +06:30
|
|
|
AppTranslations.of(context).text("discount.form"),
|
|
|
|
|
),
|
|
|
|
|
leading: new IconButton(
|
2020-10-14 13:54:42 +06:30
|
|
|
icon: new Icon(CupertinoIcons.back),
|
2020-06-30 16:11:58 +06:30
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2020-06-26 16:04:40 +06:30
|
|
|
),
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
actions: <Widget>[],
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
2020-10-07 18:49:28 +06:30
|
|
|
codeBox,
|
|
|
|
|
nameBox,
|
|
|
|
|
amountBox,
|
2020-06-26 16:04:40 +06:30
|
|
|
widget.discount == null
|
|
|
|
|
? Container()
|
|
|
|
|
: Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 5),
|
2020-10-07 18:49:28 +06:30
|
|
|
child: statusBox,
|
2020-06-26 16:04:40 +06:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
widget.discount == null
|
|
|
|
|
? Align(
|
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 250,
|
|
|
|
|
child: FlatButton(
|
|
|
|
|
child: Text('Add Discount'),
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
textColor: Colors.white,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)))
|
|
|
|
|
: Align(
|
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 250,
|
|
|
|
|
child: FlatButton(
|
|
|
|
|
child: Text('Save box'),
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
textColor: Colors.white,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
))),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 30,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|