homepage
homepage
dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:watch/Screens/addWatch.dart';
import 'package:watch/Screens/drawer.dart';
import 'package:watch/Screens/Details.dart';
import 'package:watch/Screens/favpage.dart';
import 'package:watch/Screens/profile.dart';
import 'package:watch/Screens/searchPage.dart';
@override
State<Home> createState() => _HomeState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.orange),
title: Center(
child: Text(
''کاتژمێر,
style: TextStyle(color: Colors.orange),
textAlign: TextAlign.center,
),
),
backgroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
actions: [
IconButton(
icon: Icon(
Icons.search,
color: Colors.orange,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SearchPage()),
);
},
),
],
),
body: SingleChildScrollView(
child: Column(
children: [
SizedBox(height: 10),
CarouselSlider(
options: CarouselOptions(
height: 200,
autoPlay: true,
enlargeCenterPage: true,
aspectRatio: 16 / 9,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 0.9,
),
items: [
'https://th.bing.com/th/id/OIP.D2TxOh929WgYZdXiEvmVRQAAAA?
rs=1&pid=ImgDetMain',
'https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/e08f4062816275.5a9d053b
e79b7.jpg',
'https://michaelspiers.co.uk/cdn/shop/files/MICHAEL_SPIRES_1792x700_SE27_1792x700_c
rop_center.jpg?v=1694529788',
'https://mir-s3-cdn-cf.behance.net/projects/max_808_webp/90b281172311715.Y3JvcCw4MT
MsNjM2LDc2LDEw.jpg',
].map((imageUrl) {
return Image.network(
imageUrl,
width: 400,
fit: BoxFit.fitHeight,
);
}).toList(),
),
SizedBox(height: 20),
_buildCategoryList(),
SizedBox(height: 20),
Container(
height: MediaQuery.of(context).size.height * 1,
child: buildItemsList(context),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const addwatch()));
},
child: const Icon(Icons.add, color: Colors.orange),
backgroundColor: Colors.black,
),
drawer: draweer(),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.black,
selectedItemColor: Colors.orange,
unselectedItemColor: Colors.white.withOpacity(0.5),
currentIndex: _selectedIndex,
onTap: (int index) {
setState(() {
_selectedIndex = index;
});
if (index == 0) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Home()),
);
}
if (index == 1) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => favPage()),
);
}
if (index == 2) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProfilePage()),
);
}
},
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: ')'سەرەکی,
BottomNavigationBarItem(
icon: Icon(Icons.favorite), label: ')'دڵخوازەکان,
BottomNavigationBarItem(icon: Icon(Icons.person), label: ')'پرۆفایل,
],
),
);
}
Future<QuerySnapshot> query;
if (filterByBrand) {
query = FirebaseFirestore.instance
.collection('Items')
.where('brand', isEqualTo: selectedBrand)
.get();
} else {
query = FirebaseFirestore.instance.collection('Items').get();
}
return FutureBuilder<QuerySnapshot>(
future: query.catchError((error) {
print('Error fetching data from Firebase: $error');
}),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (snapshot.hasData) {
final List<DocumentSnapshot> documents = snapshot.data!.docs;
return SingleChildScrollView(
child: Column(
children: documents.map((doc) {
final data = doc.data() as Map<String, dynamic>;
final String brand = data['brand'] ?? '';
final String price = '\$${data['price'] ?? ''}';
final bool isFav = data['isFav'] ?? false;
final String condition = data['condition'] ?? '';
final List<String> imageUrls =
List<String>.from(data['imageUrls'] ?? []);
final String imageUrl = imageUrls.isNotEmpty ? imageUrls[0] : '';
return Padding(
padding: EdgeInsets.all(8.0),
child: Card(
elevation: 15,
child: Column(
children: [
GestureDetector(
onTap: () {
showModalBottomSheet(
context: context,
builder: (BuildContext context) => Container(
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 15.0,
top: 55.0),
child: Column(
children: [
Image.network(
height: 250,
width: 250,
imageUrl,
loadingBuilder: (BuildContext context,
Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return child;
}
return Center(
child: CircularProgressIndicator(
value:
loadingProgress.expectedTotalBytes != null
?
loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (BuildContext context,
Object exception, StackTrace? stackTrace) {
print('Error loading image:
$exception' + 'Image URL: $imageUrl');
return Container(
color: Colors.red,
width: 270,
height: 270,
child: Center(
child: Text(
'No image available',
style: TextStyle(color:
Colors.white),
),
),
);
},
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
'$brand د:' ب را ن,
style: TextStyle(fontSize: 18),
),
SizedBox(height: 8),
Text(
'نرخ: \$$price',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 8),
Text(
' بار و دۆخ: $condition ',
style: TextStyle(fontSize: 16),
),
SizedBox(height: 8),
],
),
),
SizedBox(height: 16),
],
),
),
);
},
child: Row(
children: [
Column(
children: [
Container(
height: 200,
width: 200,
child: ClipRRect(
borderRadius: BorderRadius.vertical(
top: Radius.circular(8.0),
),
child: Image.network(
imageUrl,
fit: BoxFit.fitHeight,
loadingBuilder: (BuildContext context,
Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return child;
}
return Center(
child: CircularProgressIndicator(
value:
loadingProgress.expectedTotalBytes != null
?
loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (BuildContext context, Object
exception, StackTrace? stackTrace) {
print('Error loading image: $exception' +
'Image URL: $imageUrl');
return Container(
color: Colors.red,
width: double.infinity,
height: 200,
child: Center(
child: Text(
'No image available',
style: TextStyle(color:
Colors.white),
),
),
);
},
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(left: 18.0),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(
brand,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8),
Text(' نرخ: $price'),
Text(' بار و دۆخ: $condition'),
],
),
),
],
),
),
],
),
),
],
),
),
);
}).toList(),
),
);
} else {
return Center(child: Text('No data found.'));
}
},
);
}
Widget _buildAllCategoryList() {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: allItems
.asMap()
.entries
.map(
(entry) => GestureDetector(
onTap: () {
setState(() {
selectedCategoryIndex = entry.key;
});
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 8.0),
padding:
EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
decoration: BoxDecoration(
color: selectedCategoryIndex == entry.key
? Colors.orange
: Colors.black,
borderRadius: BorderRadius.circular(20.0),
),
child: Text(
entry.value,
style: TextStyle(
color: selectedCategoryIndex == entry.key
? Colors.black
: Colors.white,
),
),
),
),
)
.toList(),
),
);
}
Widget _buildCategoryList() {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: brands
.asMap()
.entries
.map(
(entry) => GestureDetector(
onTap: () {
setState(() {
selectedCategoryIndex = entry.key;
});
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 8.0),
padding:
EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
decoration: BoxDecoration(
color: selectedCategoryIndex == entry.key
? Colors.orange
: Colors.black,
borderRadius: BorderRadius.circular(20.0),
),
child: Text(
entry.value,
style: TextStyle(
color: selectedCategoryIndex == entry.key
? Colors.black
: Colors.white,
),
),
),
),
)
.toList(),
),
);
}