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

85 lines
2.4 KiB
Dart

import 'package:tangocard_reader/components/flashcard.dart';
import 'package:flutter/material.dart';
import 'package:tangocard_reader/models/data_entry.dart';
import 'package:tangocard_reader/components/navigation_buttons.dart';
class FlashcardPage extends StatefulWidget {
final YokutangoEntry card;
final void Function() onNextCard;
final void Function() onPreviousCard;
final bool languageFlipped;
final int? index;
const FlashcardPage({
required this.card,
required this.onNextCard,
required this.onPreviousCard,
this.languageFlipped = false,
this.index,
Key? key,
}) : super(key: key);
@override
_FlashcardPageState createState() => _FlashcardPageState();
}
class _FlashcardPageState extends State<FlashcardPage> {
bool isPressed = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (isPressed) {
widget.onNextCard();
}
setState(() {
isPressed = !isPressed;
});
},
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()),
],
)
],
),
);
}
}