|
|
@ -1,13 +1,17 @@ |
|
|
import 'dart:async'; |
|
|
import 'dart:async'; |
|
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
|
import 'package:bloc/bloc.dart'; |
|
|
import 'package:bloc/bloc.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
|
|
import 'package:flutter/foundation.dart'; |
|
|
import 'package:go_router/go_router.dart'; |
|
|
import 'package:go_router/go_router.dart'; |
|
|
import 'package:hadi_hoda_flutter/common_ui/resources/my_audios.dart'; |
|
|
import 'package:hadi_hoda_flutter/common_ui/resources/my_audios.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/routers/my_routes.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/routers/my_routes.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/services/audio_service.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/services/audio_service.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; |
|
|
|
|
|
import 'package:hadi_hoda_flutter/core/utils/my_context.dart'; |
|
|
|
|
|
import 'package:hadi_hoda_flutter/core/utils/storage_path.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/widgets/dialog/about_us_dialog.dart'; |
|
|
import 'package:hadi_hoda_flutter/core/widgets/dialog/about_us_dialog.dart'; |
|
|
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart'; |
|
|
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart'; |
|
|
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart'; |
|
|
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart'; |
|
|
@ -16,12 +20,12 @@ import 'package:hive/hive.dart'; |
|
|
|
|
|
|
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> { |
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> { |
|
|
/// ------------constructor------------ |
|
|
/// ------------constructor------------ |
|
|
HomeBloc( |
|
|
|
|
|
this._mainAudioService, |
|
|
|
|
|
this._effectAudioService, |
|
|
|
|
|
) : super(const HomeState()) { |
|
|
|
|
|
|
|
|
HomeBloc(this._mainAudioService, this._effectAudioService) |
|
|
|
|
|
: super(const HomeState()) { |
|
|
volumeStream = _mainAudioService.volumeStream(); |
|
|
volumeStream = _mainAudioService.volumeStream(); |
|
|
playMusic(); |
|
|
playMusic(); |
|
|
|
|
|
preCacheQuestionGifs(); |
|
|
|
|
|
preCacheAnswerGifs(); |
|
|
on<GetHomeEvent>(_getHomeEvent); |
|
|
on<GetHomeEvent>(_getHomeEvent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -36,7 +40,9 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> { |
|
|
|
|
|
|
|
|
/// ------------Functions------------ |
|
|
/// ------------Functions------------ |
|
|
void goToLevelPage(BuildContext context) { |
|
|
void goToLevelPage(BuildContext context) { |
|
|
final String? selectedLanguage = LocalStorage.readData(key: MyConstants.selectLanguage); |
|
|
|
|
|
|
|
|
final String? selectedLanguage = LocalStorage.readData( |
|
|
|
|
|
key: MyConstants.selectLanguage, |
|
|
|
|
|
); |
|
|
final Box<TotalDataEntity> dataBox = Hive.box(MyConstants.levelBox); |
|
|
final Box<TotalDataEntity> dataBox = Hive.box(MyConstants.levelBox); |
|
|
final TotalDataEntity findData = dataBox.values.singleWhere( |
|
|
final TotalDataEntity findData = dataBox.values.singleWhere( |
|
|
(e) => e.code == selectedLanguage, |
|
|
(e) => e.code == selectedLanguage, |
|
|
@ -72,6 +78,42 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> { |
|
|
await _mainAudioService.play(); |
|
|
await _mainAudioService.play(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> preCacheQuestionGifs() async { |
|
|
|
|
|
try { |
|
|
|
|
|
final Directory directory = Directory( |
|
|
|
|
|
'${StoragePath.documentDir}/question_image', |
|
|
|
|
|
); |
|
|
|
|
|
final List<FileSystemEntity> files = directory.listSync(); |
|
|
|
|
|
await Future.wait( |
|
|
|
|
|
files.map( |
|
|
|
|
|
(file) => precacheImage(FileImage(File(file.path)), MyContext.get), |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
if (kDebugMode) { |
|
|
|
|
|
print('$e'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> preCacheAnswerGifs() async { |
|
|
|
|
|
try { |
|
|
|
|
|
final Directory directory = Directory( |
|
|
|
|
|
'${StoragePath.documentDir}/answer_image', |
|
|
|
|
|
); |
|
|
|
|
|
final List<FileSystemEntity> files = directory.listSync(); |
|
|
|
|
|
await Future.wait( |
|
|
|
|
|
files.map( |
|
|
|
|
|
(file) => precacheImage(FileImage(File(file.path)), MyContext.get), |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
if (kDebugMode) { |
|
|
|
|
|
print('$e'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// ------------Api Calls------------ |
|
|
/// ------------Api Calls------------ |
|
|
FutureOr<void> _getHomeEvent(event, emit) async {} |
|
|
FutureOr<void> _getHomeEvent(event, emit) async {} |
|
|
} |
|
|
} |