yokutango-mobile-reader/lib/screens/practise/kanji.dart

110 lines
3.2 KiB
Dart
Raw Normal View History

2022-01-29 19:16:13 +01:00
import 'package:flutter/material.dart';
2022-02-04 04:22:35 +01:00
import 'package:signature/signature.dart';
2022-01-29 19:16:13 +01:00
import '../../models/data_entry.dart';
2022-02-04 04:22:35 +01:00
import '../../components/navigation_buttons.dart';
2022-01-29 19:16:13 +01:00
class KanjiPage extends StatefulWidget {
final KanjiEntry entry;
final Function() onNextCard;
2022-02-02 23:45:37 +01:00
final Function() onPreviousCard;
final bool showDrawingPanel;
final bool showStrokeOrder;
2022-01-29 19:16:13 +01:00
final int? index;
const KanjiPage({
required this.entry,
required this.onNextCard,
2022-02-02 23:45:37 +01:00
required this.onPreviousCard,
this.showDrawingPanel = false,
this.showStrokeOrder = false,
2022-01-29 19:16:13 +01:00
this.index,
Key? key,
}) : super(key: key);
@override
_KanjiPageState createState() => _KanjiPageState();
}
class _KanjiPageState extends State<KanjiPage> {
bool isPressed = false;
2022-02-04 04:22:35 +01:00
late final controller = SignatureController(
penColor: Theme.of(context).textTheme.bodyText1?.color ?? Colors.black,
);
2022-01-29 19:16:13 +01:00
@override
Widget build(BuildContext context) {
return GestureDetector(
2022-02-02 23:45:37 +01:00
behavior: HitTestBehavior.opaque,
2022-01-29 19:16:13 +01:00
onTap: () {
2022-02-04 04:22:35 +01:00
if (widget.showDrawingPanel) return;
if (isPressed) {
controller.clear();
widget.onNextCard();
}
2022-01-29 19:16:13 +01:00
setState(() => isPressed = !isPressed);
},
2022-02-02 23:45:37 +01:00
child: Stack(
alignment: Alignment.center,
fit: StackFit.expand,
children: [
2022-02-04 04:22:35 +01:00
if (widget.showDrawingPanel) ...[
const SizedBox(width: 20),
Signature(
controller: controller,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
)
],
2022-02-02 23:45:37 +01:00
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
widget.entry.kana.join('\n'),
style: Theme.of(context).textTheme.headline3,
),
const SizedBox(width: 20),
const Divider(thickness: 5),
2022-02-04 04:22:35 +01:00
const SizedBox(width: 20),
Text(
widget.entry.kanji,
style: isPressed
? Theme.of(context).textTheme.headline1
: Theme.of(context)
.textTheme
.headline1
?.merge(const TextStyle(color: Colors.transparent)),
),
const SizedBox(width: 20),
const Divider(thickness: 5),
2022-02-02 23:45:37 +01:00
],
),
Positioned(
bottom: 40,
child: NavigationButtons(
middleText:
widget.index == null ? 'N' : (widget.index! + 1).toString(),
2022-02-04 04:22:35 +01:00
onMiddlePressed: () {
if (isPressed) {
controller.clear();
widget.onNextCard();
}
setState(() => isPressed = !isPressed);
},
2022-02-02 23:45:37 +01:00
onNextCard: () => setState(() {
2022-02-04 04:22:35 +01:00
controller.clear();
2022-02-02 23:45:37 +01:00
isPressed = false;
widget.onNextCard();
}),
onPreviousCard: () => setState(() {
2022-02-04 04:22:35 +01:00
controller.clear();
2022-02-02 23:45:37 +01:00
isPressed = false;
widget.onPreviousCard();
}),
),
)
],
2022-01-29 19:16:13 +01:00
),
);
}
}