2022-04-22 22:08:59 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-29 12:40:41 +02:00
|
|
|
|
2023-09-22 09:29:07 +02:00
|
|
|
import 'package:nekoya_app/api/api.dart';
|
|
|
|
import 'package:nekoya_app/components/product_box.dart';
|
|
|
|
import 'package:nekoya_app/components/product_detail.dart';
|
|
|
|
import 'package:nekoya_app/utils/utils.dart'
|
2022-05-25 16:14:08 +02:00
|
|
|
show kMobileBreakpoint, kTabletBreakpoint, kDesktopBreakPoint;
|
2022-04-22 22:08:59 +02:00
|
|
|
|
|
|
|
class Products extends StatefulWidget {
|
|
|
|
const Products({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Products> createState() => _ProductsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ProductsState extends State<Products> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-04-22 22:48:59 +02:00
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
2022-04-22 22:08:59 +02:00
|
|
|
appBar: AppBar(
|
2022-05-22 16:26:16 +02:00
|
|
|
title: const Text('Products'),
|
2022-04-22 22:23:28 +02:00
|
|
|
centerTitle: true,
|
2022-04-22 22:48:59 +02:00
|
|
|
backgroundColor: const Color(0xff212226),
|
2022-05-16 03:34:33 +02:00
|
|
|
automaticallyImplyLeading: false,
|
2022-04-22 22:08:59 +02:00
|
|
|
),
|
2022-05-25 16:14:08 +02:00
|
|
|
body: LayoutBuilder(builder: (context, dimension) {
|
|
|
|
int gridCount = 2;
|
|
|
|
double fontSize = 14.0;
|
2022-05-13 06:11:14 +02:00
|
|
|
|
2022-05-25 16:14:08 +02:00
|
|
|
if (dimension.maxWidth <= kMobileBreakpoint) {
|
|
|
|
gridCount = 2;
|
|
|
|
fontSize = 14.0;
|
|
|
|
} else if (dimension.maxWidth > kMobileBreakpoint &&
|
|
|
|
dimension.maxWidth <= kTabletBreakpoint) {
|
|
|
|
gridCount = 4;
|
|
|
|
fontSize = 15.0;
|
|
|
|
} else if (dimension.maxWidth > kTabletBreakpoint &&
|
|
|
|
dimension.maxWidth <= kDesktopBreakPoint) {
|
|
|
|
gridCount = 5;
|
|
|
|
fontSize = 10.0;
|
|
|
|
} else {
|
|
|
|
gridCount = 6;
|
|
|
|
fontSize = 10.0;
|
|
|
|
}
|
2022-05-13 06:11:14 +02:00
|
|
|
|
2022-05-25 16:14:08 +02:00
|
|
|
return FutureBuilder<dynamic>(
|
|
|
|
future: getProducts(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
var data = snapshot.data;
|
|
|
|
return GridView.count(
|
|
|
|
crossAxisCount: gridCount,
|
|
|
|
children: List.generate(data!.length, (index) {
|
|
|
|
return ProductBox(
|
|
|
|
imageUrl:
|
|
|
|
"https://nekoya.moe.team/img/${data[index]['IMAGE']}",
|
|
|
|
title: data[index]['TITLE'],
|
2023-11-09 17:48:59 +01:00
|
|
|
discount: data[index]['DISCOUNT'],
|
2022-05-25 16:14:08 +02:00
|
|
|
fontSize: fontSize,
|
|
|
|
callback: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
productDetail(context, data[index]['ID']),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
2022-05-13 06:11:14 +02:00
|
|
|
);
|
2022-05-25 16:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: Color(0xff8B0000),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
2022-04-22 22:08:59 +02:00
|
|
|
);
|
|
|
|
}
|
2022-05-25 16:14:08 +02:00
|
|
|
}
|