added first working prototype of flashcards
This commit is contained in:
@@ -62,7 +62,8 @@ class HlaskovnikFrontendApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
themeMode: ThemeMode.system,
|
//themeMode: ThemeMode.system, // TODO: .dark is just for testing
|
||||||
|
themeMode: ThemeMode.dark,
|
||||||
routerConfig: _router,
|
routerConfig: _router,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:frontend/provider/quote_provider.dart';
|
import 'package:frontend/provider/quote_provider.dart';
|
||||||
import 'package:frontend/model/quote.dart';
|
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -15,6 +14,8 @@ class FlashcardsPage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
//return const Center(child: Text('flashcards! flip flip'));
|
//return const Center(child: Text('flashcards! flip flip'));
|
||||||
final provider = Provider.of<QuoteProvider>(context);
|
final provider = Provider.of<QuoteProvider>(context);
|
||||||
|
if (provider.randomQuoteText == "dummy" ||
|
||||||
|
provider.randomQuoteText == "quote text") { provider.nextRandomQuote(); } // initialize the random quote variable
|
||||||
return Card(
|
return Card(
|
||||||
margin: const EdgeInsets.all(Constants.edgeInset),
|
margin: const EdgeInsets.all(Constants.edgeInset),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@@ -22,22 +23,46 @@ class FlashcardsPage extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text('insert random quote body here'),
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(Constants.edgeInset*2),
|
||||||
|
child: Text(provider.randomQuoteText,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
TextButton(
|
Padding(
|
||||||
child: Text('flip around'),
|
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||||
onPressed: () {
|
child: TextButton.icon(
|
||||||
// TODO: flip the card
|
onPressed: provider.flipRandomQuote,
|
||||||
},
|
icon: Icon(Icons.repeat,
|
||||||
|
size: 35,
|
||||||
|
),
|
||||||
|
label: Text(Strings.flipFlashcard,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
Padding(
|
||||||
child: Text('next card'),
|
padding: const EdgeInsets.all(Constants.edgeInset),
|
||||||
onPressed: () {
|
child: TextButton.icon(
|
||||||
// TODO: next random card
|
onPressed: provider.nextRandomQuote,
|
||||||
},
|
icon: Icon(Icons.arrow_right_alt,
|
||||||
|
size: 35,
|
||||||
|
),
|
||||||
|
label: Text(Strings.nextFlashcard,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import 'package:frontend/model/quote.dart';
|
import 'package:frontend/model/quote.dart';
|
||||||
import 'package:frontend/repository/quote_repository.dart';
|
import 'package:frontend/repository/quote_repository.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
class QuoteProvider extends ChangeNotifier {
|
class QuoteProvider extends ChangeNotifier {
|
||||||
List<Quote> _quotes = [];
|
List<Quote> _quotes = [];
|
||||||
@@ -44,6 +45,31 @@ class QuoteProvider extends ChangeNotifier {
|
|||||||
filterController.text = '';
|
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() {
|
void filterQuotes() {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ class Strings {
|
|||||||
static const String quote = "Hláška";
|
static const String quote = "Hláška";
|
||||||
static const String author = "Autor";
|
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 noUndo = "Tuto akci nelze odčinit.";
|
||||||
static const String filterQuery = "Filtrovací požadavek";
|
static const String filterQuery = "Filtrovací požadavek";
|
||||||
static const String allQuotesCount = "Celkový počet hlášek";
|
static const String allQuotesCount = "Celkový počet hlášek";
|
||||||
|
|||||||
Reference in New Issue
Block a user