import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../config/custom_text.dart'; import '../providers/Term_conditionProvider.dart'; import '../utils/colors.dart'; import '../widgets/TermsCard.dart'; import '../widgets/waveAppBarWidget.dart'; class PrivacyPolicyscreen extends StatefulWidget { const PrivacyPolicyscreen({super.key}); @override State createState() => _PrivacyPolicyscreenState(); } class _PrivacyPolicyscreenState extends State { final ScrollController _scrollController = ScrollController(); bool _isScrolled = false; @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { Provider.of(context, listen: false).loadAboutUs(); }); _scrollController.addListener(() { setState(() { _isScrolled = _scrollController.offset > 0; }); }); } @override void dispose() { _scrollController.dispose(); super.dispose(); } Future _refreshData() async { await Provider.of(context, listen: false) .loadAboutUs(); } @override Widget build(BuildContext context) { final provider = Provider.of(context); final items = provider.items; return Scaffold( backgroundColor: Colors.grey.shade50, body: Column( children: [ Padding( padding: const EdgeInsets.only(top: 50, left: 20.0), child: buildWaveAppBar(context, "My Addresses"), ), // Main content // Content Section Expanded( child: provider.isLoading ? _buildLoadingState() : items.isEmpty ? _buildEmptyState() : RefreshIndicator( onRefresh: _refreshData, color: AppColors.primaryColor, child: ListView.builder( controller: _scrollController, physics: const BouncingScrollPhysics(), padding: const EdgeInsets.all(14), itemCount: items.length, itemBuilder: (context, index) { return AnimatedContainer( duration: Duration(milliseconds: 300 + (index * 100)), curve: Curves.easeOutBack, margin: const EdgeInsets.only(bottom: 14), child: buildTermCard(items[index], index), ); }, ), ), ), ], ), ); } Widget _buildLoadingState() { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: const CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(AppColors.primaryColor), strokeWidth: 3, ), ), const SizedBox(height: 24), Txt( text: 'Loading terms and conditions...', style: TextStyle( color: Colors.grey.shade600, fontSize: 16, fontWeight: FontWeight.w500, ), ), ], ), ); } Widget _buildEmptyState() { return Center( child: Container( margin: const EdgeInsets.all(32), padding: const EdgeInsets.all(32), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.grey.shade100, borderRadius: BorderRadius.circular(50), ), child: Icon( Icons.description_outlined, size: 48, color: Colors.grey.shade500, ), ), const SizedBox(height: 24), Txt( text: 'No Terms Available', style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Colors.grey.shade700, ), ), const SizedBox(height: 12), Txt( text: 'Terms and conditions are not available at the moment. Please try again later.', textAlign: TextAlign.center, style: TextStyle( fontSize: 14, color: Colors.grey.shade600, height: 1.5, ), ), const SizedBox(height: 24), ElevatedButton.icon( onPressed: _refreshData, icon: const Icon(Icons.refresh, size: 18), label: const Txt( text: 'Retry', style: TextStyle(fontWeight: FontWeight.w600)), style: ElevatedButton.styleFrom( backgroundColor: AppColors.primaryColor, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), elevation: 0, ), ), ], ), ), ); } }