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 {
var resp = await http.get(Uri.parse(url), headers: <String, String>{
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json; charset=UTF-8',
'Token': pref.getString("token")!
});
return resp.body;
return utf8.decode(resp.bodyBytes);
}
Future<String> postRequest(String url, Map<String, dynamic> data) async {
var resp = await http.post(Uri.parse(url),
headers: <String, String>{
'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

View file

@ -25,58 +25,69 @@ class _ItemViewState extends State<ItemView> {
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),
),
],