2026-01-13 00:57:18 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2026-01-15 15:53:44 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2026-01-13 00:57:18 +00:00
|
|
|
import '../../models/maps/prefecture_tile_layout.dart';
|
2026-01-15 15:53:44 +00:00
|
|
|
import '../../models/maps/japan_map_data.dart';
|
2026-01-13 00:57:18 +00:00
|
|
|
import '../../theme/app_theme.dart';
|
2026-01-15 15:53:44 +00:00
|
|
|
import '../../providers/ui_experiment_provider.dart';
|
2026-01-13 00:57:18 +00:00
|
|
|
|
2026-01-15 15:53:44 +00:00
|
|
|
class PrefectureTileMap extends ConsumerWidget {
|
2026-01-13 00:57:18 +00:00
|
|
|
final Set<String> visitedPrefectures;
|
|
|
|
|
final Function(String) onPrefectureTap;
|
|
|
|
|
final double tileSize;
|
|
|
|
|
final double gap;
|
|
|
|
|
|
|
|
|
|
const PrefectureTileMap({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.visitedPrefectures,
|
|
|
|
|
required this.onPrefectureTap,
|
|
|
|
|
this.tileSize = 46.0,
|
|
|
|
|
this.gap = 4.0,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
2026-01-15 15:53:44 +00:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final isMapColorful = ref.watch(uiExperimentProvider).isMapColorful;
|
|
|
|
|
|
2026-01-13 00:57:18 +00:00
|
|
|
// 1. Determine Grid Bounds
|
|
|
|
|
int maxCol = 0;
|
|
|
|
|
int maxRow = 0;
|
|
|
|
|
PrefectureTileLayout.getLayout.forEach((_, pos) {
|
|
|
|
|
if (pos.col + pos.width > maxCol) maxCol = pos.col + pos.width;
|
|
|
|
|
if (pos.row + pos.height > maxRow) maxRow = pos.row + pos.height;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final double totalWidth = maxCol * (tileSize + gap) - gap;
|
|
|
|
|
final double totalHeight = maxRow * (tileSize + gap) - gap;
|
|
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
|
width: totalWidth,
|
|
|
|
|
height: totalHeight,
|
|
|
|
|
child: Stack(
|
|
|
|
|
children: PrefectureTileLayout.getLayout.entries.map((entry) {
|
|
|
|
|
final prefName = entry.key;
|
|
|
|
|
final pos = entry.value;
|
|
|
|
|
final isVisited = visitedPrefectures.contains(prefName) ||
|
|
|
|
|
visitedPrefectures.any((v) => v.startsWith(prefName)); // Robust check
|
|
|
|
|
|
|
|
|
|
return Positioned(
|
|
|
|
|
left: pos.col * (tileSize + gap),
|
|
|
|
|
top: pos.row * (tileSize + gap),
|
|
|
|
|
width: pos.width * tileSize + (pos.width - 1) * gap,
|
|
|
|
|
height: pos.height * tileSize + (pos.height - 1) * gap,
|
2026-01-15 15:53:44 +00:00
|
|
|
child: _buildTile(context, prefName, isVisited, isMapColorful),
|
2026-01-13 00:57:18 +00:00
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 15:53:44 +00:00
|
|
|
static const Map<int, Color> regionColors = {
|
|
|
|
|
1: Color(0xFF6A7FF0), // Hokkaido: Blue
|
|
|
|
|
2: Color(0xFF58C2F1), // Tohoku: Cyan
|
|
|
|
|
3: Color(0xFF39D353), // Kanto: Green
|
|
|
|
|
4: Color(0xFF36D3AD), // Chubu: Emerald
|
|
|
|
|
5: Color(0xFFAEDA38), // Kinki: YellowGreen
|
|
|
|
|
6: Color(0xFFE6D33C), // Chugoku: Yellow
|
|
|
|
|
7: Color(0xFFF9A057), // Shikoku: Orange
|
|
|
|
|
8: Color(0xFFFF7B7B), // Kyushu: Pink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Widget _buildTile(BuildContext context, String prefName, bool isVisited, bool isColorful) {
|
2026-01-13 00:57:18 +00:00
|
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
|
|
2026-01-15 15:53:44 +00:00
|
|
|
// Find Region ID for coloring
|
|
|
|
|
int prefId = 0;
|
|
|
|
|
JapanMapData.prefectureNames.forEach((k, v) {
|
|
|
|
|
if (v.contains(prefName)) prefId = k;
|
|
|
|
|
});
|
|
|
|
|
final regionId = JapanMapData.getRegionId(prefId);
|
|
|
|
|
final regionColor = regionColors[regionId] ?? Colors.grey;
|
|
|
|
|
|
|
|
|
|
Color baseColor;
|
|
|
|
|
Color textColor;
|
|
|
|
|
Color borderColor;
|
|
|
|
|
BoxBorder? border; // Use BoxBorder specifically
|
|
|
|
|
|
|
|
|
|
if (isColorful) {
|
|
|
|
|
// --- Colorful Mode ---
|
|
|
|
|
if (isVisited) {
|
|
|
|
|
baseColor = regionColor;
|
|
|
|
|
textColor = Colors.white;
|
|
|
|
|
borderColor = Colors.transparent; // No border needed for filled
|
|
|
|
|
border = null;
|
|
|
|
|
} else {
|
|
|
|
|
baseColor = isDark ? Colors.grey[900]! : Colors.grey[100]!;
|
|
|
|
|
textColor = isDark ? Colors.grey[600]! : Colors.grey[400]!;
|
|
|
|
|
borderColor = regionColor.withOpacity(0.6);
|
|
|
|
|
border = Border.all(color: borderColor, width: 2);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// --- Classic Mode ---
|
|
|
|
|
baseColor = isVisited ? AppTheme.posimaiBlue : (isDark ? Colors.grey[800]! : Colors.grey[300]!);
|
|
|
|
|
textColor = isVisited ? Colors.white : (isDark ? Colors.grey[400]! : Colors.grey[700]!);
|
|
|
|
|
borderColor = isDark ? Colors.grey[700]! : Colors.white;
|
|
|
|
|
border = Border.all(color: borderColor, width: 1); // Subtle inner border
|
|
|
|
|
}
|
2026-01-13 00:57:18 +00:00
|
|
|
|
|
|
|
|
return Material(
|
|
|
|
|
color: baseColor,
|
|
|
|
|
borderRadius: BorderRadius.circular(6), // Rounded corners for "Block" look
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () => onPrefectureTap(prefName),
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
child: Container(
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
2026-01-15 15:53:44 +00:00
|
|
|
border: border,
|
2026-01-13 00:57:18 +00:00
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
prefName,
|
2026-01-15 15:53:44 +00:00
|
|
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
2026-01-13 00:57:18 +00:00
|
|
|
color: textColor,
|
|
|
|
|
fontSize: 12, // Small but legible
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|