diff --git a/lib/blocs/truth_or_dare/truth_or_dare_bloc.dart b/lib/blocs/truth_or_dare/truth_or_dare_bloc.dart index 173c62f..ae63b64 100644 --- a/lib/blocs/truth_or_dare/truth_or_dare_bloc.dart +++ b/lib/blocs/truth_or_dare/truth_or_dare_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:developer'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; @@ -6,6 +7,7 @@ import 'package:truthordare/model/DareModel.dart'; import 'package:truthordare/model/TruthModel.dart'; import 'package:truthordare/repositories/dare_repository.dart'; import 'package:truthordare/repositories/truth_repository.dart'; +import 'package:truthordare/utilities/SharedPreferences.dart'; part 'truth_or_dare_event.dart'; part 'truth_or_dare_state.dart'; @@ -31,6 +33,9 @@ class TruthOrDareBloc extends Bloc { try{ int selectedLevel=event.selectedLevel; DareModel dareModel=await truthRepository.getRandomDare(selectedLevel: selectedLevel); + await Preferences.setDataInt( + "level", selectedLevel); + log(selectedLevel.toString(),name: "level"); yield DareLoaded(dareModel: dareModel,selectedLevel: selectedLevel); }catch(e){ yield TodError(errMessage: e.toString()??"An error occured",isTruth: false); @@ -42,6 +47,8 @@ class TruthOrDareBloc extends Bloc { try{ int selectedLevel=event.selectedLevel; TruthModel truthModel=await truthRepository.getRandomTruth(selectedLevel: selectedLevel); + await Preferences.setDataInt( + "level", selectedLevel); print(truthModel); yield TruthLoaded(truthModel: truthModel,selectedLevel: selectedLevel); }catch(e){ diff --git a/lib/screen/dashboard.dart b/lib/screen/dashboard.dart index 70e9df5..6611c6c 100644 --- a/lib/screen/dashboard.dart +++ b/lib/screen/dashboard.dart @@ -62,7 +62,7 @@ class _DashboardState extends State currentIndex: _currentIndex, // this will be set when a new tab is tapped items: [ BottomNavigationBarItem( - icon: Icon(Icons.home), + icon: Icon(Icons.dashboard_outlined), label: 'Truth or Dare', ), BottomNavigationBarItem( diff --git a/lib/screen/truth_or_dare/home.dart b/lib/screen/truth_or_dare/home.dart index 6b11f5d..e8cbe6e 100644 --- a/lib/screen/truth_or_dare/home.dart +++ b/lib/screen/truth_or_dare/home.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:truthordare/blocs/truth_or_dare/truth_or_dare_bloc.dart'; @@ -30,7 +32,7 @@ class _HomeState extends State { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => sl()..add(GetTruth()), + create: (context) => sl()..add(GetTruth(selectedLevel: selectedLevel??-1)), child: Scaffold( appBar: AppBar( elevation: 0, @@ -68,10 +70,10 @@ class _HomeState extends State { onPressed: () { if (state.isTruth) { BlocProvider.of(context) - .add(GetTruth()); + .add(GetTruth(selectedLevel: selectedLevel)); } else { BlocProvider.of(context) - .add(GetDare()); + .add(GetDare(selectedLevel: selectedLevel)); } }))); } @@ -97,31 +99,31 @@ class _HomeState extends State { elevation: 2, child: Container( padding: EdgeInsets.all(10), - child: (state is TruthLoaded && - state.truthModel.results == null) || - (state is DareLoaded && - state.dareModel.results == null) - ? Column( - children: [ - Icon( - Icons.dangerous, - size: 50, - color: ColorBase.kPrimaryColor, - ), - Text( - "Tidak ada Truth or Dare untuk level yang dipilih", - style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold), - textAlign: TextAlign.center, - ), - ], - ) - : Column( + child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Column( + (state is TruthLoaded && + state.truthModel.results == null) || + (state is DareLoaded && + state.dareModel.results == null) + ? Column( + children: [ + Icon( + Icons.dangerous, + size: 50, + color: ColorBase.kPrimaryColor, + ), + Text( + "Tidak ada Truth or Dare untuk level yang dipilih", + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold), + textAlign: TextAlign.center, + ), + ], + ) + : Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -214,6 +216,7 @@ class _HomeState extends State { .indexOf(e))); selectedLevel = level.indexOf(e); + print("Here"); } } else if (state is DareLoaded) { @@ -235,8 +238,6 @@ class _HomeState extends State { selectedLevel = level.indexOf(e); } - await Preferences.setDataInt( - "level", selectedLevel); setState(() {}); } }, @@ -283,7 +284,7 @@ class _HomeState extends State { onPressed: () { BlocProvider.of(context).add(GetTruth( selectedLevel: - state is TruthLoaded ? state.selectedLevel : -1)); + selectedLevel)); }, child: Row( mainAxisAlignment: MainAxisAlignment.center, @@ -324,7 +325,7 @@ class _HomeState extends State { onPressed: () { BlocProvider.of(context).add(GetDare( selectedLevel: - state is DareLoaded ? state.selectedLevel : -1)); + selectedLevel)); }, child: Row( mainAxisAlignment: MainAxisAlignment.center,