|
|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import '../utils/top_snackbar.dart';
|
|
|
|
|
import 'package:practice_engine/practice_engine.dart';
|
|
|
|
|
import '../services/deck_storage.dart';
|
|
|
|
|
@ -135,8 +138,10 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _save() {
|
|
|
|
|
if (_deck == null || _config == null) return;
|
|
|
|
|
/// Builds config from current form state, validates, persists if valid.
|
|
|
|
|
/// Returns true if saved, false if validation failed.
|
|
|
|
|
bool _applyAndPersist() {
|
|
|
|
|
if (_deck == null || _config == null) return false;
|
|
|
|
|
|
|
|
|
|
final consecutive = int.tryParse(_consecutiveController.text);
|
|
|
|
|
final attemptSize = int.tryParse(_attemptSizeController.text);
|
|
|
|
|
@ -153,7 +158,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (consecutive < 1 ||
|
|
|
|
|
@ -166,7 +171,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate time limit in seconds
|
|
|
|
|
@ -176,7 +181,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
final minutes = int.tryParse(_timeLimitMinutesController.text) ?? 0;
|
|
|
|
|
final seconds = int.tryParse(_timeLimitSecondsController.text) ?? 0;
|
|
|
|
|
final totalSeconds = hours * 3600 + minutes * 60 + seconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (totalSeconds > 0) {
|
|
|
|
|
timeLimitSeconds = totalSeconds;
|
|
|
|
|
} else {
|
|
|
|
|
@ -186,7 +191,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -203,21 +208,78 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final updatedDeck = _deck!.copyWith(config: updatedConfig);
|
|
|
|
|
final deckStorage = DeckStorage();
|
|
|
|
|
deckStorage.saveDeckSync(updatedDeck);
|
|
|
|
|
|
|
|
|
|
// Show success message
|
|
|
|
|
showTopSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
message: 'Deck configuration saved successfully',
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
duration: const Duration(seconds: 1),
|
|
|
|
|
);
|
|
|
|
|
setState(() {
|
|
|
|
|
_deck = updatedDeck;
|
|
|
|
|
_config = updatedConfig;
|
|
|
|
|
_configHashCode = updatedConfig.hashCode;
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pop with the updated deck
|
|
|
|
|
Navigator.pop(context, updatedDeck);
|
|
|
|
|
Map<String, dynamic> _configToJsonMap() {
|
|
|
|
|
int? timeLimitSeconds;
|
|
|
|
|
if (_timeLimitEnabled) {
|
|
|
|
|
final hours = int.tryParse(_timeLimitHoursController.text) ?? 0;
|
|
|
|
|
final minutes = int.tryParse(_timeLimitMinutesController.text) ?? 0;
|
|
|
|
|
final seconds = int.tryParse(_timeLimitSecondsController.text) ?? 0;
|
|
|
|
|
timeLimitSeconds = hours * 3600 + minutes * 60 + seconds;
|
|
|
|
|
if (timeLimitSeconds == 0) timeLimitSeconds = null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
'requiredConsecutiveCorrect': int.tryParse(_consecutiveController.text) ?? _config!.requiredConsecutiveCorrect,
|
|
|
|
|
'defaultAttemptSize': int.tryParse(_attemptSizeController.text) ?? _config!.defaultAttemptSize,
|
|
|
|
|
'priorityIncreaseOnIncorrect': int.tryParse(_priorityIncreaseController.text) ?? _config!.priorityIncreaseOnIncorrect,
|
|
|
|
|
'priorityDecreaseOnCorrect': int.tryParse(_priorityDecreaseController.text) ?? _config!.priorityDecreaseOnCorrect,
|
|
|
|
|
'immediateFeedbackEnabled': _immediateFeedback,
|
|
|
|
|
'includeKnownInAttempts': _includeKnownInAttempts,
|
|
|
|
|
'shuffleAnswerOrder': _shuffleAnswerOrder,
|
|
|
|
|
'excludeFlaggedQuestions': _excludeFlaggedQuestions,
|
|
|
|
|
if (timeLimitSeconds != null) 'timeLimitSeconds': timeLimitSeconds,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _cancel() {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
void _showAsJson() {
|
|
|
|
|
if (_deck == null || _config == null) return;
|
|
|
|
|
final map = _configToJsonMap();
|
|
|
|
|
final jsonString = const JsonEncoder.withIndent(' ').convert(map);
|
|
|
|
|
showDialog<void>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
|
title: const Text('Attempt Settings as JSON'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: SelectableText(
|
|
|
|
|
jsonString,
|
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: const Text('Close'),
|
|
|
|
|
),
|
|
|
|
|
FilledButton.icon(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Clipboard.setData(ClipboardData(text: jsonString));
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
showTopSnackBar(
|
|
|
|
|
context,
|
|
|
|
|
message: 'JSON copied to clipboard',
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
duration: const Duration(seconds: 1),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.copy, size: 20),
|
|
|
|
|
label: const Text('Copy'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _editDeck() {
|
|
|
|
|
@ -307,7 +369,18 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: const Text('Deck Configuration'),
|
|
|
|
|
title: const Text('Attempt Settings'),
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
|
onPressed: () => Navigator.pop(context, _deck),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.code),
|
|
|
|
|
onPressed: _showAsJson,
|
|
|
|
|
tooltip: 'Show as JSON',
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
@ -335,6 +408,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
|
|
|
|
@ -347,6 +421,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
|
|
|
|
@ -359,6 +434,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
|
|
|
|
@ -371,6 +447,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
|
|
|
|
@ -385,6 +462,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
setState(() {
|
|
|
|
|
_immediateFeedback = value;
|
|
|
|
|
});
|
|
|
|
|
_applyAndPersist();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
@ -400,6 +478,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
setState(() {
|
|
|
|
|
_includeKnownInAttempts = value;
|
|
|
|
|
});
|
|
|
|
|
_applyAndPersist();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
@ -415,6 +494,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
setState(() {
|
|
|
|
|
_shuffleAnswerOrder = value;
|
|
|
|
|
});
|
|
|
|
|
_applyAndPersist();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
@ -430,6 +510,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
setState(() {
|
|
|
|
|
_excludeFlaggedQuestions = value;
|
|
|
|
|
});
|
|
|
|
|
_applyAndPersist();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
@ -450,6 +531,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
_timeLimitSecondsController.clear();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_applyAndPersist();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
if (_timeLimitEnabled) ...[
|
|
|
|
|
@ -464,6 +546,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
@ -475,6 +558,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
@ -486,6 +570,7 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
onEditingComplete: _applyAndPersist,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -579,26 +664,6 @@ class _DeckConfigScreenState extends State<DeckConfigScreen> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
|
|
|
|
|
// Action Buttons
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: OutlinedButton(
|
|
|
|
|
onPressed: _cancel,
|
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: FilledButton(
|
|
|
|
|
onPressed: _save,
|
|
|
|
|
child: const Text('Save'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|