81 lines
2.7 KiB
Dart
81 lines
2.7 KiB
Dart
import 'package:aman_kassa_flutter/core/entity/Voucher.dart';
|
|
import 'package:aman_kassa_flutter/core/locator.dart';
|
|
import 'package:aman_kassa_flutter/core/route_names.dart';
|
|
import 'package:aman_kassa_flutter/core/services/DbService.dart';
|
|
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
|
|
import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
|
import 'package:aman_kassa_flutter/views/check/image_show_container.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
|
|
|
class HistoryView extends StatefulWidget {
|
|
HistoryView();
|
|
|
|
@override
|
|
_HistoryViewState createState() => _HistoryViewState();
|
|
}
|
|
|
|
class _HistoryViewState extends State<HistoryView> {
|
|
DateFormat dateFormat = DateFormat("dd.MM.yyyy HH:mm:ss");
|
|
DbService _dbService = locator<DbService>();
|
|
NavigatorService _navigatorService = locator<NavigatorService>();
|
|
List<Voucher> data = [];
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
load();
|
|
}
|
|
|
|
load() async {
|
|
List<Map> list = await _dbService.queryAllRowsOrderBy(Voucher_tableName, '$Voucher_columnDateTime desc');
|
|
print(list);
|
|
setState(() {
|
|
data = list.map((e) => Voucher.fromMap(e)).toList();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('История чеков'),
|
|
actions: <Widget>[
|
|
FlatButton(
|
|
child: Text('Очистить', style: TextStyle(color: whiteColor, fontSize: 15, fontWeight: FontWeight.bold),),
|
|
onPressed: () async {
|
|
await _dbService.deleteAll(Voucher_tableName);
|
|
await this.load();
|
|
})
|
|
],
|
|
),
|
|
body: ListView.separated(
|
|
itemCount: data.length,
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return Divider();
|
|
},
|
|
itemBuilder: (BuildContext context, int index) {
|
|
Voucher voucher = data[index];
|
|
return ListTile(
|
|
onTap: (){
|
|
_navigatorService.push(ImageShowRoute,
|
|
arguments: ImageShowModel(voucher.base64Data, voucher.name));
|
|
},
|
|
title: buildText(voucher),
|
|
subtitle: Text(dateFormat.format(voucher.dateTime)),
|
|
trailing: Icon(Icons.arrow_right),
|
|
leading: voucher.type == VoucherTypePayment ? Icon(MdiIcons.cashRegister, size: 40,) : Icon(Icons.description, size: 40,),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Text buildText(Voucher voucher) {
|
|
if( voucher.type == VoucherTypePayment ){
|
|
return Text('${voucher.name} на сумму: ${voucher.total.toStringAsFixed(2)}');
|
|
}
|
|
return Text('${voucher.name}');
|
|
}
|
|
}
|