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

85 lines
2.4 KiB
Dart
Raw Normal View History

2022-01-26 00:25:07 +01:00
import 'package:tangocard_reader/components/flashcard.dart';
import 'package:flutter/material.dart';
2022-01-26 01:58:47 +01:00
import 'package:tangocard_reader/models/data_entry.dart';
2022-02-04 04:22:35 +01:00
import 'package:tangocard_reader/components/navigation_buttons.dart';
2022-01-26 00:25:07 +01:00
2022-01-29 19:16:13 +01:00
class FlashcardPage extends StatefulWidget {
2022-01-26 00:25:07 +01:00
final YokutangoEntry card;
2022-02-02 23:45:37 +01:00
final void Function() onNextCard;
final void Function() onPreviousCard;
2022-01-26 00:25:07 +01:00
final bool languageFlipped;
final int? index;
2022-01-29 19:16:13 +01:00
const FlashcardPage({
2022-01-26 00:25:07 +01:00
required this.card,
required this.onNextCard,
2022-02-02 23:45:37 +01:00
required this.onPreviousCard,
2022-01-26 00:25:07 +01:00
this.languageFlipped = false,
this.index,
Key? key,
}) : super(key: key);
@override
_FlashcardPageState createState() => _FlashcardPageState();
}
2022-01-29 19:16:13 +01:00
class _FlashcardPageState extends State<FlashcardPage> {
2022-01-26 00:25:07 +01:00
bool isPressed = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (isPressed) {
widget.onNextCard();
}
setState(() {
isPressed = !isPressed;
});
},
2022-02-02 23:45:37 +01:00
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flashcard(
card: widget.card,
cardIndex: widget.index,
isLeftSide: true,
languageFlipped: widget.languageFlipped,
),
const SizedBox(width: 40),
Flashcard(
card: isPressed ? widget.card : null,
cardIndex: widget.index,
languageFlipped: widget.languageFlipped,
),
],
),
Row(
children: [
const Expanded(child: SizedBox()),
NavigationButtons(
middleText:
widget.index == null ? 'N' : (widget.index! + 1).toString(),
onNextCard: () => setState(() {
isPressed = false;
widget.onNextCard();
}),
onPreviousCard: () => setState(() {
isPressed = false;
widget.onPreviousCard();
}),
),
const Expanded(child: SizedBox()),
],
)
],
2022-01-26 00:25:07 +01:00
),
);
}
}