refactor
This commit is contained in:
parent
cf1214e2ae
commit
4b2c8711df
4 changed files with 197 additions and 100 deletions
|
@ -4,6 +4,8 @@ import 'package:cdb_ui/pages/flow/end_flow_page.dart';
|
||||||
import 'package:cdb_ui/pages/flow/flow_note.dart';
|
import 'package:cdb_ui/pages/flow/flow_note.dart';
|
||||||
import 'package:cdb_ui/pages/transaction.dart';
|
import 'package:cdb_ui/pages/transaction.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:qr_bar_code/qr/src/qr_code.dart';
|
||||||
|
import 'package:qr_bar_code/qr/src/types.dart';
|
||||||
|
|
||||||
class ActiveFlowPage extends StatefulWidget {
|
class ActiveFlowPage extends StatefulWidget {
|
||||||
final API.Flow flow;
|
final API.Flow flow;
|
||||||
|
@ -80,40 +82,56 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
|
||||||
icon: const Icon(Icons.arrow_forward)),
|
icon: const Icon(Icons.arrow_forward)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Padding(
|
||||||
children: [
|
padding: EdgeInsets.symmetric(horizontal: 18.0),
|
||||||
Text("ID: ${widget.flow.id}"),
|
child: Column(
|
||||||
Text("Started since: ${tsFormat(widget.flow.started)}"),
|
children: [
|
||||||
if (widget.flow.input != null)
|
Row(
|
||||||
...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
|
children: [
|
||||||
if (widget.flow.done != null) ...[
|
QRCode(
|
||||||
Text("Ended: ${tsFormat(widget.flow.done!.ended)}"),
|
data: widget.flow.id,
|
||||||
if (widget.flow.done!.next != null)
|
size: 128,
|
||||||
Text("Next: ${widget.flow.done!.next!}"),
|
eyeStyle: const QREyeStyle(color: Colors.white),
|
||||||
...widget.flow.done!.produced!
|
dataModuleStyle: const QRDataModuleStyle(color: Colors.white),
|
||||||
.map((x) => Text("Produced: $x"))
|
semanticsLabel: "Transaction UUID",
|
||||||
.toList(),
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 16.0,
|
||||||
|
),
|
||||||
|
Text("Started since: ${tsFormat(widget.flow.started)}"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (widget.flow.input != null)
|
||||||
|
...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
|
||||||
|
if (widget.flow.done != null) ...[
|
||||||
|
Text("Ended: ${tsFormat(widget.flow.done!.ended)}"),
|
||||||
|
if (widget.flow.done!.next != null)
|
||||||
|
Text("Next: ${widget.flow.done!.next!}"),
|
||||||
|
...widget.flow.done!.produced!
|
||||||
|
.map((x) => Text("Produced: $x"))
|
||||||
|
.toList(),
|
||||||
|
],
|
||||||
|
const Divider(),
|
||||||
|
FutureBuilder(
|
||||||
|
future: API.API().getNotesOfFlow(widget.flow.id),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return const CircularProgressIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = snapshot.data!;
|
||||||
|
|
||||||
|
return Expanded(
|
||||||
|
child: ListView(
|
||||||
|
children: data
|
||||||
|
.map(
|
||||||
|
(x) => FlowNoteCard(x),
|
||||||
|
)
|
||||||
|
.toList()));
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
const Divider(),
|
),
|
||||||
FutureBuilder(
|
|
||||||
future: API.API().getNotesOfFlow(widget.flow.id),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (!snapshot.hasData) {
|
|
||||||
return const CircularProgressIndicator();
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = snapshot.data!;
|
|
||||||
|
|
||||||
return Expanded(
|
|
||||||
child: ListView(
|
|
||||||
children: data
|
|
||||||
.map(
|
|
||||||
(x) => FlowNoteCard(x),
|
|
||||||
)
|
|
||||||
.toList()));
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
|
@ -48,6 +48,7 @@ class FlowNoteCard extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
|
dense: true,
|
||||||
title: Text(tsFormat(note.timestamp),
|
title: Text(tsFormat(note.timestamp),
|
||||||
style: const TextStyle(fontSize: 12)),
|
style: const TextStyle(fontSize: 12)),
|
||||||
subtitle: Text(note.content, overflow: TextOverflow.ellipsis),
|
subtitle: Text(note.content, overflow: TextOverflow.ellipsis),
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import 'package:cdb_ui/api.dart' as API;
|
import 'package:cdb_ui/api.dart' as API;
|
||||||
import 'package:cdb_ui/pages/expandable_list.dart';
|
import 'package:cdb_ui/pages/expandable_list.dart';
|
||||||
|
import 'package:cdb_ui/pages/flow/active_flow_page.dart';
|
||||||
import 'package:cdb_ui/pages/flow/flow_info_page.dart';
|
import 'package:cdb_ui/pages/flow/flow_info_page.dart';
|
||||||
import 'package:cdb_ui/pages/transaction.dart';
|
import 'package:cdb_ui/pages/transaction.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
||||||
|
|
||||||
class FlowsPage extends StatefulWidget {
|
class FlowsPage extends StatefulWidget {
|
||||||
const FlowsPage({super.key});
|
const FlowsPage({super.key});
|
||||||
|
@ -135,27 +137,51 @@ class _FlowsPageState extends State<FlowsPage> {
|
||||||
return DefaultTabController(
|
return DefaultTabController(
|
||||||
length: 4,
|
length: 4,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text("Flows"),
|
title: const Text("Flows"),
|
||||||
bottom: TabBar(
|
bottom: TabBar(
|
||||||
tabs: const [
|
tabs: const [
|
||||||
Tab(text: "All"),
|
Tab(text: "All"),
|
||||||
Tab(text: "Produces"),
|
Tab(text: "Produces"),
|
||||||
Tab(text: "Depends"),
|
Tab(text: "Depends"),
|
||||||
Tab(text: "Active")
|
Tab(text: "Active")
|
||||||
],
|
],
|
||||||
onTap: (value) {
|
onTap: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
tabSelection = value;
|
tabSelection = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
body: switch (tabSelection) {
|
||||||
|
0 => listAllFlowInfos(context, flowInfos!),
|
||||||
|
1 => listFlowInfoByProduced(context, flowInfos!),
|
||||||
|
2 => listFlowInfoByDependant(context, flowInfos!),
|
||||||
|
3 => listFlowInfoByActive(context, flowInfos!),
|
||||||
|
_ => const Text("..."),
|
||||||
|
},
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () {
|
||||||
|
// scan flow code
|
||||||
|
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||||
|
context: context,
|
||||||
|
onCode: (code) {
|
||||||
|
// library is retarded
|
||||||
|
code = code!.replaceFirst("Code scanned = ", "");
|
||||||
|
|
||||||
|
API.API().getFlow(code).then((flow) {
|
||||||
|
API.API().getFlowInfo(flow.kind).then((info) {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
|
return ActiveFlowPage(flow, info);
|
||||||
|
},
|
||||||
|
));
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
)),
|
},
|
||||||
body: switch (tabSelection) {
|
);
|
||||||
0 => listAllFlowInfos(context, flowInfos!),
|
},
|
||||||
1 => listFlowInfoByProduced(context, flowInfos!),
|
child: const Icon(Icons.qr_code),
|
||||||
2 => listFlowInfoByDependant(context, flowInfos!),
|
),
|
||||||
3 => listFlowInfoByActive(context, flowInfos!),
|
));
|
||||||
_ => const Text("..."),
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,26 @@ class TransactionPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TransactionPageState extends State<TransactionPage> {
|
class _TransactionPageState extends State<TransactionPage> {
|
||||||
|
late Transaction transaction;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
transaction = widget.transaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> reload() async {
|
||||||
|
if (widget.refresh != null) {
|
||||||
|
widget.refresh!();
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateTransaction = await API().getTransaction(transaction.uuid);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
transaction = updateTransaction;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -102,56 +122,88 @@ class _TransactionPageState extends State<TransactionPage> {
|
||||||
icon: const Icon(Icons.move_up))
|
icon: const Icon(Icons.move_up))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Padding(
|
||||||
children: [
|
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
||||||
Text("UUID: ${widget.transaction.uuid}"),
|
child: Column(
|
||||||
QRCode(
|
children: [
|
||||||
data: widget.transaction.uuid,
|
Row(
|
||||||
size: 22,
|
children: [
|
||||||
semanticsLabel: "Transaction UUID",
|
QRCode(
|
||||||
),
|
data: transaction.uuid,
|
||||||
|
size: 128,
|
||||||
// todo : human names
|
eyeStyle: const QREyeStyle(color: Colors.white),
|
||||||
Text("${widget.transaction.item} - ${widget.transaction.variant}"),
|
dataModuleStyle: const QRDataModuleStyle(color: Colors.white),
|
||||||
|
semanticsLabel: "Transaction UUID",
|
||||||
Text("Added: ${tsFormat(widget.transaction.timestamp)}"),
|
),
|
||||||
|
const SizedBox(
|
||||||
if (widget.transaction.expired) const Text("Transaction is Expired!"),
|
width: 16.0,
|
||||||
|
),
|
||||||
IconText(Icons.money, widget.transaction.price.format(),
|
Column(
|
||||||
color: Colors.green),
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
if (widget.transaction.origin != null)
|
// todo : human names
|
||||||
IconText(Icons.store, widget.transaction.origin!,
|
Text(
|
||||||
color: Colors.blue),
|
"${transaction.item}",
|
||||||
|
style: const TextStyle(
|
||||||
if (widget.transaction.location != null)
|
fontWeight: FontWeight.bold, fontSize: 28),
|
||||||
IconText(Icons.location_city, widget.transaction.location!.name),
|
),
|
||||||
|
Text(
|
||||||
if (widget.transaction.note != null) Text(widget.transaction.note!),
|
"${transaction.variant}",
|
||||||
|
style: const TextStyle(
|
||||||
if (widget.transaction.consumed != null) ...[
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 20,
|
||||||
|
color: Colors.grey),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 8.0,
|
||||||
|
),
|
||||||
|
Text("Added: ${tsFormat(transaction.timestamp)}"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
Text(
|
const SizedBox(
|
||||||
"Consumed on: ${tsFormat(widget.transaction.consumed!.timestamp)}"),
|
height: 12.0,
|
||||||
IconText(Icons.store, widget.transaction.consumed!.destination,
|
),
|
||||||
color: Colors.blue),
|
|
||||||
IconText(Icons.money, widget.transaction.consumed!.price.format(),
|
|
||||||
color: Colors.green),
|
|
||||||
]
|
|
||||||
|
|
||||||
// todo : chart with price history
|
if (transaction.expired) const Text("Transaction is Expired!"),
|
||||||
],
|
|
||||||
|
IconText(Icons.money, transaction.price.format(),
|
||||||
|
color: Colors.green),
|
||||||
|
|
||||||
|
if (transaction.origin != null)
|
||||||
|
IconText(Icons.store, transaction.origin!, color: Colors.blue),
|
||||||
|
|
||||||
|
if (transaction.location != null)
|
||||||
|
IconText(Icons.location_city, transaction.location!.name),
|
||||||
|
|
||||||
|
if (transaction.note != null) Text(transaction.note!),
|
||||||
|
|
||||||
|
if (transaction.consumed != null) ...[
|
||||||
|
const Divider(),
|
||||||
|
Text("Consumed on: ${tsFormat(transaction.consumed!.timestamp)}"),
|
||||||
|
IconText(Icons.store, transaction.consumed!.destination,
|
||||||
|
color: Colors.blue),
|
||||||
|
IconText(Icons.money, transaction.consumed!.price.format(),
|
||||||
|
color: Colors.green),
|
||||||
|
]
|
||||||
|
|
||||||
|
// todo : chart with price history
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: transaction.consumed == null
|
||||||
onPressed: () {
|
? FloatingActionButton(
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
onPressed: () {
|
||||||
builder: (context) {
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
return ConsumePage(widget.transaction, widget.refresh ?? () {});
|
builder: (context) {
|
||||||
|
return ConsumePage(transaction, reload);
|
||||||
|
},
|
||||||
|
));
|
||||||
},
|
},
|
||||||
));
|
child: const Icon(Icons.receipt_long))
|
||||||
},
|
: null,
|
||||||
child: const Icon(Icons.receipt_long)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue