import 'package:wanisdriver/widgets/custom_text.dart'; import 'package:wanisdriver/widgets/custom_text.dart'; import 'package:wanisdriver/widgets/custom_text.dart'; import 'package:wanisdriver/widgets/custom_text.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../Provider/TermConditionprovider.dart'; import '../utils/colors.dart'; import '../widgets/buildHeaderItemSettingWidget.dart'; import '../widgets/buildTermCard.dart'; class Privacyscreen extends StatefulWidget { const Privacyscreen({super.key}); @override State createState() => _PrivacyscreenState(); } class _PrivacyscreenState 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( appBar: AppBar( backgroundColor: Theme.of(context).brightness == Brightness.dark ? AppColors.darkPrimaryColor : AppColors.primaryColor, elevation: 0, // Remove shadow leading: InkWell( onTap: () => Navigator.pop(context), child: const Icon( Icons.arrow_back, color: AppColors.white , size: 22, ), ), title: const Txt( text: "Support & privacy", style: TextStyle( color: AppColors.white , fontWeight: FontWeight.bold, fontSize: 22, fontFamily: 'Poppins', ), ), centerTitle: false, // Align title to the start ), body: Column( children: [ const SizedBox(height: 30), Expanded( child: provider.isLoading ? _buildLoadingState() : items.isEmpty ? _buildEmptyState() : RefreshIndicator( onRefresh: _refreshData, color: Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor: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,context), ); }, ), ), ), ], ), ); } Widget _buildLoadingState() { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), blurRadius: 10, offset: const Offset(0, 2), ), ], ), child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor: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: Theme.of(context).cardColor, 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.shade500, ), ), 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.shade500, 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: Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), elevation: 0, ), ), ], ), ), ); } }