Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/validations #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions study_cards/lib/components/add_card_related/card_back.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class CardBack extends StatelessWidget {
child: Column(
children: [
TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderSide:
BorderSide(color: Color.fromARGB(255, 146, 146, 146)),
),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Color.fromARGB(255, 146, 146, 146)),
),
),
controller: controller.backTextController,
maxLines: null,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import '../../controllers/add_card_controller.dart';

class ChangeCardSideButton extends StatelessWidget {
AddCardController controller;
ChangeCardSideButton({super.key, required this.controller});
Function() changeSide;
ChangeCardSideButton({super.key, required this.controller, required this.changeSide});

@override
Widget build(BuildContext context) {
return ElevatedButton.icon(
onPressed: () {
controller.changeCardSide();
},
onPressed: () => changeSide(),
icon: const Icon(Icons.change_circle_outlined),
label: controller.animationStatus == AnimationStatus.dismissed
label: controller.showFrontSide
? const Text("front")
: const Text("back"));
}
Expand Down
34 changes: 16 additions & 18 deletions study_cards/lib/components/add_card_related/show_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:math';

import 'package:flip_card/flip_card.dart';
import 'package:flutter/material.dart';
import 'package:scribble/scribble.dart';
import '../../controllers/add_card_controller.dart';
Expand All @@ -23,24 +24,21 @@ class ShowCard extends StatelessWidget {
return SizedBox(
height: MediaQuery.of(context).size.height / 2,
width: MediaQuery.of(context).size.width / 2,
child: Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(2, 1, 0.0015)
..rotateY(pi * controller.animation.value),
child: controller.animation.value <= 0.5
? CardFront(
controller: controller,
allowShowingImage: allowShowingImage,
alternateEraser: alternateEraser,
changeStroke: changeStroke,
)
: CardBack(
controller: controller,
allowShowingImage: allowShowingImage,
alternateEraser: alternateEraser,
changeStroke: changeStroke,
),
child: FlipCard(
controller: controller.flipCardController,
flipOnTouch: false,
front: CardFront(
controller: controller,
allowShowingImage: allowShowingImage,
alternateEraser: alternateEraser,
changeStroke: changeStroke,
),
back: CardBack(
controller: controller,
allowShowingImage: allowShowingImage,
alternateEraser: alternateEraser,
changeStroke: changeStroke,
),
),
);
}
Expand Down
29 changes: 5 additions & 24 deletions study_cards/lib/components/folder_view_related/card_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:study_cards/components/study_cards_related/dificulty_list.dart';
import 'package:study_cards/controllers/folder_controller.dart';
import 'package:study_cards/models/card_model.dart';

class CardDialog extends StatelessWidget {
final CardModel card;
final FolderController controller;
Function(CardModel) updateCardsToStudy;
Function(Duration) updateCard;
CardDialog(
{super.key,
required this.controller,
required this.card,
required this.updateCardsToStudy});
required this.updateCardsToStudy,
required this.updateCard});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -71,29 +74,7 @@ class CardDialog extends StatelessWidget {
),
Visibility(
visible: controller.showBack,
child: Row(
children: [
Slider(
min: 0,
max: 3,
value:
controller.cardDificulty.toDouble(),
onChanged: (value) => setState(
() {
controller.cardDificulty =
value.toInt();
controller.setTimeToStudy();
},
)),
Text(controller.showDificultyLabel()),
Text(controller.timeToStudy.toString()),
ElevatedButton(
onPressed: () => setState(() {
updateCardsToStudy(card);
}),
child: const Text("OK"))
],
),
child: DificultyList(updateCard: updateCard,)
),
],
),
Expand Down
1 change: 1 addition & 0 deletions study_cards/lib/components/folder_view_related/cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Cards extends StatelessWidget {
),
onTap: () {
controller.showBack = false;
controller.indexCardShowing = index;
showCardDialog(context, controller.folder.cards[index]);
},
);
Expand Down
31 changes: 20 additions & 11 deletions study_cards/lib/controllers/add_card_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:flip_card/flip_card_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:scribble/scribble.dart';
Expand All @@ -15,7 +16,7 @@ class AddCardController{
TextEditingController frontTextController = TextEditingController();
TextEditingController backTextController = TextEditingController();
double stroke = 1;

bool eraseSelected = false;

bool showFrontSide = true;
Expand All @@ -36,17 +37,25 @@ class AddCardController{

bool highlightFrontText = false;

bool createCardValidated = true;

FlipCardController flipCardController = FlipCardController();

AddCardController(this.folder);

void changeCardSide(){
updateImage();
if (animationStatus == AnimationStatus.dismissed) {
showFrontSide = false;
animationController.forward();
} else {
showFrontSide = true;
animationController.reverse();
bool validateCard(){
if(folder.cards.map((e) => e.frontDescription).contains(frontTextController.text)){
createCardValidated = false;
return false;
}
createCardValidated = true;
return true;
}

Future<void> changeCardSide() async{
updateImage();
await flipCardController.toggleCard();
showFrontSide = !showFrontSide;
}

Future<void> updateImage() async{
Expand All @@ -65,11 +74,11 @@ class AddCardController{
await updateImage();

if(imageFront != null && showImageFront){
File fileFront = File("${FileManager.instance.getFolderImagePath(folder)}\\${frontTextController.text}0");
File fileFront = File("${FileManager.instance.getFolderImagePath(folder)}\\${frontTextController.text.replaceAll(RegExp('[^A-Za-z0-9]'), '')}0");
fileFront.writeAsBytes(imageFront!.buffer.asUint8List());
}
if(imageBack != null && showImageBack){
File fileBack = File("${FileManager.instance.getFolderImagePath(folder)}\\${frontTextController.text}1");
File fileBack = File("${FileManager.instance.getFolderImagePath(folder)}\\${frontTextController.text.replaceAll(RegExp('[^A-Za-z0-9]'), '')}1");
fileBack.writeAsBytes(imageBack!.buffer.asUint8List());
}

Expand Down
16 changes: 11 additions & 5 deletions study_cards/lib/controllers/folder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class FolderController{
int cardDificulty = 0 ;
Duration timeToStudy = const Duration(minutes:0);


int indexCardShowing = 0;

List<CardModel> cardsToStudy = [];

FolderController(this.folder);
Expand Down Expand Up @@ -67,8 +68,8 @@ class FolderController{

Future<void> _deleteImages(CardModel card, FolderModel folder) async{
String folderPath = FileManager.instance.getFolderImagePath(folder);
File file0 = File("$folderPath\\${card.frontDescription}0");
File file1 = File("$folderPath\\${card.frontDescription}1");
File file0 = File("$folderPath\\${card.frontDescription.replaceAll(RegExp('[^A-Za-z0-9]'), '')}0");
File file1 = File("$folderPath\\${card.frontDescription.replaceAll(RegExp('[^A-Za-z0-9]'), '')}1");
if(await file0.exists()){
file0.delete();
}
Expand Down Expand Up @@ -115,9 +116,9 @@ class FolderController{

Future<void> prepareImages(CardModel card) async {
String folderPath = FileManager.instance.getFolderImagePath(folder);
frontCardFile = File("$folderPath\\${card.frontDescription}0");
frontCardFile = File("$folderPath\\${card.frontDescription.replaceAll(RegExp('[^A-Za-z0-9]'), '')}0");
frontCardExists = await frontCardFile.exists();
backCardFile = File("$folderPath\\${card.frontDescription}1");
backCardFile = File("$folderPath\\${card.frontDescription.replaceAll(RegExp('[^A-Za-z0-9]'), '')}1");
backCardExists = await backCardFile.exists();
}

Expand All @@ -132,5 +133,10 @@ class FolderController{
const timeToStudy = Duration(minutes: 0);
}
}

void updateCard(Duration duration) {
folder.cards[indexCardShowing].timeToStudy = DateTime.now().add(duration);
FileManager.instance.saveCards();
}

}
10 changes: 8 additions & 2 deletions study_cards/lib/views/add_card_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class _AddCardPageState extends State<AddCardPage>
});
}

void changeSide(){
setState(() {
controller.changeCardSide();
});
}

void _changeStroke(double value, ScribbleNotifier notifier) {
setState(() {
controller.stroke = value;
Expand All @@ -73,7 +79,7 @@ class _AddCardPageState extends State<AddCardPage>

void _addCard() {
setState(() {
if (controller.frontTextController.text.replaceAll(" ", "") != "") {
if (controller.frontTextController.text.replaceAll(" ", "") != "" && controller.validateCard()) {
controller.addCard();
Navigator.of(context).pop();
Navigator.of(context).push(
Expand Down Expand Up @@ -111,7 +117,7 @@ class _AddCardPageState extends State<AddCardPage>
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ChangeCardSideButton(controller: controller),
ChangeCardSideButton(controller: controller, changeSide: changeSide,),
ShowCard(
controller: controller,
allowShowingImage: _allowShowingImage,
Expand Down
8 changes: 7 additions & 1 deletion study_cards/lib/views/folders_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class _FolderPageState extends State<FolderPage> {
folderController = FolderController(folder);
}

void updateCard(Duration duration) {
setState(() {
folderController.updateCard(duration);
});
}

addFolder() {
setState(() {
folderController.folderCreateValidated = true;
Expand Down Expand Up @@ -146,7 +152,7 @@ class _FolderPageState extends State<FolderPage> {
// ignore: use_build_context_synchronously
showDialog(
context: context,
builder: (context) => CardDialog(controller: folderController, card: card, updateCardsToStudy: _updateCardsToStudy),
builder: (context) => CardDialog(controller: folderController, card: card, updateCardsToStudy: _updateCardsToStudy, updateCard: updateCard,),
);
}

Expand Down
54 changes: 0 additions & 54 deletions study_cards/lib/views/login_page.dart

This file was deleted.

8 changes: 8 additions & 0 deletions study_cards/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.4"
flip_card:
dependency: "direct main"
description:
name: flip_card
sha256: "5d4aa58f3983cced0782f4ce45826b7eea36e8e464964d9209dcbc7a87b2292f"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions study_cards/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:
sdk: '>=2.19.1 <4.0.0'

dependencies:
flip_card: ^0.7.0
flutter:
sdk: flutter
flutter_spinbox: ^0.12.0
Expand Down