Skip to content

Commit

Permalink
Merge pull request #3 from SSebigo/fix-useless-delays
Browse files Browse the repository at this point in the history
Fix useless delays
  • Loading branch information
febryardiansyah authored Jun 6, 2020
2 parents 050ebb8 + 59908d9 commit cfcbecf
Show file tree
Hide file tree
Showing 56 changed files with 1,872 additions and 1,428 deletions.
17 changes: 17 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include: package:lint/analysis_options.yaml

linter:
rules:
- parameter_assignments

analyzer:
enable-experiment:
- extension-methods
errors:
missing_required_param: error
missing_return: error
must_be_immutable: error
parameter_assignments: error
yield_of_invalid_type: ignore
# TODO remove this rule
return_of_invalid_type_from_closure: info
22 changes: 10 additions & 12 deletions lib/bloc/current_season_bloc/current_bloc_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@ import 'package:animku/models/current_season_model.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';

abstract class CurrentBlocState extends Equatable{}
abstract class CurrentBlocState extends Equatable {}

class CurrentInitialState extends CurrentBlocState{
class CurrentInitialState extends CurrentBlocState {
@override
// TODO: implement props
List<Object> get props => [];
}

class CurrentLoadingState extends CurrentBlocState{
class CurrentLoadingState extends CurrentBlocState {
@override
// TODO: implement props
List<Object> get props => [];
}

class CurrentLoadedState extends CurrentBlocState{
class CurrentLoadedState extends CurrentBlocState {
final List<AnimeList> animeList;

List<AnimeList>animeList;
CurrentLoadedState({@required this.animeList});

@override
// TODO: implement props
List<Object> get props => [animeList];

}
class CurrentErrorState extends CurrentBlocState{
String message;

class CurrentErrorState extends CurrentBlocState {
final String message;

CurrentErrorState({@required this.message});

@override
// TODO: implement props
List<Object> get props => [message];

}
}
18 changes: 8 additions & 10 deletions lib/bloc/current_season_bloc/fall_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ import 'package:animku/repository/current_season_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'current_bloc_event.dart';

class FallBloc extends Bloc<CurrentEvent,CurrentBlocState>{
class FallBloc extends Bloc<CurrentEvent, CurrentBlocState> {
CurrentSeasonRepository currentSeasonRepository;

FallBloc(this.currentSeasonRepository);

@override
// TODO: implement initialState
CurrentBlocState get initialState => CurrentInitialState();

@override
Stream<CurrentBlocState> mapEventToState(CurrentEvent event) async* {
// TODO: implement mapEventToState
if(event is FetchCurrentEvent){
if (event is FetchCurrentEvent) {
yield CurrentLoadingState();
try{
List<AnimeList> list = await currentSeasonRepository.getFall2020();
try {
final List<AnimeList> list =
await currentSeasonRepository.getFall2020();
yield CurrentLoadedState(animeList: list);
}catch(e){
yield CurrentErrorState(message: e);
} catch (e) {
yield CurrentErrorState(message: e as String);
}
}
}

}
}
2 changes: 1 addition & 1 deletion lib/bloc/current_season_bloc/spring_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SpringBloc extends Bloc<CurrentEvent,CurrentBlocState>{
if(event is FetchCurrentEvent){
yield CurrentLoadingState();
try{
List<AnimeList> animeList = await currentSeasonRepository.getSpring2020();
final List<AnimeList> animeList = await currentSeasonRepository.getSpring2020();
yield CurrentLoadedState(animeList: animeList);
}catch(e){
yield CurrentErrorState(message: e.toString());
Expand Down
16 changes: 8 additions & 8 deletions lib/bloc/current_season_bloc/summer_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/repository/current_season_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SummerBloc extends Bloc<CurrentEvent,CurrentBlocState>{
class SummerBloc extends Bloc<CurrentEvent, CurrentBlocState> {
CurrentSeasonRepository currentSeasonRepository;

SummerBloc(this.currentSeasonRepository);
Expand All @@ -14,17 +14,17 @@ class SummerBloc extends Bloc<CurrentEvent,CurrentBlocState>{
CurrentBlocState get initialState => CurrentInitialState();

@override
Stream<CurrentBlocState> mapEventToState(CurrentEvent event)async* {
Stream<CurrentBlocState> mapEventToState(CurrentEvent event) async* {
// TODO: implement mapEventToState
if(event is FetchCurrentEvent){
if (event is FetchCurrentEvent) {
yield CurrentLoadingState();
try{
List<AnimeList> list = await currentSeasonRepository.getSummer2020();
try {
final List<AnimeList> list =
await currentSeasonRepository.getSummer2020();
yield CurrentLoadedState(animeList: list);
}catch(e){
} catch (e) {
yield CurrentErrorState(message: e.toString());
}
}
}

}
}
16 changes: 8 additions & 8 deletions lib/bloc/current_season_bloc/winter_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/repository/current_season_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class WinterBloc extends Bloc<CurrentEvent,CurrentBlocState>{
class WinterBloc extends Bloc<CurrentEvent, CurrentBlocState> {
CurrentSeasonRepository currentSeasonRepository;

WinterBloc(this.currentSeasonRepository);
Expand All @@ -14,17 +14,17 @@ class WinterBloc extends Bloc<CurrentEvent,CurrentBlocState>{
CurrentBlocState get initialState => CurrentInitialState();

@override
Stream<CurrentBlocState> mapEventToState(CurrentEvent event)async* {
Stream<CurrentBlocState> mapEventToState(CurrentEvent event) async* {
// TODO: implement mapEventToState
if(event is FetchCurrentEvent){
if (event is FetchCurrentEvent) {
yield CurrentLoadingState();
try{
List<AnimeList>animeList = await currentSeasonRepository.getWinter2020();
try {
final List<AnimeList> animeList =
await currentSeasonRepository.getWinter2020();
yield CurrentLoadedState(animeList: animeList);
}catch(e){
} catch (e) {
yield CurrentErrorState(message: e.toString());
}
}
}

}
}
15 changes: 7 additions & 8 deletions lib/bloc/schedule_bloc/friday_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/repository/schedule_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class FridayBloc extends Bloc<ScheduleEvent,ScheduleState>{
class FridayBloc extends Bloc<ScheduleEvent, ScheduleState> {
ScheduleRepository scheduleRepository;

FridayBloc(this.scheduleRepository);
Expand All @@ -13,16 +13,15 @@ class FridayBloc extends Bloc<ScheduleEvent,ScheduleState>{
ScheduleState get initialState => ScheduleInitialState();

@override
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async*{
if(event is FetchSchedule){
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async* {
if (event is FetchSchedule) {
yield ScheduleInitialState();
try{
List<AnimeList> list = await scheduleRepository.getFriday();
try {
final List<AnimeList> list = await scheduleRepository.getFriday();
yield ScheduleLoadedState(animeList: list);
}catch(e){
} catch (e) {
yield ScheduleErrorState(message: e.toString());
}
}
}

}
}
14 changes: 7 additions & 7 deletions lib/bloc/schedule_bloc/monday_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:animku/bloc/schedule_bloc/shedule_event_state.dart';
import 'package:animku/models/current_season_model.dart';
import 'package:animku/models/days_model.dart';
import 'package:animku/repository/schedule_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class MondayBloc extends Bloc<ScheduleEvent,ScheduleState>{
class MondayBloc extends Bloc<ScheduleEvent, ScheduleState> {
ScheduleRepository scheduleRepository;

MondayBloc(this.scheduleRepository);
Expand All @@ -15,12 +15,12 @@ class MondayBloc extends Bloc<ScheduleEvent,ScheduleState>{

@override
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async* {
if(event is FetchSchedule){
if (event is FetchSchedule) {
yield ScheduleInitialState();
try{
List<AnimeList> list = await scheduleRepository.getMonday();
try {
final List<AnimeList> list = await scheduleRepository.getMonday();
yield ScheduleLoadedState(animeList: list);
}catch(e){
} catch (e) {
yield ScheduleErrorState(message: e.toString());
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/bloc/schedule_bloc/saturday_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/repository/schedule_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SaturdayBloc extends Bloc<ScheduleEvent,ScheduleState>{
class SaturdayBloc extends Bloc<ScheduleEvent, ScheduleState> {
ScheduleRepository scheduleRepository;

SaturdayBloc(this.scheduleRepository);
Expand All @@ -13,16 +13,16 @@ class SaturdayBloc extends Bloc<ScheduleEvent,ScheduleState>{
ScheduleState get initialState => ScheduleInitialState();

@override
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async*{
if(event is FetchSchedule){
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async* {
if (event is FetchSchedule) {
yield ScheduleInitialState();
try{
List<AnimeList> list = await scheduleRepository.getSaturday();
try {
final List<AnimeList> list = await scheduleRepository.getSaturday();
print(list);
yield ScheduleLoadedState(animeList: list);
}catch(e){
} catch (e) {
yield ScheduleErrorState(message: e.toString());
}
}
}

}
}
18 changes: 10 additions & 8 deletions lib/bloc/schedule_bloc/shedule_event_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ import 'package:animku/models/current_season_model.dart';
import 'package:equatable/equatable.dart';

//fetch event
abstract class ScheduleEvent extends Equatable{}
abstract class ScheduleEvent extends Equatable {}

class FetchSchedule extends ScheduleEvent{
class FetchSchedule extends ScheduleEvent {
@override
List<Object> get props => [];
}

//state
abstract class ScheduleState extends Equatable{}
abstract class ScheduleState extends Equatable {}

class ScheduleInitialState extends ScheduleState{
class ScheduleInitialState extends ScheduleState {
@override
List<Object> get props => [];
}
class ScheduleLoadedState extends ScheduleState{
List<AnimeList> animeList;

class ScheduleLoadedState extends ScheduleState {
final List<AnimeList> animeList;

ScheduleLoadedState({this.animeList});

@override
List<Object> get props => [animeList];
}
class ScheduleErrorState extends ScheduleState{
String message;

class ScheduleErrorState extends ScheduleState {
final String message;

ScheduleErrorState({this.message});

Expand Down
18 changes: 9 additions & 9 deletions lib/bloc/schedule_bloc/sunday_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:animku/bloc/schedule_bloc/shedule_event_state.dart';
import 'package:animku/models/current_season_model.dart';
import 'package:animku/models/days_model.dart';
import 'package:animku/repository/schedule_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SundayBloc extends Bloc<ScheduleEvent,ScheduleState>{
class SundayBloc extends Bloc<ScheduleEvent, ScheduleState> {
ScheduleRepository scheduleRepository;

SundayBloc(this.scheduleRepository);
Expand All @@ -14,15 +14,15 @@ class SundayBloc extends Bloc<ScheduleEvent,ScheduleState>{
ScheduleState get initialState => ScheduleInitialState();

@override
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async*{
if(event is FetchSchedule){
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async* {
if (event is FetchSchedule) {
yield ScheduleInitialState();
try{
List<AnimeList> data = await scheduleRepository.getSunday();
try {
final List<AnimeList> data = await scheduleRepository.getSunday();
yield ScheduleLoadedState(animeList: data);
}catch(e){
} catch (e) {
yield ScheduleErrorState(message: e.toString());
}
}
}
}
}
14 changes: 7 additions & 7 deletions lib/bloc/schedule_bloc/thursday_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:animku/models/current_season_model.dart';
import 'package:animku/repository/schedule_repo.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class ThursdayBloc extends Bloc<ScheduleEvent,ScheduleState>{
class ThursdayBloc extends Bloc<ScheduleEvent, ScheduleState> {
ScheduleRepository scheduleRepository;

ThursdayBloc(this.scheduleRepository);
Expand All @@ -13,15 +13,15 @@ class ThursdayBloc extends Bloc<ScheduleEvent,ScheduleState>{
ScheduleState get initialState => ScheduleInitialState();

@override
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async*{
if(event is FetchSchedule){
Stream<ScheduleState> mapEventToState(ScheduleEvent event) async* {
if (event is FetchSchedule) {
yield ScheduleInitialState();
try{
List<AnimeList> list = await scheduleRepository.getThursday();
try {
final List<AnimeList> list = await scheduleRepository.getThursday();
yield ScheduleLoadedState(animeList: list);
}catch(e){
} catch (e) {
yield ScheduleErrorState(message: e.toString());
}
}
}
}
}
Loading

0 comments on commit cfcbecf

Please sign in to comment.