140 lines
4.3 KiB
Dart
140 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/custom_kanji_item.dart';
|
|
import '../services/custom_deck_repository.dart';
|
|
|
|
class CustomCardDetailsScreen extends StatefulWidget {
|
|
final CustomKanjiItem item;
|
|
final CustomDeckRepository repository;
|
|
|
|
const CustomCardDetailsScreen({
|
|
super.key,
|
|
required this.item,
|
|
required this.repository,
|
|
});
|
|
|
|
@override
|
|
State<CustomCardDetailsScreen> createState() =>
|
|
_CustomCardDetailsScreenState();
|
|
}
|
|
|
|
class _CustomCardDetailsScreenState extends State<CustomCardDetailsScreen> {
|
|
late TextEditingController _japaneseController;
|
|
late TextEditingController _englishController;
|
|
late TextEditingController _kanjiController;
|
|
late bool _useInterval;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_japaneseController = TextEditingController(text: widget.item.characters);
|
|
_englishController = TextEditingController(text: widget.item.meaning);
|
|
_kanjiController = TextEditingController(text: widget.item.kanji);
|
|
_useInterval = widget.item.useInterval;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_japaneseController.dispose();
|
|
_englishController.dispose();
|
|
_kanjiController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _saveChanges() {
|
|
final updatedItem = CustomKanjiItem(
|
|
characters: _japaneseController.text,
|
|
meaning: _englishController.text,
|
|
kanji: _kanjiController.text.trim().isNotEmpty
|
|
? _kanjiController.text.trim()
|
|
: null,
|
|
useInterval: _useInterval,
|
|
srsData: widget.item.srsData,
|
|
);
|
|
widget.repository.updateCard(updatedItem);
|
|
Navigator.of(context).pop(true);
|
|
}
|
|
|
|
void _deleteCard() {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Delete Card'),
|
|
content: const Text('Are you sure you want to delete this card?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
widget.repository.deleteCard(widget.item);
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context).pop(true);
|
|
},
|
|
child: const Text('Delete'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Edit Card'),
|
|
actions: [
|
|
IconButton(icon: const Icon(Icons.delete), onPressed: _deleteCard),
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
TextFormField(
|
|
controller: _japaneseController,
|
|
decoration: const InputDecoration(labelText: 'Japanese (Kana)'),
|
|
),
|
|
TextFormField(
|
|
controller: _kanjiController,
|
|
decoration: const InputDecoration(labelText: 'Japanese (Kanji)'),
|
|
),
|
|
TextFormField(
|
|
controller: _englishController,
|
|
decoration: const InputDecoration(labelText: 'English'),
|
|
),
|
|
SwitchListTile(
|
|
title: const Text('Use Interval SRS'),
|
|
value: _useInterval,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_useInterval = value;
|
|
});
|
|
},
|
|
),
|
|
const SizedBox(height: 20),
|
|
const Text(
|
|
'SRS Levels',
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
Text(
|
|
'Jpn→Eng: ${widget.item.srsData.japaneseToEnglish} (Next review: ${widget.item.srsData.japaneseToEnglishNextReview?.toString() ?? 'N/A'})',
|
|
),
|
|
Text(
|
|
'Eng→Jpn: ${widget.item.srsData.englishToJapanese} (Next review: ${widget.item.srsData.englishToJapaneseNextReview?.toString() ?? 'N/A'})',
|
|
),
|
|
Text(
|
|
'Listening: ${widget.item.srsData.listeningComprehension} (Next review: ${widget.item.srsData.listeningComprehensionNextReview?.toString() ?? 'N/A'})',
|
|
),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _saveChanges,
|
|
child: const Text('Save Changes'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|