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,58 +25,69 @@ class _ItemViewState extends State<ItemView> {
title: Text(widget.item.name), title: Text(widget.item.name),
), ),
body: Column(children: [ body: Column(children: [
Row( Padding(
mainAxisAlignment: MainAxisAlignment.start, padding: EdgeInsets.symmetric(horizontal: 28),
children: [ child: Column(
SizedBox(width: 28), children: [
const Align( Row(
alignment: Alignment.centerLeft, mainAxisAlignment: MainAxisAlignment.start,
child: Placeholder( children: [
fallbackWidth: 100, const Align(
fallbackHeight: 100, 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 const SizedBox(height: 18),
SizedBox( Row(
width: 16.0, mainAxisAlignment: MainAxisAlignment.spaceBetween,
), children: widget.item.variants.entries.map((entry) {
Column( return Column(children: [
children: [ Text(
Text( entry.value.name,
widget.item.name, style: TextStyle(fontWeight: FontWeight.bold),
style: const TextStyle(fontWeight: FontWeight.bold), ),
), FutureBuilder(
Text(widget.item.category), 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( 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),
), ),
], ],