From b6a46673cfa2325b9f79ec0f49638adbf975b15e Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 15 Sep 2024 17:43:32 +0200 Subject: [PATCH] fix api + ui --- lib/api.dart | 7 +-- lib/pages/itemview.dart | 117 ++++++++++++++++++++++------------------ 2 files changed, 68 insertions(+), 56 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 094f885..8c4c05f 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -32,22 +32,23 @@ class API { Future getRequest(String url) async { var resp = await http.get(Uri.parse(url), headers: { 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json; charset=UTF-8', 'Token': pref.getString("token")! }); - return resp.body; + return utf8.decode(resp.bodyBytes); } Future postRequest(String url, Map data) async { var resp = await http.post(Uri.parse(url), headers: { 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Content-Type': 'application/json; charset=UTF-8', 'Token': pref.getString("token")! }, body: jsonEncode(data)); - return resp.body; + return utf8.decode(resp.bodyBytes); } // /items diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index 5503716..147a3cb 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -25,58 +25,69 @@ class _ItemViewState extends State { title: Text(widget.item.name), ), body: Column(children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox(width: 28), - const Align( - alignment: Alignment.centerLeft, - child: Placeholder( - fallbackWidth: 100, - fallbackHeight: 100, + Padding( + padding: EdgeInsets.symmetric(horizontal: 28), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Align( + alignment: Alignment.centerLeft, + child: Placeholder( + fallbackWidth: 100, + fallbackHeight: 100, + ), + ), // todo + SizedBox( + width: 16.0, + ), + Column( + children: [ + Text( + widget.item.name, + style: const TextStyle(fontWeight: FontWeight.bold), + ), + Text(widget.item.category), + ], + ) + ], ), - ), // todo - SizedBox( - width: 16.0, - ), - Column( - children: [ - Text( - widget.item.name, - style: const TextStyle(fontWeight: FontWeight.bold), - ), - Text(widget.item.category), - ], - ) - ], + const SizedBox(height: 18), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: widget.item.variants.entries.map((entry) { + return Column(children: [ + Text( + entry.value.name, + style: TextStyle(fontWeight: FontWeight.bold), + ), + FutureBuilder( + future: API().getStat(widget.item.id, entry.key), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return CircularProgressIndicator(); + } + + var stat = snapshot.data!; + + return Column( + children: [ + Text("Amount: ${stat.amount}"), + Text( + "Total Cost: ${stat.total_price.toStringAsFixed(2)}") + ], + ); + }, + ) + ]); + }).toList()), + SizedBox( + height: 12, + ) + ], + ), ), - const SizedBox(height: 10), - Row( - children: widget.item.variants.entries.map((entry) { - return Column(children: [ - Text( - entry.value.name, - style: TextStyle(fontWeight: FontWeight.bold), - ), - FutureBuilder( - future: API().getStat(widget.item.id, entry.key), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return CircularProgressIndicator(); - } - - var stat = snapshot.data!; - - return Column( - children: [ - Text("Amount: ${stat.amount}"), - Text("Total Cost: ${stat.total_price}") - ], - ); - }, - ) - ]); - }).toList()), FutureBuilder( future: API().getInventory(widget.item.id), builder: (context, snapshot) { @@ -119,7 +130,7 @@ class TransactionCard extends StatelessWidget { )); }, child: Card( - color: t.expired ? Colors.red[100] : Colors.white, + color: t.expired ? Colors.red[100] : Colors.black, margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), @@ -144,7 +155,7 @@ class TransactionCard extends StatelessWidget { ), Text( t.variant, - style: TextStyle(fontSize: 14, color: Colors.grey[600]), + style: TextStyle(fontSize: 14, color: Colors.grey[400]), ), ], ), @@ -162,7 +173,7 @@ class TransactionCard extends StatelessWidget { Icon(Icons.money, size: 18, color: Colors.green), SizedBox(width: 6), Text( - "${t.price.value} ${t.price.currency}", + "${t.price.value.toStringAsFixed(2)} ${t.price.currency}", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ],