Completed Offer with Flexi Card Screen
This commit is contained in:
75
lib/offer_section/bloc/search_offers_listing_bloc.dart
Normal file
75
lib/offer_section/bloc/search_offers_listing_bloc.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
// ----- Events -----
|
||||
abstract class OffersEvent {}
|
||||
|
||||
class LoadOffers extends OffersEvent {}
|
||||
|
||||
class SearchOffers extends OffersEvent {
|
||||
final String query;
|
||||
SearchOffers(this.query);
|
||||
}
|
||||
|
||||
// ----- State -----
|
||||
class OffersState {
|
||||
final List<Map<String, String>> offers;
|
||||
const OffersState(this.offers);
|
||||
}
|
||||
|
||||
// ----- Bloc -----
|
||||
class OffersBloc extends Bloc<OffersEvent, OffersState> {
|
||||
OffersBloc() : super(const OffersState([])) {
|
||||
on<LoadOffers>(_onLoadOffers);
|
||||
on<SearchOffers>(_onSearchOffers);
|
||||
}
|
||||
|
||||
final List<Map<String, String>> _allOffers = [
|
||||
{
|
||||
"image": "assets/images/aa1.png",
|
||||
"title": "Astor Hotels Ultra Deluxe",
|
||||
"description": "15% Discount on all treatments for first-time clients"
|
||||
},
|
||||
{
|
||||
"image": "assets/images/aa2.png",
|
||||
"title": "Green Valley Spa Lux",
|
||||
"description": "20% off on spa memberships and treatments"
|
||||
},
|
||||
{
|
||||
"image": "assets/images/aa3.png",
|
||||
"title": "Ocean Breeze Resort",
|
||||
"description": "Complimentary breakfast with every booking for first-time guests"
|
||||
},
|
||||
{
|
||||
"image": "assets/images/aa4.png",
|
||||
"title": "Mountain Retreat of Light",
|
||||
"description": "10% Discount on group bookings of 5 or more guests"
|
||||
},
|
||||
{
|
||||
"image": "assets/images/card_banner.png",
|
||||
"title": "Mountain View Retreat",
|
||||
"description": "Free hiking gear rental for all visitors during their stay"
|
||||
},
|
||||
{
|
||||
"image": "assets/images/city_germany.jpg",
|
||||
"title": "Sunny Shores Hotel",
|
||||
"description": "10% Discount on group bookings of 5 or more guests"
|
||||
},
|
||||
|
||||
|
||||
];
|
||||
|
||||
void _onLoadOffers(event,emit) {
|
||||
emit(OffersState(_allOffers));
|
||||
}
|
||||
|
||||
void _onSearchOffers(event,emit) {
|
||||
final filtered = _allOffers
|
||||
.where((offer) =>
|
||||
offer["title"]!.toLowerCase().contains(event.query.toLowerCase()) ||
|
||||
offer["description"]!
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase()))
|
||||
.toList();
|
||||
emit(OffersState(filtered));
|
||||
}
|
||||
}
|
||||
152
lib/offer_section/view/search_offers_with_listing.dart
Normal file
152
lib/offer_section/view/search_offers_with_listing.dart
Normal file
@@ -0,0 +1,152 @@
|
||||
import 'package:citycards_customer/common_packages/app_bar.dart';
|
||||
import 'package:citycards_customer/common_packages/custom_search_field.dart';
|
||||
import 'package:citycards_customer/common_packages/custom_text.dart';
|
||||
import 'package:citycards_customer/offer_section/bloc/search_offers_listing_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class SearchOffersWithListing extends StatelessWidget {
|
||||
SearchOffersWithListing({super.key});
|
||||
|
||||
final List<String> category = ["Beach", "Hike", "Popular", "Best in Summer"];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => OffersBloc()..add(LoadOffers()),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
CommonAppBar(isWhiteLogo: false, isProfilePage: false,showCart: false,),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.arrow_back),
|
||||
SizedBox(width: 8.w),
|
||||
CustomText(text: "Offers with Flexi Card", size: 12.sp),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 33.h),
|
||||
|
||||
Builder(
|
||||
builder: (context) => CommonSearchField(
|
||||
hint: "Search offers",
|
||||
hintColor: const Color(0xFFF95F62).withOpacity(.6),
|
||||
showSuffix: true,
|
||||
onChanged: (value) {
|
||||
context.read<OffersBloc>().add(SearchOffers(value));
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 20.h),
|
||||
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
|
||||
child: Row(
|
||||
children: [
|
||||
...List.generate(category.length, (index) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: 8.0.w),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 6.h,
|
||||
horizontal: 12.w,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFFEE7E7),
|
||||
borderRadius: BorderRadius.circular(100.sp),
|
||||
border: Border.all(color: Color(0xFFFDCDCE)),
|
||||
),
|
||||
child: Center(
|
||||
child: CustomText(text: category[index]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 20.h),
|
||||
|
||||
/// Offer list
|
||||
Expanded(
|
||||
child: BlocBuilder<OffersBloc, OffersState>(
|
||||
builder: (context, state) {
|
||||
final offers = state.offers;
|
||||
|
||||
if (offers.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
"No offers found",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 16.w,
|
||||
mainAxisSpacing: 22.h,
|
||||
childAspectRatio: 0.65,
|
||||
),
|
||||
itemCount: offers.length,
|
||||
itemBuilder: (context, index) {
|
||||
final offer = offers[index];
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 6.w,
|
||||
vertical: 6.h,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Color(0xFFF95F62).withOpacity(.24),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12.sp),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.sp),
|
||||
child: Image.asset(
|
||||
offer["image"] ?? "",
|
||||
width: double.infinity,
|
||||
height: 120.5.h,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8.h),
|
||||
CustomText(
|
||||
text: offer["title"] ?? "",
|
||||
size: 18.sp,
|
||||
),
|
||||
SizedBox(height: 8.h),
|
||||
CustomText(
|
||||
text: offer["description"] ?? "",
|
||||
color: Colors.black.withOpacity(.6),
|
||||
size: 12.sp,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user