added first working prototype of flashcards

This commit is contained in:
odweta
2026-04-02 20:35:09 +02:00
parent 51ce826de6
commit eae9e34ddf
4 changed files with 68 additions and 13 deletions
+2 -1
View File
@@ -62,7 +62,8 @@ class HlaskovnikFrontendApp extends StatelessWidget {
),
useMaterial3: true,
),
themeMode: ThemeMode.system,
//themeMode: ThemeMode.system, // TODO: .dark is just for testing
themeMode: ThemeMode.dark,
routerConfig: _router,
);
}
+37 -12
View File
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:frontend/provider/quote_provider.dart';
import 'package:frontend/model/quote.dart';
import 'package:provider/provider.dart';
@@ -15,6 +14,8 @@ class FlashcardsPage extends StatelessWidget {
Widget build(BuildContext context) {
//return const Center(child: Text('flashcards! flip flip'));
final provider = Provider.of<QuoteProvider>(context);
if (provider.randomQuoteText == "dummy" ||
provider.randomQuoteText == "quote text") { provider.nextRandomQuote(); } // initialize the random quote variable
return Card(
margin: const EdgeInsets.all(Constants.edgeInset),
child: Padding(
@@ -22,22 +23,46 @@ class FlashcardsPage extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('insert random quote body here'),
Padding(
padding: const EdgeInsets.all(Constants.edgeInset*2),
child: Text(provider.randomQuoteText,
style: TextStyle(
fontSize: 35,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
child: Text('flip around'),
onPressed: () {
// TODO: flip the card
},
Padding(
padding: const EdgeInsets.all(Constants.edgeInset),
child: TextButton.icon(
onPressed: provider.flipRandomQuote,
icon: Icon(Icons.repeat,
size: 35,
),
label: Text(Strings.flipFlashcard,
style: TextStyle(
fontSize: 35,
),
),
),
),
TextButton(
child: Text('next card'),
onPressed: () {
// TODO: next random card
},
Padding(
padding: const EdgeInsets.all(Constants.edgeInset),
child: TextButton.icon(
onPressed: provider.nextRandomQuote,
icon: Icon(Icons.arrow_right_alt,
size: 35,
),
label: Text(Strings.nextFlashcard,
style: TextStyle(
fontSize: 35,
),
),
),
),
],
),
+26
View File
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:frontend/model/quote.dart';
import 'package:frontend/repository/quote_repository.dart';
import 'dart:math';
class QuoteProvider extends ChangeNotifier {
List<Quote> _quotes = [];
@@ -44,6 +45,31 @@ class QuoteProvider extends ChangeNotifier {
filterController.text = '';
}
Quote randomQuote = Quote(
id: 0,
body: "quote text",
author: "dummy"
);
bool randomQuoteDeterminator = true;
String get randomQuoteText {
if (randomQuoteDeterminator) {
return randomQuote.body;
} else {
return randomQuote.author;
}
}
void flipRandomQuote() {
randomQuoteDeterminator = !randomQuoteDeterminator;
notifyListeners();
}
void nextRandomQuote() {
final random = Random();
randomQuote = filteredQuotes[random.nextInt(filteredQuotes.length)];
notifyListeners();
}
void filterQuotes() {
notifyListeners();
}
+3
View File
@@ -19,6 +19,9 @@ class Strings {
static const String quote = "Hláška";
static const String author = "Autor";
static const String flipFlashcard = "Otočit flashkartu";
static const String nextFlashcard = "Další flashkarta";
static const String noUndo = "Tuto akci nelze odčinit.";
static const String filterQuery = "Filtrovací požadavek";
static const String allQuotesCount = "Celkový počet hlášek";