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/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>? _reservedOffersFuture; @override void initState() { super.initState(); _reservedIds = context.read().state.reservedProductIds; _reservedOffersFuture = _fetchReservedOffers(); } Future> _fetchReservedOffers() { final offerRepo = context.read(); final offerFutures = _reservedIds.map((id) => offerRepo.fetchOfferById(id)).toList(); return Future.wait(offerFutures); } @override Widget build(BuildContext context) { return Directionality( textDirection: TextDirection.rtl, child: Scaffold( appBar: _buildCustomAppBar(context), body: FutureBuilder>( future: _reservedOffersFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); } if (snapshot.hasError) { return Center( child: Text('خطا در بارگذاری اطلاعات: ${snapshot.error}'), ); } if (!snapshot.hasData || snapshot.data!.isEmpty) { return const Center( child: Text('هیچ آیتم رزرو شده‌ای وجود ندارد.'), ); } final reservedOffers = snapshot.data!.whereType().toList(); if (reservedOffers.isEmpty) { return const Center( child: Text('هیچ آیتم رزرو شده‌ای یافت نشد.'), ); } return 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(), ), ], ), ], ), ], ), ), ), ), ); } }