import 'package:wanisclient/utils/colors.dart'; import 'package:flutter/material.dart'; class RatingWidget extends StatefulWidget { final String userImageUrl; final String userName; final Function(int rating) onRatingChanged; final VoidCallback onClose; const RatingWidget({ Key? key, required this.userImageUrl, required this.userName, required this.onRatingChanged, required this.onClose, }) : super(key: key); @override _RatingWidgetState createState() => _RatingWidgetState(); } class _RatingWidgetState extends State { int currentRating = 0; @override Widget build(BuildContext context) { return Material( color: Colors.black54, // Transparent black background child: Container( width: double.infinity, height: double.infinity, child: Center( child: Container( width: MediaQuery.of(context).size.width * 0.85, padding: EdgeInsets.all(24), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: const [ BoxShadow( color: Colors.black26, blurRadius: 10, offset: Offset(0, 5), ), ], ), child: Column( mainAxisSize: MainAxisSize.min, children: [ // Close button Align( alignment: Alignment.topRight, child: IconButton( onPressed: widget.onClose, icon: Icon(Icons.close, color: Colors.grey[600]), padding: EdgeInsets.zero, ), ), SizedBox(height: 8), // User image Container( width: 80, height: 80, decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all(color: Colors.grey[300]!, width: 2), ), child: ClipOval( child: widget.userImageUrl.isNotEmpty ? Image.network( widget.userImageUrl, fit: BoxFit.cover, errorBuilder: (context, error, stackTrace) { return Container( color: Colors.grey[200], child: Icon( Icons.person, size: 40, color: Colors.grey[500], ), ); }, ) : Container( color: Colors.grey[200], child: Icon( Icons.person, size: 40, color: Colors.grey[500], ), ), ), ), SizedBox(height: 16), // User name Text( widget.userName, style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.grey[800], ), ), SizedBox(height: 8), // Rating text Text( 'Rate your experience', style: TextStyle( fontSize: 16, color: Colors.grey[600], ), ), SizedBox(height: 24), // Star rating Row( mainAxisAlignment: MainAxisAlignment.center, children: List.generate(5, (index) { return GestureDetector( onTap: () { setState(() { currentRating = index + 1; }); widget.onRatingChanged(currentRating); }, child: Container( padding: EdgeInsets.all(4), child: Icon( Icons.star, size: 40, color: index < currentRating ? Colors.amber : Colors.grey[300], ), ), ); }), ), SizedBox(height: 16), // Rating text indicator if (currentRating > 0) Text( _getRatingText(currentRating), style: TextStyle( fontSize: 14, color: Colors.grey[600], fontWeight: FontWeight.w500, ), ), SizedBox(height: 24), // Submit button if (currentRating > 0) SizedBox( width: double.infinity, child: ElevatedButton( onPressed: () { widget.onRatingChanged(currentRating); widget.onClose(); }, style: ElevatedButton.styleFrom( backgroundColor: AppColors.primaryColor, foregroundColor: Colors.white, padding: EdgeInsets.symmetric(vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), ), child: Text( 'Submit Rating', style: TextStyle(fontSize: 16), ), ), ), ], ), ), ), ), ); } String _getRatingText(int rating) { switch (rating) { case 1: return 'Poor'; case 2: return 'Fair'; case 3: return 'Good'; case 4: return 'Very Good'; case 5: return 'Excellent'; default: return ''; } } }