-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restructured and refactored entire project (#19)
feat: added pagination using Provider feat: added dynamic routing refactor: updated project to use relative imports refactor: review.dart -> review_page.dart refactor: lesson.dart -> lesson_page.dart refactor: manage_page -> profile_page.dart
- Loading branch information
Showing
21 changed files
with
716 additions
and
868 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,4 @@ google-services.json | |
GoogleService-Info.plist | ||
.vscode/* | ||
src/lib/tests/* | ||
scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class FlashcardModel { | ||
String cardId; | ||
String deckId; | ||
String title; | ||
String instructions; | ||
String image; | ||
|
||
FlashcardModel( | ||
{required this.cardId, | ||
required this.deckId, | ||
required this.title, | ||
required this.instructions, | ||
required this.image}); | ||
|
||
factory FlashcardModel.fromMap( | ||
Map<String, dynamic> data, | ||
String cardId, | ||
String deckId, | ||
) { | ||
return FlashcardModel( | ||
cardId: cardId, | ||
deckId: deckId, | ||
title: data['title'] as String, | ||
instructions: data['instructions'] as String, | ||
image: data['image'] as String, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class LessonModel { | ||
final String title; | ||
final String description; | ||
final String id; | ||
final int cardsCompleted; | ||
final int cardsTotal; | ||
|
||
LessonModel({ | ||
required this.cardsCompleted, | ||
required this.cardsTotal, | ||
required this.title, | ||
required this.description, | ||
required this.id, | ||
}); | ||
|
||
factory LessonModel.fromMap(id, cardsCompleted, Map<String, dynamic> data) => | ||
LessonModel( | ||
cardsCompleted: cardsCompleted, | ||
cardsTotal: data['cardCount'], | ||
title: data['title'], | ||
description: data['description'], | ||
id: id, | ||
); | ||
|
||
LessonModel copyWith({ | ||
int? cardsCompleted, | ||
int? cardsTotal, | ||
String? title, | ||
String? description, | ||
String? id, | ||
}) => | ||
LessonModel( | ||
cardsCompleted: cardsCompleted ?? this.cardsCompleted, | ||
cardsTotal: cardsTotal ?? this.cardsTotal, | ||
title: title ?? this.title, | ||
description: description ?? this.description, | ||
id: id ?? this.id, | ||
); | ||
|
||
void navigateToLesson(BuildContext context) => Navigator.pushNamed( | ||
context, | ||
'/${title.toLowerCase().replaceAll(' ', '_')}', | ||
arguments: { | ||
'lesson': this, | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class ReviewModel { | ||
final String deckId; | ||
final String deckTitle; | ||
final String deckDescription; | ||
final String cardId; | ||
final String cardTitle; | ||
final String cardInstructions; | ||
final String cardImage; | ||
|
||
ReviewModel({ | ||
required this.cardTitle, | ||
required this.cardInstructions, | ||
required this.cardImage, | ||
required this.deckTitle, | ||
required this.deckDescription, | ||
required this.cardId, | ||
required this.deckId, | ||
}); | ||
|
||
factory ReviewModel.fromMap(cardId, Map<String, dynamic> data) => ReviewModel( | ||
cardId: cardId, | ||
cardTitle: data['title'], | ||
cardInstructions: data['instructions'], | ||
cardImage: data['image'], | ||
deckTitle: data['deckTitle'], | ||
deckDescription: data['deckDescription'], | ||
deckId: data['deckId'], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../models/lesson_model.dart'; | ||
import '../models/flashcard_model.dart'; | ||
import '../widgets/flashcard.dart'; | ||
|
||
class Lesson extends StatefulWidget { | ||
const Lesson({super.key, required this.lesson}); | ||
final LessonModel lesson; | ||
|
||
@override | ||
State<Lesson> createState() => _LessonState(); | ||
} | ||
|
||
class _LessonState extends State<Lesson> { | ||
int _currentCardIndex = 0; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// TODO optional: quiz minigame at end of lesson or loop | ||
|
||
return WillPopScope( | ||
onWillPop: () async { | ||
return true; | ||
}, | ||
child: Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.lesson.title), | ||
), | ||
body: FutureBuilder<QuerySnapshot>( | ||
future: _getCardsFuture(), | ||
builder: (context, snapshot) => snapshot.hasData | ||
? Column( | ||
mainAxisSize: MainAxisSize.max, | ||
children: [ | ||
_buildFlashcards(snapshot.data!.docs), | ||
// TODO set prograss indicator location fixed to bottom of screen | ||
_buildProgressTextIndicator(), | ||
_buildProgressBarIndicator(), | ||
], | ||
) | ||
: const Center(child: CircularProgressIndicator()))), | ||
); | ||
} | ||
|
||
Future<QuerySnapshot> _getCardsFuture() => FirebaseFirestore.instance | ||
.collection("decks") | ||
.doc(widget.lesson.id) | ||
.collection('cards') | ||
.get(); | ||
|
||
void _handleIndex() => setState(() { | ||
bool isCompleted = _currentCardIndex == widget.lesson.cardsTotal - 1; | ||
if (isCompleted) { | ||
Navigator.pop(context); | ||
} else { | ||
_currentCardIndex++; | ||
} | ||
}); | ||
|
||
List<Widget> _getFlashcards(List<QueryDocumentSnapshot> cards) => cards | ||
.map((card) => Flashcard( | ||
card: FlashcardModel.fromMap( | ||
card.data() as Map<String, dynamic>, card.id, widget.lesson.id), | ||
handleIndex: _handleIndex, | ||
isReview: false, | ||
)) | ||
.toList(); | ||
|
||
Widget _buildFlashcards(List<QueryDocumentSnapshot<Object?>> cards) => | ||
Padding( | ||
padding: const EdgeInsets.only(top: 20.0), | ||
child: IndexedStack( | ||
index: _currentCardIndex, | ||
children: _getFlashcards(cards), | ||
), | ||
); | ||
|
||
Widget _buildProgressTextIndicator() { | ||
return Container( | ||
padding: const EdgeInsets.all(8.0), | ||
alignment: Alignment.centerRight, | ||
child: Text('${_currentCardIndex + 1} / ${widget.lesson.cardsTotal}')); | ||
} | ||
|
||
Widget _buildProgressBarIndicator() { | ||
return TweenAnimationBuilder( | ||
tween: Tween<double>( | ||
begin: _currentCardIndex / widget.lesson.cardsTotal, | ||
end: (_currentCardIndex + 1) / widget.lesson.cardsTotal), | ||
duration: const Duration(milliseconds: 1000), | ||
builder: (context, double value, child) => | ||
LinearProgressIndicator(value: value)); | ||
} | ||
} |
Oops, something went wrong.