Saving and sorting - Book update
This commit is contained in:
+12
-5
@@ -2,28 +2,35 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart'; // Import for SystemChrome
|
import 'package:flutter/services.dart'; // Import for SystemChrome
|
||||||
import 'screens/home_screen.dart';
|
import 'screens/home_screen.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// Lock orientation to portrait only
|
||||||
|
await SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.portraitUp,
|
||||||
|
DeviceOrientation.portraitDown,
|
||||||
|
]);
|
||||||
|
|
||||||
// Set system UI overlay style globally for the app
|
// Set system UI overlay style globally for the app
|
||||||
SystemChrome.setSystemUIOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
SystemUiOverlayStyle(
|
SystemUiOverlayStyle(
|
||||||
statusBarColor: Colors.grey[900], // Set status bar color (top bar)
|
statusBarColor: Colors.grey[900],
|
||||||
systemNavigationBarColor: Colors.grey[900], // Set navigation bar color
|
systemNavigationBarColor: Colors.grey[900],
|
||||||
systemNavigationBarIconBrightness: Brightness.light, // Set navigation icon color to light
|
systemNavigationBarIconBrightness: Brightness.light,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'App with Calendar',
|
title: 'SDK Muta',
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
|
||||||
|
|||||||
+146
-60
@@ -22,6 +22,7 @@ class _BookScreenState extends State<BookScreen> with WidgetsBindingObserver {
|
|||||||
Map<String, bool> _folderTypes = {}; // true = tournament, false = training
|
Map<String, bool> _folderTypes = {}; // true = tournament, false = training
|
||||||
String _folderFilter = 'all';
|
String _folderFilter = 'all';
|
||||||
bool isRenameEnabled = false;
|
bool isRenameEnabled = false;
|
||||||
|
String _sortMode = 'date'; // or 'score'
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -172,8 +173,6 @@ Color _getColorFromName(String colorName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Function to safely get the score from the JSON data
|
// Function to safely get the score from the JSON data
|
||||||
int _getScoreFromJson(Map<String, dynamic> data) {
|
int _getScoreFromJson(Map<String, dynamic> data) {
|
||||||
if (data.containsKey('totalScore') && data['totalScore'] is int) {
|
if (data.containsKey('totalScore') && data['totalScore'] is int) {
|
||||||
@@ -267,17 +266,24 @@ Color _getColorFromName(String colorName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 🔽 Sort using `createdAt` from _folderCreationDates (which is now based on metadata.json)
|
// 🔽 Sort using `createdAt` from _folderCreationDates (which is now based on metadata.json)
|
||||||
folders.sort((a, b) {
|
// 🔽 Apply sorting based on selected sort mode
|
||||||
|
folders.sort((a, b) {
|
||||||
|
if (_sortMode == 'score') {
|
||||||
|
final scoreA = _folderScores[a] ?? 0;
|
||||||
|
final scoreB = _folderScores[b] ?? 0;
|
||||||
|
return scoreB.compareTo(scoreA); // High score first
|
||||||
|
} else {
|
||||||
final dateA = _folderCreationDates[a];
|
final dateA = _folderCreationDates[a];
|
||||||
final dateB = _folderCreationDates[b];
|
final dateB = _folderCreationDates[b];
|
||||||
if (dateA == null || dateB == null) return 0;
|
if (dateA == null || dateB == null) return 0;
|
||||||
return dateB.compareTo(dateA); // Newest first
|
return dateB.compareTo(dateA); // Newest first
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<void> _renameFolder(String oldFolderName) async {
|
Future<void> _renameFolder(String oldFolderName) async {
|
||||||
final newNameController = TextEditingController();
|
final newNameController = TextEditingController();
|
||||||
bool isTournament = _folderTypes[oldFolderName] == true;
|
bool isTournament = _folderTypes[oldFolderName] == true;
|
||||||
@@ -564,61 +570,74 @@ Future<void> _renameFolder(String oldFolderName) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build the folder row with folder name, trash, and rename options
|
|
||||||
// Build the folder row with folder name, trash, rename options, and view all targets icon
|
|
||||||
Widget _buildFolderRow(String folderName) {
|
Widget _buildFolderRow(String folderName) {
|
||||||
final numberOfTargets = _groupedFiles[folderName]!.length;
|
final numberOfTargets = _groupedFiles[folderName]!.length;
|
||||||
final totalScore = _folderScores[folderName];
|
final totalScore = _folderScores[folderName];
|
||||||
|
final folderDate = _folderCreationDates[folderName];
|
||||||
|
final formattedDate = folderDate != null
|
||||||
|
? DateFormat('yyyy-MM-dd').format(folderDate)
|
||||||
|
: 'Unknown Date';
|
||||||
|
|
||||||
|
final isExpanded = _expandedFolder == folderName;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
margin: const EdgeInsets.symmetric(vertical: 6, horizontal: 16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey[300], // Lighter background for folder
|
color: isExpanded ? _bulletColor.withOpacity(0.15) : Colors.grey[300],
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: isExpanded ? _bulletColor : Colors.transparent,
|
||||||
|
width: 1.5,
|
||||||
|
),
|
||||||
|
boxShadow: isExpanded
|
||||||
|
? [
|
||||||
|
BoxShadow(
|
||||||
|
color: _bulletColor.withOpacity(0.2),
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
contentPadding: const EdgeInsets.all(0),
|
dense: true, // Compact layout
|
||||||
title: Row(
|
contentPadding: EdgeInsets.zero,
|
||||||
children: [
|
title: Text(
|
||||||
Text(folderName, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
_folderTypes[folderName] == true
|
||||||
if (_folderTypes[folderName] == true)
|
? '🏆 $folderName'
|
||||||
const Padding(
|
: folderName,
|
||||||
padding: EdgeInsets.only(left: 6),
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||||
child: Text('🏆', style: TextStyle(fontSize: 18)),
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
subtitle: Padding(
|
subtitle: Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0), // Add padding between title and info
|
padding: const EdgeInsets.only(top: 4.0),
|
||||||
child: Row(
|
child: Text(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
"📝 $numberOfTargets / 🎯 $totalScore / 📅 $formattedDate",
|
||||||
children: [
|
style: const TextStyle(fontSize: 13, color: Colors.black87),
|
||||||
Icon(Icons.insert_drive_file, color: Colors.black45),
|
|
||||||
const SizedBox(width: 4), // Small space between the icon and the text
|
|
||||||
Text(
|
|
||||||
"$numberOfTargets / 🎯 $totalScore",
|
|
||||||
style: const TextStyle(fontSize: 16, color: Colors.black),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
|
iconSize: 22,
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
icon: const Icon(Icons.my_location, color: Colors.grey),
|
icon: const Icon(Icons.my_location, color: Colors.grey),
|
||||||
onPressed: () => _openFolderTargetView(folderName),
|
onPressed: () => _openFolderTargetView(folderName),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
iconSize: 22,
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
icon: Icon(Icons.edit, color: _bulletColor),
|
icon: Icon(Icons.edit, color: _bulletColor),
|
||||||
onPressed: () => _renameFolder(folderName),
|
onPressed: () => _renameFolder(folderName),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
iconSize: 22,
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
icon: const Icon(Icons.delete, color: Colors.red),
|
icon: const Icon(Icons.delete, color: Colors.red),
|
||||||
onPressed: () => _deleteFolder(folderName),
|
onPressed: () => _deleteFolder(folderName),
|
||||||
),
|
),
|
||||||
@@ -626,13 +645,11 @@ Widget _buildFolderRow(String folderName) {
|
|||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
// If the folder is already expanded, collapse it, otherwise expand it
|
_expandedFolder = isExpanded ? null : folderName;
|
||||||
_expandedFolder = _expandedFolder == folderName ? null : folderName;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (_expandedFolder == folderName)
|
if (isExpanded)
|
||||||
// When expanded, display the file row inside the folder
|
|
||||||
..._groupedFiles[folderName]!
|
..._groupedFiles[folderName]!
|
||||||
.asMap()
|
.asMap()
|
||||||
.entries
|
.entries
|
||||||
@@ -709,7 +726,7 @@ Widget build(BuildContext context) {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
_folderFilter == 'all'
|
_folderFilter == 'all'
|
||||||
? 'Showing: All folders'
|
? 'Showing: 📂 All folders'
|
||||||
: _folderFilter == 'tournament'
|
: _folderFilter == 'tournament'
|
||||||
? 'Showing: 🏆 Tournament folders'
|
? 'Showing: 🏆 Tournament folders'
|
||||||
: 'Showing: 🎯 Training folders',
|
: 'Showing: 🎯 Training folders',
|
||||||
@@ -720,15 +737,16 @@ Widget build(BuildContext context) {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 📁 Folder list or empty state
|
// 📁 Folder list or empty state
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _groupedFiles.isEmpty
|
child: _groupedFiles.isEmpty
|
||||||
? const Center(child: Text("No saved target data found", style: TextStyle(fontSize: 18)))
|
? const Center(child: Text("No saved target data found", style: TextStyle(fontSize: 18)))
|
||||||
: ListView.builder(
|
: Scrollbar(
|
||||||
|
thumbVisibility: true, // always show scrollbar
|
||||||
|
thickness: 6, // optional: adjust width
|
||||||
|
radius: const Radius.circular(8),
|
||||||
|
child: ListView.builder(
|
||||||
itemCount: _filteredFolderNames().length,
|
itemCount: _filteredFolderNames().length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
String folderName = _filteredFolderNames()[index];
|
String folderName = _filteredFolderNames()[index];
|
||||||
@@ -736,6 +754,7 @@ Widget build(BuildContext context) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -745,15 +764,15 @@ void _showFolderFilterPopup(BuildContext context) {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
return StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: Colors.grey[900],
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
child: Container(
|
child: Padding(
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text(
|
||||||
'Filter Folders',
|
'Filter Folders',
|
||||||
@@ -762,28 +781,96 @@ void _showFolderFilterPopup(BuildContext context) {
|
|||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
_buildFilterOption('all', '📂 All folders'),
|
// Folder type filters
|
||||||
|
_buildStyledFilterButton('all', '📂 All folders', context),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildFilterOption('tournament', '🏆 Tournament'),
|
_buildStyledFilterButton('tournament', '🏆 Tournament', context),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildFilterOption('training', '🎯 Training'),
|
_buildStyledFilterButton('training', '🎯 Training', context),
|
||||||
|
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
|
const Text(
|
||||||
|
'Sort By',
|
||||||
|
style: TextStyle(color: Colors.white70, fontSize: 16, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
setState(() => _sortMode = 'date');
|
||||||
|
this.setState(() {}); // 👈 refresh parent widget
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
margin: const EdgeInsets.only(right: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: _sortMode == 'date' ? _bulletColor : Colors.grey[800],
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'📅 Sort by Date',
|
||||||
|
style: TextStyle(
|
||||||
|
color: _sortMode == 'date' ? Colors.white : Colors.white70,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
setState(() => _sortMode = 'score');
|
||||||
|
this.setState(() {}); // 👈 refresh parent widget
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: _sortMode == 'score' ? _bulletColor : Colors.grey[800],
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'🏆 Sort by Score',
|
||||||
|
style: TextStyle(
|
||||||
|
color: _sortMode == 'score' ? Colors.white : Colors.white70,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Widget _buildFilterOption(String value, String label) {
|
Widget _buildStyledFilterButton(String value, String label, BuildContext context) {
|
||||||
final isSelected = _folderFilter == value;
|
final isSelected = _folderFilter == value;
|
||||||
|
|
||||||
return GestureDetector(
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_folderFilter = value;
|
_folderFilter = value;
|
||||||
@@ -791,20 +878,20 @@ Widget _buildFilterOption(String value, String label) {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSelected ? _bulletColor.withOpacity(0.3) : Colors.grey[800],
|
color: isSelected ? _bulletColor : Colors.grey[800],
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
|
||||||
color: isSelected ? _bulletColor : Colors.transparent,
|
|
||||||
width: 1.5,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
label,
|
label,
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
style: TextStyle(
|
||||||
|
color: isSelected ? Colors.white : Colors.white70,
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -812,5 +899,4 @@ Widget _buildFilterOption(String value, String label) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: Colors.grey[900],
|
||||||
iconTheme: const IconThemeData(color: Colors.white),
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
|
scrolledUnderElevation: 0, // For Material 3 (Flutter 3.7+)
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.logout, color: Colors.red),
|
icon: const Icon(Icons.logout, color: Colors.red),
|
||||||
|
|||||||
+100
-136
@@ -529,195 +529,160 @@ void _moveBullet(Offset offsetDelta) {
|
|||||||
final directory = await getApplicationDocumentsDirectory();
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
final saveDirectory = Directory('${directory.path}/saved_images');
|
final saveDirectory = Directory('${directory.path}/saved_images');
|
||||||
|
|
||||||
// Ensure directory exists
|
|
||||||
if (!await saveDirectory.exists()) {
|
if (!await saveDirectory.exists()) {
|
||||||
await saveDirectory.create(recursive: true);
|
await saveDirectory.create(recursive: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing folders and their modified time
|
final folders = saveDirectory.listSync().whereType<Directory>().toList();
|
||||||
final folderStats = <Map<String, dynamic>>[];
|
|
||||||
final folders = saveDirectory.listSync();
|
// Sort to get most recently modified
|
||||||
|
folders.sort((a, b) => b.statSync().changed.compareTo(a.statSync().changed));
|
||||||
|
final String? lastFolder = folders.isNotEmpty ? folders.first.path.split('/').last : null;
|
||||||
|
|
||||||
|
bool lastIsTournament = false;
|
||||||
|
|
||||||
|
if (lastFolder != null) {
|
||||||
|
final metadataFile = File('${folders.first.path}/metadata.json');
|
||||||
|
if (await metadataFile.exists()) {
|
||||||
|
try {
|
||||||
|
final metadata = jsonDecode(await metadataFile.readAsString());
|
||||||
|
lastIsTournament = metadata['isTournament'] == true;
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-generate next Training and Tournament folder names
|
||||||
|
int trainingCount = 1;
|
||||||
|
int tournamentCount = 1;
|
||||||
|
|
||||||
for (var folder in folders) {
|
for (var folder in folders) {
|
||||||
if (folder is Directory) {
|
final name = folder.path.split('/').last;
|
||||||
final stat = folder.statSync();
|
if (name.startsWith('Training')) {
|
||||||
folderStats.add({
|
final num = int.tryParse(name.replaceAll('Training ', ''));
|
||||||
'name': folder.path.split('/').last,
|
if (num != null && num >= trainingCount) trainingCount = num + 1;
|
||||||
'changed': stat.changed,
|
}
|
||||||
});
|
if (name.startsWith('Tournament')) {
|
||||||
|
final num = int.tryParse(name.replaceAll('Tournament ', ''));
|
||||||
|
if (num != null && num >= tournamentCount) tournamentCount = num + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by modified time, newest first
|
final String nextTraining = 'Training $trainingCount';
|
||||||
folderStats.sort((a, b) =>
|
final String nextTournament = 'Tournament $tournamentCount';
|
||||||
(b['changed'] as DateTime).compareTo(a['changed'] as DateTime));
|
|
||||||
String? lastFolderName =
|
|
||||||
folderStats.isNotEmpty ? folderStats.first['name'] : null;
|
|
||||||
|
|
||||||
TextEditingController _controller = TextEditingController();
|
return showDialog<String>(
|
||||||
bool isNewFolderEnabled = folderStats.isEmpty; // pre-enable if none
|
|
||||||
bool isTournament = false;
|
|
||||||
|
|
||||||
return await showDialog<String>(
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
backgroundColor: Colors.grey[900],
|
backgroundColor: Colors.grey[900],
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24),
|
||||||
child: StatefulBuilder(
|
child: Column(
|
||||||
builder: (context, setState) {
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
const Padding(
|
const Text(
|
||||||
padding: EdgeInsets.only(bottom: 16.0),
|
|
||||||
child: Text(
|
|
||||||
'Save Target Data',
|
'Save Target Data',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 24),
|
||||||
const Text(
|
|
||||||
"Select where you'd like to save the data:",
|
|
||||||
style: TextStyle(color: Colors.white70),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// Quick save to newest folder
|
// 🎯 Training Button
|
||||||
if (lastFolderName != null) ...[
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context, lastFolderName);
|
Navigator.pop(
|
||||||
|
context,
|
||||||
|
jsonEncode({'folder': nextTraining, 'isTournament': false}),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: _bulletColor,
|
backgroundColor: _bulletColor,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
horizontal: 20, vertical: 14),
|
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text("Save to '$lastFolderName'"),
|
child: Text('🎯 Save to "$nextTraining"'),
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
|
|
||||||
// Always show folder name input
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: TextField(
|
|
||||||
controller: _controller,
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey[800],
|
|
||||||
hintText: "Enter a new folder name",
|
|
||||||
hintStyle: const TextStyle(color: Colors.white54),
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16, vertical: 14),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide.none,
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: BorderSide(color: _bulletColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
isNewFolderEnabled = value.trim().isNotEmpty;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// Tournament toggle
|
// 🏆 Tournament Button
|
||||||
if (isNewFolderEnabled) ...[
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
isTournament = !isTournament;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: isTournament
|
|
||||||
? _bulletColor.withOpacity(0.2)
|
|
||||||
: Colors.grey[850],
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(
|
|
||||||
color: isTournament
|
|
||||||
? _bulletColor
|
|
||||||
: Colors.grey[700]!,
|
|
||||||
width: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16, vertical: 14),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
isTournament
|
|
||||||
? 'Tournament Mode 🏆'
|
|
||||||
: 'Mark as Tournament 🏆',
|
|
||||||
style: TextStyle(
|
|
||||||
color: isTournament
|
|
||||||
? _bulletColor
|
|
||||||
: Colors.white70,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
|
|
||||||
// Create folder button
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: isNewFolderEnabled
|
onPressed: () {
|
||||||
? () => Navigator.pop(
|
Navigator.pop(
|
||||||
context,
|
context,
|
||||||
jsonEncode({
|
jsonEncode({'folder': nextTournament, 'isTournament': true}),
|
||||||
'folder': _controller.text.trim(),
|
);
|
||||||
'isTournament': isTournament,
|
},
|
||||||
}),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(
|
backgroundColor: _bulletColor,
|
||||||
horizontal: 20, vertical: 14),
|
|
||||||
backgroundColor:
|
|
||||||
isNewFolderEnabled ? _bulletColor : Colors.grey[700],
|
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
disabledBackgroundColor: Colors.grey[700],
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: const Text("Create New Folder"),
|
child: Text('🏆 Save to "$nextTournament"'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (lastFolder != null) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
|
// 📁 Last Used Folder Button (highlighted subtly)
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.white.withOpacity(0.2), width: 1),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(
|
||||||
|
context,
|
||||||
|
jsonEncode({
|
||||||
|
'folder': lastFolder,
|
||||||
|
'isTournament': lastIsTournament,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: _bulletColor.withOpacity(0.9),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${lastIsTournament ? "🏆" : "🎯"} Save to "$lastFolder"',
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
const Text(
|
||||||
|
'Last used folder',
|
||||||
|
style: TextStyle(fontSize: 12, color: Colors.white70),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
],
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -725,7 +690,6 @@ void _moveBullet(Offset offsetDelta) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Map<String, dynamic>? _getRingCenterSize(List<DetectionResult> results) {
|
Map<String, dynamic>? _getRingCenterSize(List<DetectionResult> results) {
|
||||||
try {
|
try {
|
||||||
final ring = results.firstWhere((r) => r.classId == 2);
|
final ring = results.firstWhere((r) => r.classId == 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user