pagination

This commit is contained in:
2025-02-14 18:52:46 +05:30
parent 9874c094a9
commit e3b601ee7d
9 changed files with 504 additions and 191 deletions

View File

@@ -14,6 +14,7 @@ import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
import 'package:shimmer/shimmer.dart';
class BestDealScreen extends StatefulWidget {
const BestDealScreen({super.key});
@@ -23,10 +24,12 @@ class BestDealScreen extends StatefulWidget {
}
class _BestDealScreenState extends State<BestDealScreen> {
bool _isSearching = false;
TextEditingController _searchController = TextEditingController();
@override
void initState() {
Provider.of<ProductProvider>(context, listen: false)
.getBestDealProduct(context);
.getBestDealProduct(context, '');
super.initState();
}
@@ -56,31 +59,69 @@ class _BestDealScreenState extends State<BestDealScreen> {
height: 20,
width: 20,
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: SvgPicture.asset(
APPASSETS.back,
height: 20,
width: 20,
)),
),
),
title: const Text(
"Best Deal",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
actions: [
InkWell(
onTap: () {},
child: Icon(
MdiIcons.magnify,
size: 35,
onTap: () {
Navigator.of(context).pop();
},
child: SvgPicture.asset(
APPASSETS.back,
height: 20,
width: 20,
),
),
)
),
),
title: _isSearching
? TextField(
controller: _searchController,
autofocus: true, // Focus on search field when opened
decoration: InputDecoration(
hintText: "Search...",
border: InputBorder.none,
),
style: TextStyle(fontSize: 18),
onChanged: (query) {
// You can call a search function here
},
)
: const Text(
"Best Deal",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
actions: [
if (_isSearching) // Show search icon only when searching
InkWell(
onTap: () {
Provider.of<ProductProvider>(context, listen: false)
.getBestDealProduct(context, _searchController.text);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
MdiIcons.magnify,
size: 35,
),
),
),
InkWell(
onTap: () {
setState(() {
_isSearching = !_isSearching;
if (!_isSearching) {
_searchController.clear(); // Clear search when closed
}
});
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
_isSearching ? Icons.close : MdiIcons.magnify,
size: 35,
),
),
),
],
),
floatingActionButton: floatingAction(),
@@ -180,11 +221,68 @@ class _BestDealScreenState extends State<BestDealScreen> {
Widget itemBestdeal() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isBestdealingloading) {
return Center(child: CircularProgressIndicator());
return Padding(
padding: const EdgeInsets.all(15),
child: GridView.builder(
itemCount: 6, // Number of shimmer items
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.5),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
return Shimmer.fromColors(
baseColor: Colors.grey[300]!,
highlightColor: Colors.grey[100]!,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
),
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.15,
width: MediaQuery.of(context).size.width * 0.4,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(15),
),
),
SizedBox(height: 8),
Container(
height: 10,
width: MediaQuery.of(context).size.width * 0.35,
color: Colors.grey[300],
),
SizedBox(height: 5),
Container(
height: 10,
width: MediaQuery.of(context).size.width * 0.25,
color: Colors.grey[300],
),
SizedBox(height: 10),
Container(
height: 15,
width: MediaQuery.of(context).size.width * 0.3,
color: Colors.grey[300],
),
],
),
),
),
);
},
),
);
} else if (provider.bestdeal.isEmpty) {
return Center(child: Text('No products available'));
} else {
print("kjhfgjkdfkjghdhjfgk ${provider.bestdeal.first.additionalInfo}");
return Padding(
padding: const EdgeInsets.all(15),
child: GridView.builder(
@@ -380,6 +478,75 @@ class _BestDealScreenState extends State<BestDealScreen> {
},
),
);
// Padding(
// padding: const EdgeInsets.all(15),
// child: GridView.builder(
// itemCount: provider.bestdeal.length,
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 2,
// childAspectRatio: MediaQuery.of(context).size.width /
// (MediaQuery.of(context).size.height / 1.5),
// crossAxisSpacing: 10,
// mainAxisSpacing: 10,
// ),
// itemBuilder: (context, index) {
// var bestdealproduct = provider.bestdeal[index];
// return InkWell(
// onTap: () {
// context.push(MyRoutes.PRODUCTDETAILS,
// extra: bestdealproduct.id);
// },
// child: Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15),
// ),
// child: Padding(
// padding: const EdgeInsets.all(5),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Container(
// height: MediaQuery.of(context).size.height * 0.15,
// width: MediaQuery.of(context).size.width * 0.4,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(15),
// ),
// child: AppNetworkImage(
// height: MediaQuery.of(context).size.height * 0.13,
// width: MediaQuery.of(context).size.width * 0.35,
// imageUrl:
// bestdealproduct.productImages?.first.url ?? "",
// backGroundColor: Colors.transparent,
// ),
// ),
// SizedBox(height: 8),
// Text(bestdealproduct.name ?? ""),
// Text(bestdealproduct.unit ?? ""),
// Text(bestdealproduct.quantity > 0
// ? "In Stock"
// : "Out of Stock"),
// Row(
// children: [
// Text("₹${bestdealproduct.discountPrice ?? ""}"),
// Text(
// "₹${bestdealproduct.basePrice ?? ""}",
// style: TextStyle(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// ),
// ],
// ),
// ),
// ),
// );
// },
// ),
// );
}
});
}