2022-04-26 11:13:57 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
|
|
|
import 'package:nekoya_flutter/components/cart_box.dart';
|
|
|
|
import 'package:nekoya_flutter/data/cart.dart';
|
|
|
|
|
|
|
|
class Cart extends StatefulWidget {
|
|
|
|
const Cart({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Cart> createState() => _CartState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CartState extends State<Cart> {
|
2022-04-27 14:08:00 +02:00
|
|
|
Future<dynamic> _viewCart = viewCart();
|
|
|
|
|
2022-04-26 11:13:57 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Cart'),
|
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: const Color(0xff212226),
|
|
|
|
),
|
|
|
|
body: FutureBuilder<dynamic>(
|
2022-04-27 14:08:00 +02:00
|
|
|
future: _viewCart,
|
2022-04-26 11:13:57 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var data = snapshot.data;
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: data!.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return FutureBuilder<dynamic>(
|
|
|
|
future: getProduct(data[index]["product_id"]),
|
|
|
|
builder: (context, snapshotx) {
|
2022-04-27 08:19:22 +02:00
|
|
|
if (snapshotx.hasData) {
|
2022-04-26 11:13:57 +02:00
|
|
|
var productData = snapshotx.data;
|
|
|
|
if (productData != null) {
|
|
|
|
return CartBox(
|
2022-04-28 08:16:41 +02:00
|
|
|
controller: true,
|
2022-04-26 11:13:57 +02:00
|
|
|
imageUrl: 'https://nekoya.moe.team/img/' + productData[0]['IMAGE'],
|
|
|
|
title: productData[0]['TITLE'],
|
|
|
|
quantity: data[index]["quantity"],
|
|
|
|
plus: () {
|
|
|
|
addToCart(data[index]["product_id"]);
|
2022-04-27 14:08:00 +02:00
|
|
|
setState(() {
|
|
|
|
_viewCart = viewCart();
|
|
|
|
});
|
2022-04-26 11:13:57 +02:00
|
|
|
},
|
|
|
|
minus: () {
|
|
|
|
removeFromCart(data[index]["product_id"], false);
|
2022-04-27 14:08:00 +02:00
|
|
|
setState(() {
|
|
|
|
_viewCart = viewCart();
|
|
|
|
});
|
2022-04-26 11:13:57 +02:00
|
|
|
},
|
|
|
|
remove: () {
|
|
|
|
removeFromCart(data[index]["product_id"], true);
|
2022-04-27 14:08:00 +02:00
|
|
|
setState(() {
|
|
|
|
_viewCart = viewCart();
|
|
|
|
});
|
2022-04-26 11:13:57 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CartBox(
|
2022-04-28 08:16:41 +02:00
|
|
|
controller: true,
|
2022-04-26 11:13:57 +02:00
|
|
|
imageUrl: 'https://i.ibb.co/QJFLZC4/La-Darknesss-Portrait.webp',
|
|
|
|
title: 'Loading...',
|
|
|
|
quantity: 0,
|
|
|
|
plus: () {},
|
|
|
|
minus: () {},
|
|
|
|
remove: () {},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: Color(0xff8B0000),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|