fix api + ui

This commit is contained in:
JMARyA 2024-09-15 17:43:32 +02:00
parent 549df5ff22
commit b6a46673cf
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 68 additions and 56 deletions

View file

@ -32,22 +32,23 @@ class API {
Future<String> getRequest(String url) async { Future<String> getRequest(String url) async {
var resp = await http.get(Uri.parse(url), headers: <String, String>{ var resp = await http.get(Uri.parse(url), headers: <String, String>{
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json; charset=UTF-8',
'Token': pref.getString("token")! 'Token': pref.getString("token")!
}); });
return resp.body; return utf8.decode(resp.bodyBytes);
} }
Future<String> postRequest(String url, Map<String, dynamic> data) async { Future<String> postRequest(String url, Map<String, dynamic> data) async {
var resp = await http.post(Uri.parse(url), var resp = await http.post(Uri.parse(url),
headers: <String, String>{ headers: <String, String>{
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json', 'Content-Type': 'application/json; charset=UTF-8',
'Token': pref.getString("token")! 'Token': pref.getString("token")!
}, },
body: jsonEncode(data)); body: jsonEncode(data));
return resp.body; return utf8.decode(resp.bodyBytes);
} }
// /items // /items

View file

@ -25,10 +25,13 @@ class _ItemViewState extends State<ItemView> {
title: Text(widget.item.name), title: Text(widget.item.name),
), ),
body: Column(children: [ body: Column(children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 28),
child: Column(
children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
SizedBox(width: 28),
const Align( const Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Placeholder( child: Placeholder(
@ -50,8 +53,9 @@ class _ItemViewState extends State<ItemView> {
) )
], ],
), ),
const SizedBox(height: 10), const SizedBox(height: 18),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: widget.item.variants.entries.map((entry) { children: widget.item.variants.entries.map((entry) {
return Column(children: [ return Column(children: [
Text( Text(
@ -70,13 +74,20 @@ class _ItemViewState extends State<ItemView> {
return Column( return Column(
children: [ children: [
Text("Amount: ${stat.amount}"), Text("Amount: ${stat.amount}"),
Text("Total Cost: ${stat.total_price}") Text(
"Total Cost: ${stat.total_price.toStringAsFixed(2)}")
], ],
); );
}, },
) )
]); ]);
}).toList()), }).toList()),
SizedBox(
height: 12,
)
],
),
),
FutureBuilder( FutureBuilder(
future: API().getInventory(widget.item.id), future: API().getInventory(widget.item.id),
builder: (context, snapshot) { builder: (context, snapshot) {
@ -119,7 +130,7 @@ class TransactionCard extends StatelessWidget {
)); ));
}, },
child: Card( 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), margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
@ -144,7 +155,7 @@ class TransactionCard extends StatelessWidget {
), ),
Text( Text(
t.variant, 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), Icon(Icons.money, size: 18, color: Colors.green),
SizedBox(width: 6), SizedBox(width: 6),
Text( Text(
"${t.price.value} ${t.price.currency}", "${t.price.value.toStringAsFixed(2)} ${t.price.currency}",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
), ),
], ],