|
|
|
@ -20,6 +20,7 @@ class IntroBloc extends Bloc<IntroEvent, IntroState> { |
|
|
|
/// ------------constructor------------ |
|
|
|
IntroBloc() : super(const IntroState()) { |
|
|
|
initVideos(); |
|
|
|
listenController(); |
|
|
|
on<InitVideosEvent>(_initVideosEvent); |
|
|
|
on<ChangeVideosEvent>(_changeVideosEvent); |
|
|
|
} |
|
|
|
@ -70,6 +71,27 @@ class IntroBloc extends Bloc<IntroEvent, IntroState> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void listenController() { |
|
|
|
// A helper function to check for video completion |
|
|
|
void _onVideoEnd(PodPlayerController controller, int controllerIndex) { |
|
|
|
final position = controller.videoPlayerValue?.position; |
|
|
|
final duration = controller.videoPlayerValue?.duration; |
|
|
|
|
|
|
|
if (position != null && duration != null && position >= duration) { |
|
|
|
// Only trigger the change if the completed video is the current one |
|
|
|
if (state.currentIntro == controllerIndex) { |
|
|
|
add(ChangeVideosEvent()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
podController1.addListener(() => _onVideoEnd(podController1, 0)); |
|
|
|
podController2.addListener(() => _onVideoEnd(podController2, 1)); |
|
|
|
podController3.addListener(() => _onVideoEnd(podController3, 2)); |
|
|
|
podController4.addListener(() => _onVideoEnd(podController4, 3)); |
|
|
|
podController5.addListener(() => _onVideoEnd(podController5, 4)); |
|
|
|
} |
|
|
|
|
|
|
|
/// ------------Api Calls------------ |
|
|
|
FutureOr<void> _changeVideosEvent(ChangeVideosEvent event, Emitter emit) async { |
|
|
|
switch (state.currentIntro) { |
|
|
|
|