Browse Source

fix: get data form database

pull/14/head
AmirrezaChegini 3 days ago
parent
commit
c388f005c4
  1. 13
      lib/features/level/data/datasource/level_datasource.dart
  2. 10
      lib/features/level/presentation/bloc/level_bloc.dart
  3. 9
      lib/features/level/presentation/ui/level_page.dart

13
lib/features/level/data/datasource/level_datasource.dart

@ -1,7 +1,9 @@
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart';
import 'package:hadi_hoda_flutter/core/params/level_params.dart';
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart';
import 'package:hive/hive.dart';
abstract class ILevelDatasource {
@ -10,14 +12,19 @@ abstract class ILevelDatasource {
/// Local
class LocalLevelDatasourceImpl implements ILevelDatasource {
const LocalLevelDatasourceImpl();
@override
Future<List<LevelEntity>> getLevels({required LevelParams params}) async {
try {
final Box<LevelEntity> levelBox = Hive.box(MyConstants.levelBox);
return levelBox.values.toList();
final String selectedLanguage = LocalStorage.readData(
key: MyConstants.selectLanguage);
final Box<TotalDataEntity> levelBox = Hive.box(MyConstants.levelBox);
final TotalDataEntity findData = levelBox.values.singleWhere((e) =>
e.code == selectedLanguage,
orElse: () => TotalDataEntity(),
);
return findData.levels ?? [];
} catch (_) {
throw MyException(errorMessage: 'Operation Failed');
}

10
lib/features/level/presentation/bloc/level_bloc.dart

@ -63,7 +63,6 @@ class LevelBloc extends Bloc<LevelEvent, LevelState> {
final ScrollController scrollController = ScrollController();
/// ------------Functions------------
void goToQuestionPage(BuildContext context, LevelEntity level){
context.pushNamed(
Routes.questionPage,
@ -73,6 +72,10 @@ class LevelBloc extends Bloc<LevelEvent, LevelState> {
);
}
void goToHomePage(BuildContext context){
context.pop();
}
/// ------------Api Calls------------
FutureOr<void> _getLevelListEvent(GetLevelListEvent event,
Emitter<LevelState> emit) async {
@ -87,12 +90,13 @@ class LevelBloc extends Bloc<LevelEvent, LevelState> {
getLevelStatus: const BaseComplete(''),
chooseLevel: data.first,
));
await Future.delayed(Duration(milliseconds: 500));
await Future.delayed(Duration(milliseconds: 500), () {
scrollController.animateTo(
scrollController.position.maxScrollExtent,
duration: Duration(seconds: 1),
duration: Duration(seconds: 500),
curve: Curves.easeInOut,
);
});
},
(error) {},
);

9
lib/features/level/presentation/ui/level_page.dart

@ -26,7 +26,7 @@ class LevelPage extends StatelessWidget {
alignment: Alignment.center,
children: [
_background(),
// _topPath(context),
_topPath(context),
_bottomPath(context),
],
),
@ -47,7 +47,7 @@ class LevelPage extends StatelessWidget {
return Positioned(
bottom: MediaQuery
.viewPaddingOf(context)
.bottom + 10,
.bottom + MySpaces.s10,
right: MySpaces.s16,
left: MySpaces.s16,
child: HintLevelWidget(
@ -71,9 +71,12 @@ class LevelPage extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyImage(
InkWell(
onTap: () => context.read<LevelBloc>().goToHomePage(context),
child: MyImage(
image: MyAssets.homeButton,
),
),
MyImage(
image: MyAssets.musicOn,
),

Loading…
Cancel
Save