Skip to content

Commit

Permalink
Implemented Search Feature correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaymehrotra committed Feb 27, 2024
1 parent cdf431b commit f49deb4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 50 deletions.
90 changes: 42 additions & 48 deletions lib/ui/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,40 @@ import 'package:flutter_svg/svg.dart';

import 'view_all_page.dart';


class HomePage extends StatefulWidget {
HomePage({super.key});

@override
_HomePageState createState() => _HomePageState();

}
class _HomePageState extends State<HomePage> {

String address_locality="";
String address_country="";
class _HomePageState extends State<HomePage> {
String address_locality = "";
String address_country = "";

late LocationController _controller;
late locationModel lc;

@override
void initState(){

void initState() {
super.initState();
_controller=LocationController();
lc=locationModel(country: "", locality: "");
_controller = LocationController();
lc = locationModel(country: "", locality: "");
_updateLocation();
}

Future<void> _updateLocation() async{
try{
Future<void> _updateLocation() async {
try {
lc = await _controller.getCurrentLocation();
setState(() {
address_locality = lc.locality;
address_country = lc.country;
});
}catch(e){
} catch (e) {
print('Error updating location: $e');
setState(() {
address_locality="No address";
address_country="";
address_locality = "No address";
address_country = "";
});
}
}
Expand Down Expand Up @@ -96,16 +93,17 @@ class _HomePageState extends State<HomePage> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ViewAllPage(isPopularEvent: true,)),
builder: (context) => const ViewAllPage(
isPopularEvent: true,
)),
);
},
child: const Text(
"View All",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14,
color: AppColors.primaryColor
),
color: AppColors.primaryColor),
),
)
],
Expand All @@ -124,39 +122,41 @@ class _HomePageState extends State<HomePage> {
},
),
const SizedBox(height: 12),
Divider(height: 1,
endIndent: 16,
indent: 16,
thickness: 0.5,
color: Theme.of(context).disabledColor.withOpacity(0.1),
Divider(
height: 1,
endIndent: 16,
indent: 16,
thickness: 0.5,
color: Theme.of(context).disabledColor.withOpacity(0.1),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24,vertical: 12),
padding:
const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
"Event This Month",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
fontWeight: FontWeight.w600, fontSize: 18),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ViewAllPage(isPopularEvent: false,)),
builder: (context) => const ViewAllPage(
isPopularEvent: false,
)),
);
},
child: const Text(
"View All",
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 12,
color: AppColors.primaryColor
),
color: AppColors.primaryColor),
),
)
],
Expand Down Expand Up @@ -192,9 +192,9 @@ class _HomePageState extends State<HomePage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Image.asset(
'assets/images/location.png',
Row(children: [
Image.asset(
'assets/images/location.png',
width: 20,
),
const SizedBox(width: 8),
Expand All @@ -207,7 +207,7 @@ class _HomePageState extends State<HomePage> {
),
),
]),
const SizedBox(height: 8),
const SizedBox(height: 8),
Text(
address_locality,
style: const TextStyle(
Expand All @@ -218,7 +218,7 @@ class _HomePageState extends State<HomePage> {
],
),
),
const Spacer(),
const Spacer(),
GestureDetector(
onTap: () {
// Navigate to the specific page here
Expand Down Expand Up @@ -246,13 +246,13 @@ class _HomePageState extends State<HomePage> {
);

_buildSearch() => GestureDetector(
onTap: () {
Navigator.push(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const MySearchWidget()),
);
},
child: Container(
},
child: Container(
height: 48,
width: double.infinity,
margin: const EdgeInsets.symmetric(horizontal: 24),
Expand All @@ -268,14 +268,13 @@ class _HomePageState extends State<HomePage> {
const Text(
"Search event...",
style: TextStyle(
color: AppColors.greyTextColor,
fontWeight: FontWeight.w500
),
color: AppColors.greyTextColor,
fontWeight: FontWeight.w500),
)
],
),
),
);
);

_listPopularEvent(List<EventModel> events) => SizedBox(
width: MediaQuery.of(context).size.width,
Expand All @@ -284,13 +283,8 @@ class _HomePageState extends State<HomePage> {
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
autoplay: true,
pagination: const SwiperPagination(
alignment: Alignment.bottomCenter
),
control: const SwiperControl(
size: 0,
padding: EdgeInsets.all(0)
),
pagination: const SwiperPagination(alignment: Alignment.bottomCenter),
control: const SwiperControl(size: 0, padding: EdgeInsets.all(0)),
itemCount: events.length,
itemBuilder: (context, index) => GestureDetector(
onTap: () => Navigator.pushNamed(
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/widgets/search_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class _MySearchWidgetState extends State<MySearchWidget> {
context,
NamedRoutes.detailScreen)),
child: CardEventThisMonth(
eventModel: eventList[index],
eventModel: filteredList[index],
),
);
},
Expand All @@ -136,11 +136,12 @@ class _MySearchWidgetState extends State<MySearchWidget> {
List<EventModel> tempFilteredList = [];
for (var event in eventList) {
if (event.title.toLowerCase().contains(searchText.toLowerCase())) {
print(event.title.toLowerCase());
tempFilteredList.add(event);
}
}
setState(() {
filteredList = tempFilteredList; // Set the filtered list
filteredList = tempFilteredList; // Set the filtered
});
}
}
Expand Down

0 comments on commit f49deb4

Please sign in to comment.