-
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.
Merge pull request #70 from ia-toki/quiz-start-page
Quiz Start Page
- Loading branch information
Showing
9 changed files
with
262 additions
and
67 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
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
42 changes: 42 additions & 0 deletions
42
app/lib/features/quiz_start/presentation/bloc/quiz_start_cubit.dart
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,42 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import '../../../../models/quiz_participation.dart'; | ||
import '../../../../models/weekly_quiz.dart'; | ||
import '../../../../services/quiz_service.dart'; | ||
|
||
part 'quiz_start_state.dart'; | ||
|
||
class QuizStartCubit extends Cubit<QuizStartState> { | ||
QuizStartCubit() : super(QuizStartInitial()); | ||
|
||
bool agreement = false; | ||
late WeeklyQuiz quiz; | ||
late WeeklyQuizParticipation participation; | ||
|
||
Future<void> initialize(String? quizParticipantId) async { | ||
try { | ||
final quizService = QuizService(); | ||
|
||
if (quizParticipantId == null) { | ||
throw Exception('QuizParticipantId is null'); | ||
} | ||
|
||
participation = await quizService.getWeeklyQuizParticipant( | ||
quizParticipantId: quizParticipantId); | ||
|
||
quiz = await quizService.getWeeklyQuizById(participation.quiz_id); | ||
|
||
emit(QuizStartSuccess( | ||
participation: participation, quiz: quiz, agreement: agreement)); | ||
} catch (e) { | ||
emit(QuizStartFailed(e.toString())); | ||
} | ||
} | ||
|
||
void setAgreement(bool value) { | ||
agreement = value; | ||
emit(QuizStartSuccess( | ||
participation: participation, quiz: quiz, agreement: agreement)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/lib/features/quiz_start/presentation/bloc/quiz_start_state.dart
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 @@ | ||
part of 'quiz_start_cubit.dart'; | ||
|
||
@immutable | ||
abstract class QuizStartState {} | ||
|
||
class QuizStartInitial extends QuizStartState {} | ||
|
||
class QuizStartSuccess extends QuizStartState { | ||
final WeeklyQuizParticipation participation; | ||
final WeeklyQuiz quiz; | ||
final bool agreement; | ||
|
||
QuizStartSuccess( | ||
{required this.participation, | ||
required this.quiz, | ||
required this.agreement}); | ||
@override | ||
List<Object> get props => [participation, quiz, agreement]; | ||
} | ||
|
||
class QuizStartFailed extends QuizStartState { | ||
final String error; | ||
|
||
QuizStartFailed(this.error); | ||
|
||
@override | ||
List<Object> get props => [error]; | ||
} |
11 changes: 11 additions & 0 deletions
11
app/lib/features/quiz_start/presentation/pages/_pages.dart
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,11 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
import '../../../../core/bases/enum/button_type.dart'; | ||
import '../../../../core/bases/widgets/atoms/button.dart'; | ||
import '../../../../core/bases/widgets/layout/bebras_scaffold.dart'; | ||
import '../../../../core/constants/assets.dart'; | ||
import '../bloc/quiz_start_cubit.dart'; | ||
|
||
part 'quiz_start_page.dart'; |
Oops, something went wrong.