diff --git a/lib/ui/pages/home_page.dart b/lib/ui/pages/home_page.dart index add6cf0..d07973d 100644 --- a/lib/ui/pages/home_page.dart +++ b/lib/ui/pages/home_page.dart @@ -12,6 +12,7 @@ import 'package:event_app/ui/widgets/card_event_this_month.dart'; import 'package:event_app/ui/widgets/card_popular_event.dart'; import 'package:event_app/ui/widgets/custom_app_bar.dart'; import 'package:event_app/ui/widgets/my_navigation_bar.dart'; +import 'package:event_app/ui/widgets/search_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -19,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 { - String address_locality=""; - String address_country=""; +class _HomePageState extends State { + 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 _updateLocation() async{ - try{ + Future _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 = ""; }); } } @@ -95,7 +93,9 @@ class _HomePageState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => const ViewAllPage(isPopularEvent: true,)), + builder: (context) => const ViewAllPage( + isPopularEvent: true, + )), ); }, child: const Text( @@ -103,8 +103,7 @@ class _HomePageState extends State { style: TextStyle( fontWeight: FontWeight.w500, fontSize: 14, - color: AppColors.primaryColor - ), + color: AppColors.primaryColor), ), ) ], @@ -123,30 +122,33 @@ class _HomePageState extends State { }, ), 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( @@ -154,8 +156,7 @@ class _HomePageState extends State { style: TextStyle( fontWeight: FontWeight.w400, fontSize: 12, - color: AppColors.primaryColor - ), + color: AppColors.primaryColor), ), ) ], @@ -191,9 +192,9 @@ class _HomePageState extends State { 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), @@ -206,7 +207,7 @@ class _HomePageState extends State { ), ), ]), - const SizedBox(height: 8), + const SizedBox(height: 8), Text( address_locality, style: const TextStyle( @@ -217,7 +218,7 @@ class _HomePageState extends State { ], ), ), - const Spacer(), + const Spacer(), GestureDetector( onTap: () { // Navigate to the specific page here @@ -253,18 +254,25 @@ class _HomePageState extends State { borderRadius: BorderRadius.all(Radius.circular(50)), color: AppColors.greyLightColor, ), - child: Row( - children: [ - Image.asset('assets/images/search.png', width: 16), - const SizedBox(width: 8), - const Text( - "Search event...", - style: TextStyle( - color: AppColors.greyTextColor, - fontWeight: FontWeight.w500 - ), - ) - ], + child: GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => const MySearchWidget()), + ); + }, + child: Row( + children: [ + Image.asset('assets/images/search.png', width: 16), + const SizedBox(width: 8), + const Text( + "Search event...", + style: TextStyle( + color: AppColors.greyTextColor, + fontWeight: FontWeight.w500), + ) + ], + ), ), ); @@ -275,13 +283,8 @@ class _HomePageState extends State { 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( diff --git a/lib/ui/widgets/card_event_this_month.dart b/lib/ui/widgets/card_event_this_month.dart index d937a13..fae2d02 100644 --- a/lib/ui/widgets/card_event_this_month.dart +++ b/lib/ui/widgets/card_event_this_month.dart @@ -13,7 +13,7 @@ class CardEventThisMonth extends StatelessWidget { return Container( height: 95, margin: const EdgeInsets.only(bottom: 12), - padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8), decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: AppColors.whiteColor, diff --git a/lib/ui/widgets/search_widget.dart b/lib/ui/widgets/search_widget.dart new file mode 100644 index 0000000..5f36aa6 --- /dev/null +++ b/lib/ui/widgets/search_widget.dart @@ -0,0 +1,154 @@ +import 'dart:convert'; + +import 'package:event_app/app/resources/constant/named_routes.dart'; +import 'package:event_app/data/event_model.dart'; +import 'package:event_app/ui/widgets/card_event_this_month.dart'; +import 'package:flutter/material.dart'; + +void main() { + runApp(const MaterialApp( + debugShowCheckedModeBanner: false, + home: MySearchWidget(), + )); +} + +class MySearchWidget extends StatefulWidget { + const MySearchWidget({super.key}); + + @override + // ignore: library_private_types_in_public_api + _MySearchWidgetState createState() => _MySearchWidgetState(); +} + +class _MySearchWidgetState extends State { + String searchText = ''; + late List eventList; + List filteredList = []; + + @override + void initState() { + super.initState(); + _loadEvents().then((events) { + setState(() { + eventList = events; + }); + }).catchError((error) { + Error(); + }); + } + + @override + Widget build(BuildContext context) { + filterEvents(); // Call the function to filter events based on searchText + return SafeArea( + child: Scaffold( + body: Padding( + padding: const EdgeInsets.only(top: 15), + child: Column( + children: [ + Container( + height: 48, + width: double.infinity, + margin: const EdgeInsets.symmetric(horizontal: 24), + padding: const EdgeInsets.symmetric(horizontal: 16), + decoration: BoxDecoration( + borderRadius: const BorderRadius.all( + Radius.circular(24)), // Smaller radius + color: Colors.grey[200], // Light grey background + ), + child: Row( + children: [ + const Padding( + padding: EdgeInsets.all(8.0), + child: Icon(Icons.search, + color: Colors.grey), // Grey search icon + ), + const SizedBox(width: 8), + Expanded( + child: TextField( + onChanged: (text) { + setState(() { + searchText = text; + }); + }, + style: const TextStyle( + color: Colors.black, + fontWeight: FontWeight.w400, + ), + decoration: InputDecoration( + hintText: 'Search...', + hintStyle: TextStyle( + color: Colors.grey.withOpacity(0.5), + fontWeight: FontWeight.w400, + ), + border: InputBorder.none, + contentPadding: EdgeInsets.zero, + ), + ), + ), + IconButton( + icon: const Icon(Icons.clear, + color: Colors.grey), // Grey clear icon + onPressed: () { + setState(() { + searchText = ''; // Clear search text + Navigator.pop(context); + }); + }, + ), + ], + ), + ), + const SizedBox(height: 15), + const Text("Searched Result"), + const SizedBox(height: 15), + searchText != "" + ? Expanded( + child: ListView.builder( + itemCount: filteredList.length, + itemBuilder: (context, index) { + return GestureDetector( + onTap: (() => Navigator.pushNamed( + arguments: eventList[index].toJson(), + context, + NamedRoutes.detailScreen)), + child: CardEventThisMonth( + eventModel: filteredList[index], + ), + ); + }, + ), + ) + : const Center(child: Text("No Events")), + ], + ), + ), + ), + ); + } + + void filterEvents() { + if (searchText.isEmpty) { + setState(() { + filteredList = []; // If search text is empty, show an empty list + }); + } else { + List 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 + }); + } + } + + Future> _loadEvents() async { + String jsonString = await EventModel.getJson(); + List jsonList = json.decode(jsonString); + return jsonList.map((json) => EventModel.fromJson(json)).toList(); + } +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index f8476c9..32aadf6 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -4,6 +4,7 @@ import FlutterMacOS import Foundation + import geolocator_apple import path_provider_foundation diff --git a/pubspec.lock b/pubspec.lock index 8c6427e..dfc8070 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.17.2" crypto: dependency: transitive description: @@ -105,14 +105,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" - fixnum: - dependency: transitive - description: - name: fixnum - sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" - url: "https://pub.dev" - source: hosted - version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -196,10 +188,10 @@ packages: dependency: transitive description: name: geolocator_android - sha256: afe2393715372e3901f789422a8a527fd78cfd423783e721c7e9ae826b081ece + sha256: "06e37fa32392f69f133e166ef6b358a8b6afddbf4c418fc236988184cc115a49" url: "https://pub.dev" source: hosted - version: "4.5.1" + version: "4.4.1" geolocator_apple: dependency: transitive description: @@ -244,10 +236,10 @@ packages: dependency: transitive description: name: http - sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.1.0" http_parser: dependency: transitive description: @@ -292,10 +284,10 @@ packages: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.9.1" nested: dependency: transitive description: @@ -372,10 +364,10 @@ packages: dependency: transitive description: name: petitparser - sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750 url: "https://pub.dev" source: hosted - version: "6.0.2" + version: "5.4.0" platform: dependency: transitive description: @@ -433,18 +425,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.1" string_scanner: dependency: transitive description: @@ -473,10 +465,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.6.0" typed_data: dependency: transitive description: @@ -489,10 +481,10 @@ packages: dependency: transitive description: name: uuid - sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8 + sha256: "22c94e5ad1e75f9934b766b53c742572ee2677c56bc871d850a57dad0f82127f" url: "https://pub.dev" source: hosted - version: "4.3.3" + version: "4.2.2" vector_graphics: dependency: transitive description: @@ -529,18 +521,18 @@ packages: dependency: transitive description: name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "0.1.4-beta" win32: dependency: transitive description: name: win32 - sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8" + sha256: b0f37db61ba2f2e9b7a78a1caece0052564d1bc70668156cf3a29d676fe4e574 url: "https://pub.dev" source: hosted - version: "5.2.0" + version: "5.1.1" xdg_directories: dependency: transitive description: @@ -553,10 +545,10 @@ packages: dependency: transitive description: name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84" url: "https://pub.dev" source: hosted - version: "6.5.0" + version: "6.3.0" sdks: - dart: ">=3.2.2 <4.0.0" + dart: ">=3.1.0 <4.0.0" flutter: ">=3.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 4ea52b3..ea0942e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: ">=3.2.2 <4.0.0" + sdk: ">=3.1.0 <4.0.0" dependencies: flutter: