Files
CityCards_Customer_Flutter/lib/postcard/widgets/purchase_details_bottom_sheet.dart
2026-02-05 12:07:33 +05:30

258 lines
12 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../checkout/bloc/pass_purchase_details_bloc.dart';
import '../../checkout/bloc/pass_purchase_details_event.dart';
import '../../checkout/bloc/pass_purchase_details_state.dart';
import '../../profile/view/edit_profile/edit_profile_view.dart';
import '../blocs/postcard_creation_bloc.dart';
import '../blocs/postcard_creation_events.dart';
import '../blocs/postcard_creation_state.dart';
class PurchaseDetailsBottomSheet {
static void show(BuildContext context) {
final existingBloc = BlocProvider.of<PostcardCreationBloc>(context);
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (BuildContext modalContext) {
return MultiBlocProvider(
providers: [
BlocProvider.value(value: existingBloc),
BlocProvider(
create: (_) => PurchaseDetailsBloc()..add(LoadProfileEvent()),
),
],
child: BlocBuilder<PostcardCreationBloc, PostcardCreationState>(
builder: (context, postcardState) {
final postcardBloc = context.read<PostcardCreationBloc>();
return BlocBuilder<PurchaseDetailsBloc, PurchaseDetailsState>(
builder: (context, purchaseState) {
final purchaseBloc = context.read<PurchaseDetailsBloc>();
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
top: 16,
left: 16,
right: 16,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 45,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadius.circular(10),
),
),
const SizedBox(height: 12),
Text(
"Purchase Details",
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 24),
// 🟥 Option 1: Buy Postcard for Myself
GestureDetector(
onTap: () {
postcardBloc.add(TogglePurchaseOption(false));
purchaseBloc.add(ToggleGiftModeEvent(false));
},
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: !postcardState.isGift
? const Color(0xffF95F62)
: const Color(0xffE0E0E0),
width: 1.5,
),
),
child: Row(
children: [
Radio<bool>(
value: false,
groupValue: postcardState.isGift,
onChanged: (_) {
postcardBloc.add(TogglePurchaseOption(false));
purchaseBloc.add(ToggleGiftModeEvent(false));
},
activeColor: const Color(0xffF95F62),
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Buy Postcard for Myself",
style: TextStyle(
fontWeight: FontWeight.w600,
color: !postcardState.isGift
? const Color(0xffF95F62)
: const Color(0xff9E9E9E),
),
),
if (!postcardState.isGift && purchaseState.profile != null) ...[
const SizedBox(height: 8),
Text(
"${purchaseState.profile!.firstName} ${purchaseState.profile!.lastName}",
style: const TextStyle(
fontWeight: FontWeight.w500,
color: Color(0xff1A1A1A),
),
),
Text(
"${purchaseState.profile!.address1 ?? ""}\n${purchaseState.profile!.address2 ?? ""}",
style: const TextStyle(
fontSize: 13,
color: Color(0xff5E5E5E),
),
),
],
if (!postcardState.isGift && purchaseState.isLoadingProfile) ...[
const SizedBox(height: 8),
const SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Color(0xffF95F62),
),
),
],
],
),
),
if (!postcardState.isGift)
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const EditProfilePage(),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xffF95F62),
padding: const EdgeInsets.symmetric(
horizontal: 14, vertical: 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
"Edit Details",
style: TextStyle(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
),
const SizedBox(height: 20),
// 🩶 Option 2: Gift the Postcard
GestureDetector(
onTap: () {
postcardBloc.add(TogglePurchaseOption(true));
purchaseBloc.add(ToggleGiftModeEvent(true));
},
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: postcardState.isGift
? const Color(0xffF95F62)
: const Color(0xffE0E0E0),
width: 1.5,
),
),
child: Row(
children: [
Radio<bool>(
value: true,
groupValue: postcardState.isGift,
onChanged: (_) {
postcardBloc.add(TogglePurchaseOption(true));
purchaseBloc.add(ToggleGiftModeEvent(true));
},
activeColor: const Color(0xffF95F62),
),
const SizedBox(width: 8),
const Expanded(
child: Text(
"Gift the Postcard for someone else",
style: TextStyle(
fontWeight: FontWeight.w600,
color: Color(0xffF95F62),
),
),
),
],
),
),
),
const SizedBox(height: 15),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
PurchaseDetailsBottomSheet.close(context);
postcardBloc.add(GoToNextStep());
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xffF95F62),
padding: EdgeInsets.symmetric(vertical: 16.h),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
),
child: Text(
"Proceed",
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(height: 15),
],
),
);
},
);
},
),
);
},
);
}
static void close(BuildContext context) {
Navigator.of(context).pop();
}
}