Browse Source

fix : auto next video

pull/60/head
AmirrezaChegini 1 week ago
parent
commit
2bd73a36f4
  1. 11
      lib/common_ui/theme/my_theme.dart
  2. 22
      lib/features/intro/presentation/bloc/intro_bloc.dart

11
lib/common_ui/theme/my_theme.dart

@ -1,10 +1,17 @@
import 'package:flutter/material.dart';
import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart';
class MyTheme {
static const MyTheme _i = MyTheme._internal();
const MyTheme._internal();
factory MyTheme() => _i;
static final ThemeData light = ThemeData(brightness: Brightness.light);
static final ThemeData dark = ThemeData(brightness: Brightness.dark);
static final ThemeData light = ThemeData(
brightness: Brightness.light,
scaffoldBackgroundColor: MyColors.purple,
);
static final ThemeData dark = ThemeData(
brightness: Brightness.dark,
scaffoldBackgroundColor: MyColors.purple,
);
}

22
lib/features/intro/presentation/bloc/intro_bloc.dart

@ -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) {

Loading…
Cancel
Save