diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 39a0d06..560c10f 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -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, ); } diff --git a/frontend/lib/pages/flashcards.dart b/frontend/lib/pages/flashcards.dart index f2973c4..17e4f07 100644 --- a/frontend/lib/pages/flashcards.dart +++ b/frontend/lib/pages/flashcards.dart @@ -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(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, + ), + ), + ), ), ], ), diff --git a/frontend/lib/provider/quote_provider.dart b/frontend/lib/provider/quote_provider.dart index 6c9d758..9d5894e 100644 --- a/frontend/lib/provider/quote_provider.dart +++ b/frontend/lib/provider/quote_provider.dart @@ -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 _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(); } diff --git a/frontend/lib/values/strings.dart b/frontend/lib/values/strings.dart index 306cd05..57756d0 100644 --- a/frontend/lib/values/strings.dart +++ b/frontend/lib/values/strings.dart @@ -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";