import 'dart:io';

import 'package:flutter/material.dart';

/// 撮影済み画像のサムネイルを 3 列のグリッドで表示するウィジェット．
class ImageGrid extends StatelessWidget {
  const ImageGrid({super.key, required this.images, required this.onImageTap});

  final List<File> images;
  final void Function(File file) onImageTap;

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      padding: const EdgeInsets.all(4),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        crossAxisSpacing: 4,
        mainAxisSpacing: 4,
      ),
      itemCount: images.length,
      itemBuilder: (context, index) {
        final file = images[index];
        return GestureDetector(
          onTap: () => onImageTap(file),
          child: Image.file(file, fit: BoxFit.cover, cacheWidth: 200),
        );
      },
    );
  }
}
