clean up
This commit is contained in:
135
lib/pages/discount/discount_editor.dart
Normal file
135
lib/pages/discount/discount_editor.dart
Normal file
@@ -0,0 +1,135 @@
|
||||
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';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
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) {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
AppTranslations.of(context).text("discount.form"),
|
||||
),
|
||||
leading: new IconButton(
|
||||
icon: new Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
actions: <Widget>[],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
fcsInput('Code', FontAwesomeIcons.algolia,
|
||||
controller: _codeController),
|
||||
fcsInput('Customer Name', Feather.user,
|
||||
controller: _customerController),
|
||||
fcsInput('Amount', FontAwesomeIcons.moneyBill,
|
||||
controller: _amountController),
|
||||
widget.discount == null
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: TextFormField(
|
||||
controller: _statusController,
|
||||
readOnly: true,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
labelText: 'Status',
|
||||
labelStyle: TextStyle(
|
||||
fontSize: 16, color: primaryColor),
|
||||
filled: true,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
icon: Icon(
|
||||
Icons.av_timer,
|
||||
color: primaryColor,
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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,
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
131
lib/pages/discount/discount_list.dart
Normal file
131
lib/pages/discount/discount_list.dart
Normal file
@@ -0,0 +1,131 @@
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'discount_editor.dart';
|
||||
|
||||
class DiscountList extends StatefulWidget {
|
||||
@override
|
||||
_DiscountListState createState() => _DiscountListState();
|
||||
}
|
||||
|
||||
class _DiscountListState extends State<DiscountList> {
|
||||
bool _isLoading = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var discountModel = Provider.of<DiscountModel>(context);
|
||||
print('discounts => ${discountModel.discounts}');
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
AppTranslations.of(context).text("discount.title"),
|
||||
),
|
||||
leading: new IconButton(
|
||||
icon: new Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.search),
|
||||
onPressed: () {},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: ListView.separated(
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
),
|
||||
itemCount: discountModel.discounts.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var discount = discountModel.discounts[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(DiscountEditor(
|
||||
discount: discount,
|
||||
)),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Text(
|
||||
discount.code,
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
discount.customer,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 15),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 10.0, bottom: 5.0),
|
||||
child: Text(
|
||||
'\$ ${discount.amount.toString()}',
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16),
|
||||
),
|
||||
),
|
||||
getStatus(discount.status),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(DiscountEditor()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: Text(AppTranslations.of(context).text("discount.new")),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
56
lib/pages/discount/model/discount_model.dart
Normal file
56
lib/pages/discount/model/discount_model.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
|
||||
class DiscountModel extends BaseModel {
|
||||
List<Discount> get discounts {
|
||||
List<Discount> discountList = [
|
||||
Discount(
|
||||
code: 'XMQY01',
|
||||
customer: 'Ko Nyi',
|
||||
amount: 5000,
|
||||
status: 'Used',
|
||||
),
|
||||
Discount(
|
||||
code: 'XMQY02',
|
||||
customer: 'Ko Aung Myo',
|
||||
amount: 3000,
|
||||
status: 'Avaliable',
|
||||
),
|
||||
Discount(
|
||||
code: 'XMQY03',
|
||||
customer: 'Ko Zaw Thu',
|
||||
amount: 2000,
|
||||
status: 'Used',
|
||||
),
|
||||
Discount(
|
||||
code: 'XMQY04',
|
||||
customer: 'Ko Myo Min',
|
||||
amount: 3000,
|
||||
status: 'Avaliable',
|
||||
),
|
||||
Discount(
|
||||
code: 'XMQY05',
|
||||
customer: 'Ko Nyi',
|
||||
amount: 3000,
|
||||
status: 'Avaliable',
|
||||
),
|
||||
];
|
||||
return discountList;
|
||||
}
|
||||
|
||||
// List<Discount> get discountByCustomer {
|
||||
// return invoices.where((e) => e.status == "Avaliable").toList()
|
||||
// ..sort((e1, e2) {
|
||||
// return e2.invoiceNumber.compareTo(e1.invoiceNumber);
|
||||
// });
|
||||
// }
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
// discounts = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user