From 080afe70ee76560b095165ad01976342d01d6236 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 23 Sep 2024 20:19:30 +0200 Subject: [PATCH] refactor --- lib/api.dart | 6 +++--- lib/pages/expandable_list.dart | 10 +++++++++- lib/pages/flow.dart | 26 +++++++++++++------------- lib/pages/itemview.dart | 3 ++- lib/pages/transaction.dart | 22 ++++++++++++---------- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index e99b783..6a0f274 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -312,7 +312,7 @@ class FlowInfo { class Item { late String id; late String name; - late String category; + late String? category; late Map variants; Item(Map json) { @@ -367,7 +367,7 @@ class Transaction { late ConsumeInfo? consumed; late bool expired; late String? note; - late String? location; + late Location? location; Transaction(Map json) { uuid = json["uuid"]; @@ -379,7 +379,7 @@ class Transaction { expired = json["expired"]; note = json["note"]; consumed = json["consumed"] != null ? ConsumeInfo(json["consumed"]) : null; - location = json["location"]; + location = json["location"] != null ? Location(json["location"]) : null; } } diff --git a/lib/pages/expandable_list.dart b/lib/pages/expandable_list.dart index 69c917b..d8dd1eb 100644 --- a/lib/pages/expandable_list.dart +++ b/lib/pages/expandable_list.dart @@ -41,7 +41,15 @@ class _ExpandableListState extends State { children: widget.entries.map((ExpandableListItem item) { return ExpansionPanel( headerBuilder: (BuildContext context, bool isExpanded) { - return item.header; + return ListTile( + title: item.header, + onTap: () { + setState(() { + widget.entries.firstWhere((x) => x == item).isExpanded = + !isExpanded; + }); + }, + ); }, body: item.body, isExpanded: item.isExpanded, diff --git a/lib/pages/flow.dart b/lib/pages/flow.dart index 344ee39..67d0cfb 100644 --- a/lib/pages/flow.dart +++ b/lib/pages/flow.dart @@ -91,8 +91,7 @@ class _FlowsPageState extends State { children: producedMapping[key]!.map((x) { return flowTile(context, x); }).toList()); - items.add( - ExpandableListItem(body: flows, header: ListTile(title: Text(key)))); + items.add(ExpandableListItem(body: flows, header: Text(key))); } return ExpandableList(items); @@ -120,8 +119,7 @@ class _FlowsPageState extends State { children: dependsMapping[key]!.map((x) { return flowTile(context, x); }).toList()); - items.add( - ExpandableListItem(body: flows, header: ListTile(title: Text(key)))); + items.add(ExpandableListItem(body: flows, header: Text(key))); } return ExpandableList(items); @@ -209,15 +207,17 @@ class _FlowInfoPageState extends State { var data = snapshot.data!; - return ListView( - children: data - .map((x) => ListTile( - title: Text(x.id), - onTap: () => - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => ActiveFlowPage(x), - )))) - .toList()); + return Expanded( + child: ListView( + children: data + .map((x) => ListTile( + title: Text(x.id), + onTap: () => + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => ActiveFlowPage(x), + )))) + .toList()), + ); }, ) ], diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index f5aa4bc..2b1ebff 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -50,7 +50,8 @@ class _ItemViewState extends State { widget.item.name, style: const TextStyle(fontWeight: FontWeight.bold), ), - Text(widget.item.category), + if (widget.item.category != null) + Text(widget.item.category!), ], ) ], diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index dfd7512..cc1e691 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -22,6 +22,7 @@ class TransactionPage extends StatelessWidget { semanticsLabel: "Transaction UUID", ), + // todo : human names Text("${transaction.item} - ${transaction.variant}"), Text("Added: ${tsFormat(transaction.timestamp)}"), @@ -31,9 +32,11 @@ class TransactionPage extends StatelessWidget { IconText(Icons.money, transaction.price.format(), color: Colors.green), - IconText(Icons.store, transaction.origin!, color: Colors.blue), + if (transaction.origin != null) + IconText(Icons.store, transaction.origin!, color: Colors.blue), - IconText(Icons.location_city, transaction.location!), + if (transaction.location != null) + IconText(Icons.location_city, transaction.location!.name), if (transaction.note != null) Text(transaction.note!), @@ -134,16 +137,15 @@ class TransactionCard extends StatelessWidget { ), ], ), + if ((t.note ?? "").isNotEmpty) ...[ + const SizedBox( + height: 4, + ), + Text(t.note!) + ], const SizedBox( height: 10, ), - if ((t.note ?? "").isNotEmpty) ...[ - const SizedBox(height: 8), - Text(t.note!), - const SizedBox( - height: 10, - ) - ], IconText(Icons.money, "${t.price.value.toStringAsFixed(2)} ${t.price.currency}", color: Colors.green), @@ -155,7 +157,7 @@ class TransactionCard extends StatelessWidget { const SizedBox( height: 8, ), - IconText(Icons.location_city, t.location!) + IconText(Icons.location_city, t.location!.name) ] ], ),