Add: Lazy loading and refresh on pull down
This commit is contained in:
@@ -4,6 +4,8 @@ import 'package:gymlink_module_web/components/basket_item_card.dart';
|
||||
import 'package:gymlink_module_web/components/heading.dart';
|
||||
import 'package:gymlink_module_web/pages/order_confirmation.dart';
|
||||
import 'package:gymlink_module_web/tools/prefs.dart';
|
||||
import 'package:gymlink_module_web/tools/routes.dart';
|
||||
import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
|
||||
|
||||
List<Map<String, dynamic>> cart = [
|
||||
{
|
||||
@@ -195,6 +197,12 @@ class _BasketPageState extends State<BasketPage> {
|
||||
return const SizedBox(height: 10);
|
||||
}
|
||||
|
||||
void _onLoad() async {
|
||||
await Future.delayed(const Duration(microseconds: 1000));
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -212,7 +220,7 @@ class _BasketPageState extends State<BasketPage> {
|
||||
style: Theme.of(context).textTheme.bodyLarge),
|
||||
const SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
shape: const RoundedRectangleBorder(
|
||||
@@ -232,24 +240,28 @@ class _BasketPageState extends State<BasketPage> {
|
||||
context: context,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: cartItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = cartItems[index];
|
||||
return BasketItemCard(
|
||||
name: item['name'],
|
||||
price: item['price'],
|
||||
id: item['id'],
|
||||
image: Image(
|
||||
image: AssetImage('assets/${item['image']}'),
|
||||
width: 50,
|
||||
),
|
||||
onTapPlus: () => addItem(item['id'].toString()),
|
||||
onTapMinus: () =>
|
||||
removeItem(item['id'].toString()),
|
||||
quantity: item['count'].toString(),
|
||||
);
|
||||
},
|
||||
child: LazyLoadScrollView(
|
||||
onEndOfPage: _onLoad,
|
||||
child: ListView.builder(
|
||||
itemCount: cartItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = cartItems[index];
|
||||
return BasketItemCard(
|
||||
name: item['name'],
|
||||
price: item['price'],
|
||||
id: item['id'],
|
||||
image: Image(
|
||||
image: AssetImage('assets/${item['image']}'),
|
||||
width: 50,
|
||||
),
|
||||
onTapPlus: () => addItem(item['id'].toString()),
|
||||
onTapMinus: () {
|
||||
removeItem(item['id'].toString());
|
||||
},
|
||||
quantity: item['count'].toString(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildSpacer(),
|
||||
@@ -263,7 +275,7 @@ class _BasketPageState extends State<BasketPage> {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
CustomPageRoute(
|
||||
builder: (context) =>
|
||||
const OrderConfirmationPage(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user