add misc kanji utils
This commit is contained in:
parent
c1ccbc00b3
commit
5d3f3e2c87
|
@ -2,10 +2,10 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:tangocard_reader/models/data_entry.dart';
|
import 'package:tangocard_reader/models/data_entry.dart';
|
||||||
import 'package:tangocard_reader/models/router_args.dart';
|
import 'package:tangocard_reader/models/router_args.dart';
|
||||||
import 'package:tangocard_reader/screens/practise/flashcard.dart';
|
|
||||||
import 'package:tangocard_reader/screens/home.dart';
|
import 'package:tangocard_reader/screens/home.dart';
|
||||||
import 'package:tangocard_reader/screens/pages/tango_list.dart';
|
import 'package:tangocard_reader/screens/pages/tango_list.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:tangocard_reader/screens/practise/practise.dart';
|
||||||
|
|
||||||
import 'screens/pages/kanji_list.dart';
|
import 'screens/pages/kanji_list.dart';
|
||||||
|
|
||||||
|
@ -28,28 +28,28 @@ class PageRouter {
|
||||||
case '/benkyou/tango':
|
case '/benkyou/tango':
|
||||||
final benkyouArgs = args as BenkyouArgs;
|
final benkyouArgs = args as BenkyouArgs;
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => FlashcardView(
|
builder: (_) => PractiseView(
|
||||||
cards: benkyouArgs.cards as List<YokutangoEntry>,
|
entries: benkyouArgs.cards as List<YokutangoEntry>,
|
||||||
index: benkyouArgs.index,
|
index: benkyouArgs.index ?? 0,
|
||||||
|
isKanji: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
case '/benkyou/kanji':
|
case '/benkyou/kanji':
|
||||||
// final benkyouArgs = args as BenkyouArgs;
|
final benkyouArgs = args as BenkyouArgs;
|
||||||
// return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
// builder: (_) => FlashcardView(
|
builder: (_) => PractiseView(
|
||||||
// cards: benkyouArgs.cards as List<YokutangoEntry>,
|
entries: benkyouArgs.cards as List<KanjiEntry>,
|
||||||
// index: benkyouArgs.index,
|
index: benkyouArgs.index ?? 0,
|
||||||
// ),
|
isKanji: true,
|
||||||
// );
|
),
|
||||||
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => Scaffold(
|
builder: (_) => Scaffold(
|
||||||
appBar: AppBar(title: const Text('Error')),
|
appBar: AppBar(title: const Text('Error')),
|
||||||
body: Center(
|
body: Center(child: ErrorWidget('No such route...')),
|
||||||
child: ErrorWidget('No such route...')
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,123 +1,15 @@
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:tangocard_reader/components/flashcard.dart';
|
import 'package:tangocard_reader/components/flashcard.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:tangocard_reader/models/data_entry.dart';
|
import 'package:tangocard_reader/models/data_entry.dart';
|
||||||
|
|
||||||
class FlashcardView extends StatefulWidget {
|
class FlashcardPage extends StatefulWidget {
|
||||||
final List<YokutangoEntry> cards;
|
|
||||||
final int? index;
|
|
||||||
|
|
||||||
const FlashcardView({
|
|
||||||
required this.cards,
|
|
||||||
this.index,
|
|
||||||
Key? key,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
_FlashcardViewState createState() => _FlashcardViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
const encouragingWords = [
|
|
||||||
'頑張れ〜!',
|
|
||||||
'できるぞ!',
|
|
||||||
'ヨッシャー!',
|
|
||||||
'いけいけいけー!',
|
|
||||||
];
|
|
||||||
|
|
||||||
class _FlashcardViewState extends State<FlashcardView> {
|
|
||||||
String title = '';
|
|
||||||
int currentCard = 0;
|
|
||||||
final List<bool> _isSelected = [false, false];
|
|
||||||
|
|
||||||
get isShuffleMode => _isSelected[0];
|
|
||||||
get isLanguageSwitchedMode => _isSelected[1];
|
|
||||||
get randomCard => Random().nextInt(widget.cards.length);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
title = encouragingWords[Random().nextInt(encouragingWords.length)];
|
|
||||||
currentCard = widget.index ?? 0;
|
|
||||||
|
|
||||||
final isPhone = MediaQueryData.fromWindow(WidgetsBinding.instance!.window)
|
|
||||||
.size
|
|
||||||
.shortestSide <
|
|
||||||
600;
|
|
||||||
if (isPhone) {
|
|
||||||
SystemChrome.setPreferredOrientations([
|
|
||||||
DeviceOrientation.landscapeLeft,
|
|
||||||
DeviceOrientation.landscapeRight,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
SystemChrome.setPreferredOrientations([
|
|
||||||
DeviceOrientation.portraitDown,
|
|
||||||
DeviceOrientation.portraitUp,
|
|
||||||
DeviceOrientation.landscapeLeft,
|
|
||||||
DeviceOrientation.landscapeRight,
|
|
||||||
]);
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return 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: _FlashcardPage(
|
|
||||||
card: widget.cards[currentCard],
|
|
||||||
index: currentCard,
|
|
||||||
languageFlipped: isLanguageSwitchedMode,
|
|
||||||
onNextCard: () {
|
|
||||||
setState(() {
|
|
||||||
currentCard = isShuffleMode ? randomCard : currentCard + 1;
|
|
||||||
if (currentCard == widget.cards.length) currentCard = 0;
|
|
||||||
title = encouragingWords[Random().nextInt(encouragingWords.length)];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FlashcardPage extends StatefulWidget {
|
|
||||||
final YokutangoEntry card;
|
final YokutangoEntry card;
|
||||||
final Function() onNextCard;
|
final Function() onNextCard;
|
||||||
final bool languageFlipped;
|
final bool languageFlipped;
|
||||||
final int? index;
|
final int? index;
|
||||||
|
|
||||||
const _FlashcardPage({
|
const FlashcardPage({
|
||||||
required this.card,
|
required this.card,
|
||||||
required this.onNextCard,
|
required this.onNextCard,
|
||||||
this.languageFlipped = false,
|
this.languageFlipped = false,
|
||||||
|
@ -129,7 +21,7 @@ class _FlashcardPage extends StatefulWidget {
|
||||||
_FlashcardPageState createState() => _FlashcardPageState();
|
_FlashcardPageState createState() => _FlashcardPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FlashcardPageState extends State<_FlashcardPage> {
|
class _FlashcardPageState extends State<FlashcardPage> {
|
||||||
bool isPressed = false;
|
bool isPressed = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../models/data_entry.dart';
|
||||||
|
|
||||||
|
class KanjiPage extends StatefulWidget {
|
||||||
|
final KanjiEntry entry;
|
||||||
|
final Function() onNextCard;
|
||||||
|
final int? index;
|
||||||
|
|
||||||
|
const KanjiPage({
|
||||||
|
required this.entry,
|
||||||
|
required this.onNextCard,
|
||||||
|
this.index,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_KanjiPageState createState() => _KanjiPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _KanjiPageState extends State<KanjiPage> {
|
||||||
|
bool isPressed = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (isPressed) widget.onNextCard();
|
||||||
|
setState(() => isPressed = !isPressed);
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(widget.entry.kanji),
|
||||||
|
const SizedBox(width: 40),
|
||||||
|
Text(widget.entry.kana.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
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)];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue