-
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.
- Loading branch information
Showing
28 changed files
with
610 additions
and
517 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,67 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:mbunge/models/add_reponse.dart'; | ||
import 'package:mbunge/models/reponses.dart'; | ||
import 'package:mbunge/repository/share_preferences.dart'; | ||
import 'package:mbunge/repository/webinar_repository.dart'; | ||
|
||
part 'questioncubit_state.dart'; | ||
|
||
class QuestioncubitCubit extends Cubit<QuestioncubitState> { | ||
final WebinarRepository webinarRepository; | ||
final SharePreferenceRepo sharePreferenceRepo; | ||
QuestioncubitCubit(this.webinarRepository, this.sharePreferenceRepo) | ||
: super(QuestioncubitInitial()); | ||
|
||
Future<void> fetchQuestions(String id) async { | ||
try { | ||
final responses = await webinarRepository.getResponses( | ||
id, | ||
); | ||
if (responses != null) { | ||
emit(QuestioncubitSuccess(responses: responses, message: "")); | ||
} | ||
} catch (e) { | ||
emit(QuestioncubitError(message: e.toString())); | ||
} | ||
} | ||
|
||
Future<void> addQuestion({@required String id, @required String body}) async { | ||
final currentState = state; | ||
try { | ||
AddResponse response = AddResponse( | ||
userId: await sharePreferenceRepo.getUserId(), | ||
participationId: id, | ||
body: body, | ||
); | ||
|
||
debugPrint("${response.toJson()}"); | ||
|
||
final result = await webinarRepository.addResponse(response); | ||
debugPrint("##################################"); | ||
debugPrint("${result.toJson()}"); | ||
debugPrint("##################################"); | ||
if (currentState is QuestioncubitSuccess) { | ||
final _questions = currentState.responses; | ||
if (result != null) { | ||
_questions.insert(0, result); | ||
_questions.sort((a, b) => a.createdAt.compareTo(b.createdAt)); | ||
emit( | ||
QuestioncubitSuccess( | ||
responses: _questions, | ||
message: "Added successfully!", | ||
), | ||
); | ||
} else { | ||
emit( | ||
QuestioncubitSuccess( | ||
responses: _questions, | ||
message: "Unable to add your question!", | ||
), | ||
); | ||
} | ||
} | ||
} catch (e) {} | ||
} | ||
} |
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 @@ | ||
part of 'questioncubit_cubit.dart'; | ||
|
||
// abstract class QuestioncubitState extends Equatable { | ||
// const QuestioncubitState(); | ||
|
||
// @override | ||
// List<Object> get props => []; | ||
// } | ||
|
||
abstract class QuestioncubitState { | ||
const QuestioncubitState(); | ||
} | ||
|
||
class QuestioncubitInitial extends QuestioncubitState {} | ||
|
||
class QuestioncubitSuccess extends QuestioncubitState { | ||
final List<Responses> responses; | ||
final String message; | ||
|
||
QuestioncubitSuccess({@required this.responses, @required this.message}); | ||
// @override | ||
// List<Object> get props => [responses, message]; | ||
} | ||
|
||
class QuestioncubitError extends QuestioncubitState { | ||
final String message; | ||
|
||
QuestioncubitError({@required this.message}); | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.