Skip to content

Commit b2eb202

Browse files
committed
[Refactor] Extracted a widget to make the code better readable and maintainable.
1 parent 3a443e0 commit b2eb202

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:flashcard_project/design_system.dart';
2+
import 'package:flashcard_project/ui/screen/lesson_selector_screen.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class CompletionWidget extends StatelessWidget {
6+
final VoidCallback onPressed;
7+
const CompletionWidget({required this.onPressed, Key? key}) : super(key: key);
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return Column(
12+
mainAxisAlignment: MainAxisAlignment.center,
13+
children: [
14+
const Text("Congratulations! You finished all your cards."),
15+
const SizedBox(height: Insets.medium),
16+
ElevatedButton(
17+
onPressed: onPressed,
18+
child: const Text("Repeat Lesson"),
19+
),
20+
const SizedBox(height: Insets.medium),
21+
ElevatedButton(
22+
onPressed: () {
23+
LessonSelectorScreen.navigateTo(context);
24+
},
25+
child: const Text("Back to Lecture Selection"),
26+
)
27+
],
28+
);
29+
}
30+
}

lib/ui/screen/home_page.dart

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flashcard_project/design_system.dart';
22
import 'package:flashcard_project/domain/flashcard_service.dart';
33
import 'package:flashcard_project/repository/sheet_repo.dart';
4-
import 'package:flashcard_project/ui/screen/lesson_selector_screen.dart';
4+
import 'package:flashcard_project/ui/screen/home/completion_widget.dart';
55
import 'package:flutter/material.dart';
66

77
class HomePage extends StatefulWidget {
@@ -69,7 +69,9 @@ class _HomePageState extends State<HomePage> {
6969
if (snapshot.hasData) {
7070
return Expanded(
7171
child: allCardsFinished
72-
? _buildLoadingSpinner()
72+
? CompletionWidget(onPressed: () {
73+
init = startLesson();
74+
})
7375
: IgnorePointer(
7476
ignoring: cardFlipped,
7577
child: InkWell(
@@ -148,27 +150,4 @@ class _HomePageState extends State<HomePage> {
148150
currentQuestionAndAnswer = questionAnswerList.removeAt(0);
149151
});
150152
}
151-
152-
Column _buildLoadingSpinner() {
153-
return Column(
154-
mainAxisAlignment: MainAxisAlignment.center,
155-
children: [
156-
const Text("Congratulations! You finished all your cards."),
157-
const SizedBox(height: Insets.medium),
158-
ElevatedButton(
159-
onPressed: () {
160-
init = startLesson();
161-
},
162-
child: const Text("Repeat Lesson"),
163-
),
164-
const SizedBox(height: Insets.medium),
165-
ElevatedButton(
166-
onPressed: () {
167-
LessonSelectorScreen.navigateTo(context);
168-
},
169-
child: const Text("Back to Lecture Selection"),
170-
)
171-
],
172-
);
173-
}
174153
}

0 commit comments

Comments
 (0)