Skip to content

Commit

Permalink
Merge 42feada into 51970a0
Browse files Browse the repository at this point in the history
  • Loading branch information
ardi27 authored Feb 28, 2021
2 parents 51970a0 + 42feada commit 87c52f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
7 changes: 7 additions & 0 deletions lib/blocs/truth_or_dare/truth_or_dare_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:async';
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
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';
Expand All @@ -31,6 +33,9 @@ class TruthOrDareBloc extends Bloc<TruthOrDareEvent, TruthOrDareState> {
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);
Expand All @@ -42,6 +47,8 @@ class TruthOrDareBloc extends Bloc<TruthOrDareEvent, TruthOrDareState> {
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){
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _DashboardState extends State<Dashboard>
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(
Expand Down
59 changes: 30 additions & 29 deletions lib/screen/truth_or_dare/home.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,7 +32,7 @@ class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return BlocProvider<TruthOrDareBloc>(
create: (context) => sl<TruthOrDareBloc>()..add(GetTruth()),
create: (context) => sl<TruthOrDareBloc>()..add(GetTruth(selectedLevel: selectedLevel??-1)),
child: Scaffold(
appBar: AppBar(
elevation: 0,
Expand Down Expand Up @@ -68,10 +70,10 @@ class _HomeState extends State<Home> {
onPressed: () {
if (state.isTruth) {
BlocProvider.of<TruthOrDareBloc>(context)
.add(GetTruth());
.add(GetTruth(selectedLevel: selectedLevel));
} else {
BlocProvider.of<TruthOrDareBloc>(context)
.add(GetDare());
.add(GetDare(selectedLevel: selectedLevel));
}
})));
}
Expand All @@ -97,31 +99,31 @@ class _HomeState extends State<Home> {
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: [
Expand Down Expand Up @@ -214,6 +216,7 @@ class _HomeState extends State<Home> {
.indexOf(e)));
selectedLevel =
level.indexOf(e);
print("Here");
}
} else if (state
is DareLoaded) {
Expand All @@ -235,8 +238,6 @@ class _HomeState extends State<Home> {
selectedLevel =
level.indexOf(e);
}
await Preferences.setDataInt(
"level", selectedLevel);
setState(() {});
}
},
Expand Down Expand Up @@ -283,7 +284,7 @@ class _HomeState extends State<Home> {
onPressed: () {
BlocProvider.of<TruthOrDareBloc>(context).add(GetTruth(
selectedLevel:
state is TruthLoaded ? state.selectedLevel : -1));
selectedLevel));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -324,7 +325,7 @@ class _HomeState extends State<Home> {
onPressed: () {
BlocProvider.of<TruthOrDareBloc>(context).add(GetDare(
selectedLevel:
state is DareLoaded ? state.selectedLevel : -1));
selectedLevel));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down

0 comments on commit 87c52f6

Please sign in to comment.