0% found this document useful (0 votes)
4 views5 pages

Descri Ve

The document contains a Flutter code snippet for a shopping application screen that displays products categorized under 'Home', 'Kitchen', and 'Office'. It utilizes Firebase Firestore to fetch product data and includes features like a search button, a cart icon with item count, and a grid view for product display. The screen allows users to navigate to product details and manage their cart with appropriate notifications.

Uploaded by

chrismangala11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Descri Ve

The document contains a Flutter code snippet for a shopping application screen that displays products categorized under 'Home', 'Kitchen', and 'Office'. It utilizes Firebase Firestore to fetch product data and includes features like a search button, a cart icon with item count, and a grid view for product display. The screen allows users to navigate to product details and manage their cart with appropriate notifications.

Uploaded by

chrismangala11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Merci pour cette première partie du code !

Lorsque tu es prêt à partager la partie suivante, je


suis tout ouïe. Une fois toutes les parties reçues et que tu m'indiques "c'est fini", je
commencerai l'analyse.

parti 1 :import
'package:cheki/Cheki/Shopping/nav_screens/categorySubSubHKO_screen.dart'; import
'package:cheki/Cheki/Shopping/nav_screens/search_screen.dart'; import
'package:cheki/Cheki/Shopping/product_screens/cart_screen.dart'; import
'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import
'package:provider/provider.dart'; import
'package:cheki/Cheki/Shopping/product_screens/product_detail_screen.dart'; import
'package:fluttertoast/fluttertoast.dart';

class CategorySubHKOScreen extends StatelessWidget { final String selectedCategory;

CategorySubHKOScreen({required this.selectedCategory});

@override Widget build(BuildContext context) { final cart = Provider.of(context); final


cartItems = cart.getItems();

final Stream<QuerySnapshot<Map<String, dynamic>>> _homeStream =


FirebaseFirestore.instance
.collection('subcategoriesHKO')
.where('categoryName', isEqualTo: selectedCategory)
.where('listing', isEqualTo: 'Home')
.snapshots();

final Stream<QuerySnapshot<Map<String, dynamic>>> _kitchenStream =


FirebaseFirestore.instance
.collection('subcategoriesHKO')
.where('categoryName', isEqualTo: selectedCategory)
.where('listing', isEqualTo: 'Kitchen')
.snapshots();

final Stream<QuerySnapshot<Map<String, dynamic>>> _officeStream =


FirebaseFirestore.instance
.collection('subcategoriesHKO')
.where('categoryName', isEqualTo: selectedCategory)
.where('listing', isEqualTo: 'Office')
.snapshots();

final Stream<QuerySnapshot> _productsStream = FirebaseFirestore.instance


.collection('products')
.where('category', isEqualTo: selectedCategory)
.where('approved', isEqualTo: true)
.snapshots();

return Scaffold(
backgroundColor: Color(0xfff5f5f5),
appBar: AppBar(
elevation: 0,
title: Text(
selectedCategory,
style: TextStyle(
color: Colors.red,
),
),
actions: [
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext c) => SearchScreen(),
),
);
},
icon: Icon(Icons.search_rounded),
),
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (BuildContext c) => CartScreen()),
);
},
icon: Stack(
children: [
Icon(Icons.shopping_cart_outlined),
if (cartItems.isNotEmpty)
Positioned(
right: 0,
top: 0,
child: Container(
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: Color(0xfff35f4c),
borderRadius: BorderRadius.circular(10),
),
constraints: BoxConstraints(
minWidth: 16,
minHeight: 16,
),
child: Text(
cartItems.length.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 10,
),
textAlign: TextAlign.center,
),
),
),
],
),
),
],
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10),
buildCategorySection('HOME', _homeStream),
SizedBox(height: 10),
buildCategorySection('KITCHEN', _kitchenStream),
SizedBox(height: 10),
buildCategorySection('OFFICE', _officeStream),
SizedBox(height: 10),
StreamBuilder<QuerySnapshot>(
stream: _productsStream,
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Center(child: Text('Something went wrong'));
}

if (snapshot.connectionState == ConnectionState.waiting) {
return SizedBox.shrink();
}

return Padding(
padding: const EdgeInsets.all(8.0),
child: GridView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: snapshot.data!.size,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 2,
crossAxisSpacing: 2,
childAspectRatio: 175 / 300,
),
itemBuilder: (context, index) {
final productData = snapshot.data!.docs[index];
return GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return ProductDetailScreen(
productData: productData,
);
}));
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
color: Colors.white,
child: Column(
children: [
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
topRight: Radius.circular(4.0),
),
child: Container(
height: 175,
width: 175,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
productData['imageUrl'][0],
),
fit: BoxFit.cover,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 5.0, bottom: 5, left: 8.0, right:
8.0),
child: Align(
alignment: Alignment.topLeft,
child: Text(
productData['productName'],
style: TextStyle(
fontSize: 12,
color: Colors.black,
),
softWrap: false,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 5.0, bottom: 5, left: 8.0, right:
8.0),
child: Align(
alignment: Alignment.topLeft,
child: Text(
'TL' +
" " +
productData['productPrice']
.toStringAsFixed(2),
style: TextStyle(
fontSize: 15,
color: Color(0xff3db93b),
fontWeight: FontWeight.bold,
),
),
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
if (cart.containsProduct(
productData['productId'])) {
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(
content: Text(
'Item is already in cart'),
duration: Duration(seconds: 1),
),
);
} else if (productData['category'] ==
'Fashion' &&
productData['sizeList'] != null) {
List<String> selectedSizes = [];

showModalBottomSheet(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return Column(
children: <Widget>[
Container(
child: Padding(
padding:
const EdgeInsets
.only(
top: 10.0,
bottom: 10,
left: 16.0,
right: 16.0),

You might also like