add a shit ton of feature for the custom srs
This commit is contained in:
127
lib/src/screens/custom_card_details_screen.dart
Normal file
127
lib/src/screens/custom_card_details_screen.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
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;
|
||||
late int _srsLevel;
|
||||
|
||||
@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;
|
||||
_srsLevel = widget.item.srsLevel;
|
||||
}
|
||||
|
||||
@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,
|
||||
useInterval: _useInterval,
|
||||
srsLevel: _srsLevel,
|
||||
nextReview: widget.item.nextReview,
|
||||
);
|
||||
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;
|
||||
});
|
||||
},
|
||||
),
|
||||
Text('SRS Level: $_srsLevel'),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _saveChanges,
|
||||
child: const Text('Save Changes'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user