import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; // import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; import 'package:proxibuy/core/gen/assets.gen.dart'; import 'package:proxibuy/data/models/offer_model.dart'; import 'package:proxibuy/data/repositories/offer_repository.dart'; import 'package:proxibuy/presentation/offer/bloc/offer_bloc.dart'; import 'package:proxibuy/presentation/offer/bloc/offer_state.dart'; import 'package:proxibuy/presentation/reservation/cubit/reservation_cubit.dart'; import 'package:proxibuy/presentation/widgets/reserved_list_item_card.dart'; class ReservedListPage extends StatefulWidget { const ReservedListPage({super.key}); @override State createState() => _ReservedListPageState(); } class _ReservedListPageState extends State { late final List _reservedIds; // دیگر نیازی به Future نیست List _reservedOffers = []; @override void initState() { super.initState(); _reservedIds = context.read().state.reservedProductIds; // اطلاعات مستقیما از BLoC خوانده می‌شود _fetchReservedOffersFromBloc(); } void _fetchReservedOffersFromBloc() { final offersState = context.read().state; // بررسی می‌کند که آیا پیشنهادها قبلا بارگذاری شده‌اند یا خیر if (offersState is OffersLoadSuccess) { final allOffers = offersState.offers; if (mounted) { setState(() { _reservedOffers = allOffers .where((offer) => _reservedIds.contains(offer.id)) .toList(); }); } } } @override Widget build(BuildContext context) { return Directionality( textDirection: TextDirection.rtl, child: Scaffold( appBar: _buildCustomAppBar(context), // FutureBuilder با یک ویجت ساده جایگزین شد body: _reservedOffers.isEmpty ? const Center( child: Text('هیچ آیتم رزرو شده‌ای یافت نشد.'), ) : ListView.builder( padding: const EdgeInsets.all(16.0), itemCount: _reservedOffers.length, itemBuilder: (context, index) { final offer = _reservedOffers[index]; return Padding( padding: const EdgeInsets.only(bottom: 16.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'تخفیف ${offer.discountType} رزرو شد!', style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black87, ), ), const SizedBox(height: 8), const Divider(thickness: 1.5), const SizedBox(height: 2), ReservedListItemCard(offer: offer), SizedBox( height: 15, ) ], ), ).animate().fadeIn(delay: (100 * index).ms).slideY( begin: 0.5, duration: 500.ms, curve: Curves.easeOutCubic, ); }, ) ) ); } } PreferredSizeWidget _buildCustomAppBar(BuildContext context) { return PreferredSize( preferredSize: const Size.fromHeight(70.0), child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: const BorderRadius.vertical( bottom: Radius.circular(15), ), boxShadow: [ BoxShadow( // ignore: deprecated_member_use color: Colors.black.withOpacity(0.08), blurRadius: 10, offset: const Offset(0, 4), ), ], ), child: SafeArea( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Column( children: [ SizedBox(height: 15), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Row( children: [ const Text( 'رزرو شده‌ها', style: TextStyle( color: Colors.black, fontWeight: FontWeight.normal, fontSize: 16, ), ), IconButton( icon: SvgPicture.asset(Assets.icons.arrowLeft.path), onPressed: () => Navigator.of(context).pop(), ), ], ), ], ), ], ), ), ), ), ); }