Files
urukprize/mobile/lib/features/partners/presentation/partners_directory_screen.dart
T

211 lines
8.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../core/theme/app_theme.dart';
import '../cubit/partners_cubit.dart';
import '../cubit/partners_state.dart';
class PartnersDirectoryScreen extends StatefulWidget {
const PartnersDirectoryScreen({super.key});
@override
State<PartnersDirectoryScreen> createState() => _PartnersDirectoryScreenState();
}
class _PartnersDirectoryScreenState extends State<PartnersDirectoryScreen> {
final _searchController = TextEditingController();
String _selectedType = 'ALL';
@override
void initState() {
super.initState();
context.read<PartnersCubit>().fetchPartners();
}
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
appBar: AppBar(
title: const Text('دليل الشركاء والخصومات'),
),
body: Column(
children: [
// Search Input
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: TextField(
controller: _searchController,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: 'ابحث عن مستشفى، مركز، أو فندق...',
hintStyle: const TextStyle(color: AppTheme.textMuted),
prefixIcon: const Icon(Icons.search, color: AppTheme.goldAccent),
filled: true,
fillColor: AppTheme.cardDark,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
),
onSubmitted: (val) {
context.read<PartnersCubit>().fetchPartners(type: _selectedType, search: val);
},
),
),
// Filter Chips (Hospitals 50% vs Hotels 40-60%)
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
child: Row(
children: [
_buildFilterChip('الكل', 'ALL'),
const SizedBox(width: 8),
_buildFilterChip('المستشفيات (خصم 50%)', 'HOSPITAL'),
const SizedBox(width: 8),
_buildFilterChip('الفنادق (خصم 40%-60%)', 'HOTEL'),
],
),
),
// Partners List
Expanded(
child: BlocBuilder<PartnersCubit, PartnersState>(
builder: (context, state) {
if (state is PartnersLoading) {
return const Center(child: CircularProgressIndicator(color: AppTheme.goldAccent));
}
if (state is PartnersLoaded) {
final list = state.partners;
if (list.isEmpty) {
return const Center(
child: Text(
'لا توجد نتائج مطابقة لبحثك.',
style: TextStyle(color: AppTheme.textMuted),
),
);
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: list.length,
itemBuilder: (context, idx) {
final item = list[idx] as Map<String, dynamic>;
final isHospital = item['type'] == 'HOSPITAL';
final discount = item['discount_percentage'] ?? (isHospital ? '50%' : '40%');
return Card(
color: AppTheme.cardDark,
margin: const EdgeInsets.only(bottom: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
side: BorderSide(color: AppTheme.goldAccent.withOpacity(0.2)),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item['name_ar'] ?? 'مستشفى الشريك',
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: AppTheme.goldAccent.withOpacity(0.18),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'خصم $discount%',
style: const TextStyle(
color: AppTheme.goldLight,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
],
),
const SizedBox(height: 6),
Text(
'${item['category'] ?? 'عام'} • ${item['city'] ?? 'العراق'}',
style: const TextStyle(color: AppTheme.textMuted, fontSize: 13),
),
if (item['address'] != null) ...[
const SizedBox(height: 6),
Row(
children: [
const Icon(Icons.location_on_outlined, color: AppTheme.goldAccent, size: 16),
const SizedBox(width: 4),
Expanded(
child: Text(
item['address'],
style: const TextStyle(color: Colors.white70, fontSize: 12),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
],
],
),
),
);
},
);
}
return Center(
child: ElevatedButton(
onPressed: () => context.read<PartnersCubit>().fetchPartners(),
child: const Text('تحديث الدليل'),
),
);
},
),
),
],
),
),
);
}
Widget _buildFilterChip(String label, String type) {
final isSelected = _selectedType == type;
return ChoiceChip(
label: Text(label),
selected: isSelected,
selectedColor: AppTheme.goldAccent,
backgroundColor: AppTheme.cardDark,
labelStyle: TextStyle(
color: isSelected ? AppTheme.primaryDark : Colors.white,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontSize: 12,
),
onSelected: (selected) {
if (selected) {
setState(() => _selectedType = type);
context.read<PartnersCubit>().fetchPartners(type: type, search: _searchController.text);
}
},
);
}
}