import 'dart:io'; import 'package:flutter/material.dart'; import '../utils/colors.dart'; class MultipleImagePicker extends StatelessWidget { final List images; final Function(int) onImagePick; final Function(int)? onImageRemove; final String title; final String? subtitle; final int maxImages; const MultipleImagePicker({ Key? key, required this.images, required this.onImagePick, this.onImageRemove, required this.title, this.subtitle, this.maxImages = 4, }) : super(key: key); @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: Theme.of(context).brightness == Brightness.dark? AppColors.blackBackgroundColor: AppColors.whiteBackgroundColor, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), spreadRadius: 1, blurRadius: 6, offset: const Offset(0, 2), ), ], ), padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w500, ), ), if (subtitle != null) ...[ const SizedBox(height: 4), Text( subtitle!, style: TextStyle( fontSize: 12, color: Colors.grey.shade600, ), ), ], ], ), ), Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), decoration: BoxDecoration( color: Colors.blue.shade50, borderRadius: BorderRadius.circular(12), ), child: Text( '${images.where((img) => img != null).length}/$maxImages', style: TextStyle( fontSize: 12, color: Colors.blue.shade700, fontWeight: FontWeight.w500, ), ), ), ], ), const SizedBox(height: 16), GridView.builder( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, crossAxisSpacing: 12, mainAxisSpacing: 12, childAspectRatio: 1.2, ), itemCount: maxImages, itemBuilder: (context, index) { final bool hasImage = index < images.length && images[index] != null; return GestureDetector( onTap: () => onImagePick(index), child: Container( decoration: BoxDecoration( border: Border.all( color: hasImage ? Colors.blue.shade200 : Colors.grey.shade300, style: BorderStyle.solid, width: hasImage ? 2 : 1, ), borderRadius: BorderRadius.circular(8), color: hasImage ? Theme.of(context).brightness == Brightness.dark? AppColors.darkCardColor: Colors.blue.shade50 :Theme.of(context).brightness == Brightness.dark? AppColors.darkCardColor: Colors.grey.shade50, ), child: hasImage ? ClipRRect( borderRadius: BorderRadius.circular(6), child: Stack( children: [ Image.file( images[index]!, fit: BoxFit.cover, width: double.infinity, height: double.infinity, ), Positioned( top: 4, right: 4, child: GestureDetector( onTap: () => onImageRemove?.call(index), child: Container( padding: const EdgeInsets.all(4), decoration: BoxDecoration( color: Colors.red.withOpacity(0.8), shape: BoxShape.circle, ), child: const Icon( Icons.close, color: Colors.white, size: 14, ), ), ), ), Positioned( bottom: 4, right: 4, child: Container( padding: const EdgeInsets.all(4), decoration: BoxDecoration( color: Colors.black.withOpacity(0.6), shape: BoxShape.circle, ), child: const Icon( Icons.edit, color: Colors.white, size: 14, ), ), ), ], ), ) : Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon( Icons.add_photo_alternate_outlined, size: 28, color: Colors.grey.shade500, ), const SizedBox(height: 6), Text( 'Photo ${index + 1}', style: TextStyle( color: Colors.grey.shade600, fontSize: 11, fontWeight: FontWeight.w500, ), ), ], ), ), ); }, ), ], ), ); } }