-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加本子下的推荐功能 # bug修复 修复部分逻辑问题 # 优化 优化滚动帧率 # 调整 调整部分ui以及点击效果
- Loading branch information
Showing
25 changed files
with
1,746 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export './eps/get_comic_eps_bloc.dart'; | ||
export './info/get_comic_info_bloc.dart'; | ||
export './recommend/recommend_bloc.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:bloc_concurrency/bloc_concurrency.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:stream_transform/stream_transform.dart'; | ||
import 'package:zephyr/network/http/http_request.dart'; | ||
|
||
import '../../json/recommend/recommend_json.dart'; | ||
|
||
part 'recommend_event.dart'; | ||
part 'recommend_state.dart'; | ||
|
||
const _throttleDuration = Duration(milliseconds: 100); | ||
|
||
EventTransformer<E> _throttleDroppable<E>(Duration duration) { | ||
return (events, mapper) { | ||
return droppable<E>().call(events.throttle(duration), mapper); | ||
}; | ||
} | ||
|
||
class RecommendBloc extends Bloc<RecommendEvent, RecommendState> { | ||
RecommendBloc() : super(RecommendState()) { | ||
on<RecommendEvent>( | ||
_fetchComicList, | ||
transformer: _throttleDroppable(_throttleDuration), | ||
); | ||
} | ||
|
||
Future<void> _fetchComicList( | ||
RecommendEvent event, | ||
Emitter<RecommendState> emit, | ||
) async { | ||
if (event.status == RecommendStatus.initial) { | ||
emit(state.copyWith( | ||
status: RecommendStatus.initial, | ||
)); | ||
} | ||
|
||
try { | ||
final result = await getRecommend(event.comicId); | ||
|
||
final comics = result['data']['comics'] as List; | ||
|
||
if (comics.isEmpty) { | ||
emit(state.copyWith( | ||
status: RecommendStatus.success, | ||
comicList: null, | ||
)); | ||
} else { | ||
List<Comic> comicList = []; | ||
final temp = RecommendJson.fromJson(result); | ||
for (var comic in temp.data.comics) { | ||
comicList.add(comic); | ||
} | ||
emit(state.copyWith( | ||
status: RecommendStatus.success, | ||
comicList: comicList, | ||
)); | ||
} | ||
} catch (e) { | ||
emit(state.copyWith( | ||
status: RecommendStatus.failure, | ||
result: e.toString(), | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
part of 'recommend_bloc.dart'; | ||
|
||
final class RecommendEvent extends Equatable { | ||
final String comicId; | ||
final RecommendStatus status; | ||
|
||
const RecommendEvent( | ||
this.comicId, | ||
this.status, | ||
); | ||
|
||
@override | ||
List<Object> get props => [comicId, status]; | ||
} |
Oops, something went wrong.