Skip to content

Commit

Permalink
fixed problem with not loading of categories in home_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-dor committed Nov 6, 2024
1 parent c100368 commit d51c1ab
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
7 changes: 5 additions & 2 deletions lib/core/injections/home_screen_inj/home_screen_inj.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import 'package:youtube/features/home_screen/presentation/bloc/main_home_screen_

abstract final class HomeScreenInj {
static Future<void> inject() async {
final homeScreenRepoImpl = HomeScreenRepoImpl();
final HomeScreenRepo homeScreenRepoImpl = HomeScreenRepoImpl();

// it necessary
locator.registerLazySingleton<HomeScreenRepo>(() => homeScreenRepoImpl);

locator.registerFactory<MainHomeScreenBloc>(
() => MainHomeScreenBloc(
homeScreenRepoImpl,
locator<HomeScreenRepo>(),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RestApiHomeScreenGetCategories {

res['categories'] = categories;
res['success'] = true;
debugPrint("server categories: $res");
} catch (e) {
debugPrint("getCategories error is $e");
res['server_error'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:youtube/core/injections/injection_container.dart';
import 'package:youtube/core/models/video_category_models/video_category.dart';
import 'package:youtube/core/models/video_category_models/video_category_snippet.dart';
import 'package:youtube/features/home_screen/domain/repo/home_screen_repo.dart';
import 'package:youtube/features/home_screen/domain/usecases/hs_get_categories.dart';
import 'video_category_cubit_states.dart';

class MainVideoCategoryCubit extends Cubit<VideoCategoryCubitStates> {
Expand All @@ -12,9 +13,10 @@ class MainVideoCategoryCubit extends Cubit<VideoCategoryCubitStates> {
}

Future<void> loadVideoCategory() async {
debugPrint("loading categories");
debugPrint("loading categories 1");
emit(LoadingVideoCategoryState(List.empty()));
var data = await locator<HomeScreenRepo>().getCategories();
var data = await HsGetCategories(locator<HomeScreenRepo>()).getCategories();
debugPrint("get categories data: ${data}");
if (data.containsKey("server_error")) {
emit(ErrorVideoCategoryState(List.empty()));
} else if (data.containsKey("success")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'dart:isolate';
import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/video_category_cubit_states.dart';
import 'package:youtube/core/blocs_and_cubits/home_page_bottom_navbar_cubit/home_page_bottom_navbar_cubit.dart';
import 'package:youtube/core/injections/injection_container.dart';
import 'package:youtube/core/youtube_data_api/models/video.dart' as ytv;
Expand All @@ -14,6 +12,8 @@ import 'package:youtube/features/home_screen/domain/usecases/hs_get_categories.d
import 'package:youtube/features/home_screen/domain/usecases/hs_get_videos.dart';
import 'cubits/home_screen_videos_cubit/home_screen_videos_cubit.dart';
import 'cubits/home_screen_videos_cubit/home_screen_videos_states.dart';
import 'cubits/video_category_cubit/main_video_category_cubit.dart';
import 'cubits/video_category_cubit/video_category_cubit_states.dart';
import 'home_screen_bloc_events.dart';
import 'home_screen_bloc_states.dart';
import 'home_screen_state_model/home_screen_state_model.dart';
Expand Down Expand Up @@ -79,6 +79,8 @@ class MainHomeScreenBloc extends Bloc<HomeScreenBlocEvents, HomeScreenStates> {
categoriesCubit.loadVideoCategory();
}

debugPrint("coming data from server: $data");

if (data.containsKey("server_error")) {
// server error
homeScreenVideosCubit.errorHomeScreenVideosState();
Expand Down
8 changes: 5 additions & 3 deletions lib/features/home_screen/presentation/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/video_category_cubit_states.dart';
import 'package:youtube/core/blocs_and_cubits/home_page_bottom_navbar_cubit/home_page_bottom_navbar_cubit.dart';
import 'package:youtube/features/home_screen/presentation/bloc/main_home_screen_bloc.dart';
import 'package:youtube/features/main_screen_overlay_info_feature/presentation/cubit/main_screen_overlay_info_feature_cubit.dart';
Expand All @@ -11,6 +9,8 @@ import 'package:youtube/core/widgets/videos_widgets/videos_loaded_widget.dart';
import 'package:youtube/core/widgets/videos_widgets/videos_loading_widget.dart';
import 'bloc/cubits/home_screen_videos_cubit/home_screen_videos_cubit.dart';
import 'bloc/cubits/home_screen_videos_cubit/home_screen_videos_states.dart';
import 'bloc/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'bloc/cubits/video_category_cubit/video_category_cubit_states.dart';
import 'bloc/home_screen_bloc_events.dart';
import 'widgets/home_screen_categories_widgets/home_screen_categories_loaded_widget.dart';
import 'widgets/home_screen_categories_widgets/home_screen_categories_loading_widget.dart';
Expand All @@ -30,6 +30,8 @@ class _HomeScreenState extends State<HomeScreen> {
// TODO: implement initState
super.initState();

// context.read<MainVideoCategoryCubit>().loadVideoCategory();

context
.read<MainHomeScreenBloc>()
.add(RefreshHomeScreenEvent(context: context, refresh: false));
Expand Down Expand Up @@ -63,7 +65,7 @@ class _HomeScreenState extends State<HomeScreen> {
//data
final mainHomeScreenStateModel = mainHomeScreenState.homeScreenStateModel;
final mainScreenOverlayStateModel = mainScreenOverlayCubit.mainScreenOverlayStateModel;
debugPrint("is here working on scroll");
debugPrint("is here working on scroll | ${videoCategoryState}");
return Column(
children: [
if (videoCategoryState is LoadingVideoCategoryState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/core/models/video_category_models/video_category.dart';
import 'package:youtube/core/utils/extensions.dart';
import 'package:youtube/features/home_screen/presentation/bloc/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/features/home_screen/presentation/bloc/home_screen_bloc_events.dart';
import 'package:youtube/features/home_screen/presentation/bloc/main_home_screen_bloc.dart';
import 'package:youtube/core/widgets/text_widget.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/auth_bloc/main_auth_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/core/blocs_and_cubits/home_page_bottom_navbar_cubit/home_page_bottom_navbar_cubit.dart';
import 'package:youtube/core/injections/injection_container.dart';
import 'package:youtube/features/home_screen/presentation/bloc/cubits/home_screen_videos_cubit/home_screen_videos_cubit.dart';
import 'package:youtube/features/home_screen/presentation/bloc/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/features/home_screen/presentation/bloc/main_home_screen_bloc.dart';
import 'package:youtube/features/library_downloads/presentation/bloc/library_downloads_bloc.dart';
import 'package:youtube/features/library_inner_screens/presentation/blocs/history_inner_screen_bloc/history_inner_screen_bloc.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/core/blocs_and_cubits/cubits/video_category_cubit/video_category_cubit_states.dart';
import 'package:youtube/core/blocs_and_cubits/home_page_bottom_navbar_cubit/home_page_bottom_navbar_cubit.dart';
import 'package:youtube/core/models/video_category_models/video_category.dart';
import 'package:youtube/features/home_screen/presentation/bloc/cubits/video_category_cubit/main_video_category_cubit.dart';
import 'package:youtube/features/home_screen/presentation/bloc/cubits/video_category_cubit/video_category_cubit_states.dart';
import 'package:youtube/features/trending_screen/presentation/bloc/trending_screen_bloc.dart';
import 'package:youtube/core/widgets/videos_widgets/videos_loaded_widget.dart';
import 'package:youtube/core/widgets/videos_widgets/videos_loading_widget.dart';
Expand Down

0 comments on commit d51c1ab

Please sign in to comment.