106 lines
2.9 KiB
Dart
106 lines
2.9 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:tangocard_reader/models/data_entry.dart';
|
|
|
|
import 'flashcard.dart';
|
|
|
|
class PractiseView extends StatefulWidget {
|
|
final List<DataEntry> entries;
|
|
final bool isKanji;
|
|
final int index;
|
|
|
|
const PractiseView({
|
|
Key? key,
|
|
required this.entries,
|
|
required this.isKanji,
|
|
this.index = 0,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<PractiseView> createState() => _PractiseViewState();
|
|
}
|
|
|
|
const encouragingWords = [
|
|
'頑張れ〜!',
|
|
'できるぞ!',
|
|
'ヨッシャー!',
|
|
'いけいけいけー!',
|
|
];
|
|
|
|
class _PractiseViewState extends State<PractiseView> {
|
|
String title = '';
|
|
late int currentCard;
|
|
final List<bool> _isSelected = [false, false];
|
|
|
|
get isShuffleMode => _isSelected[0];
|
|
get isLanguageSwitchedMode => _isSelected[1];
|
|
get randomCard => Random().nextInt(widget.entries.length);
|
|
|
|
@override
|
|
void initState() {
|
|
title = encouragingWords[Random().nextInt(encouragingWords.length)];
|
|
currentCard = widget.index;
|
|
|
|
final isPhone = MediaQueryData.fromWindow(WidgetsBinding.instance!.window)
|
|
.size
|
|
.shortestSide <
|
|
600;
|
|
if (isPhone) {
|
|
SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.landscapeLeft,
|
|
DeviceOrientation.landscapeRight,
|
|
]);
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Scaffold(
|
|
appBar: AppBar(
|
|
title: Row(
|
|
children: [
|
|
Expanded(child: Container()),
|
|
Text(title),
|
|
Expanded(child: Container()),
|
|
IconButton(
|
|
onPressed: () => setState(() {
|
|
currentCard = 0;
|
|
}),
|
|
icon: const Icon(Icons.repeat),
|
|
),
|
|
ToggleButtons(
|
|
children: const [
|
|
Icon(Icons.shuffle),
|
|
Icon(Icons.translate),
|
|
],
|
|
isSelected: _isSelected,
|
|
onPressed: (int index) {
|
|
setState(() {
|
|
_isSelected[index] = !_isSelected[index];
|
|
});
|
|
})
|
|
],
|
|
),
|
|
centerTitle: true,
|
|
),
|
|
body: widget.isKanji
|
|
? Container()
|
|
: FlashcardPage(
|
|
card: widget.entries[currentCard] as YokutangoEntry,
|
|
index: currentCard,
|
|
languageFlipped: isLanguageSwitchedMode,
|
|
onNextCard: () {
|
|
setState(() {
|
|
currentCard = isShuffleMode ? randomCard : currentCard + 1;
|
|
if (currentCard == widget.entries.length) currentCard = 0;
|
|
title = encouragingWords[
|
|
Random().nextInt(encouragingWords.length)];
|
|
});
|
|
},
|
|
),
|
|
);
|
|
}
|