-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d42aa3
commit 5c4859b
Showing
16 changed files
with
202 additions
and
61 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
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
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
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,40 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:anime_tracker/core/common/util/global_static_constants.dart'; | ||
import 'package:anime_tracker/core/data/load_result.dart'; | ||
import 'package:anime_tracker/core/data/media_information_repository.dart'; | ||
import 'package:anime_tracker/core/data/model/character_and_voice_actor_model.dart'; | ||
import 'package:anime_tracker/feature/common/page_loading_state.dart'; | ||
import 'package:anime_tracker/feature/common/paging_bloc.dart'; | ||
|
||
class CharacterPageBloc extends PagingBloc<CharacterAndVoiceActorModel> { | ||
CharacterPageBloc( | ||
this.animeId, { | ||
required MediaInformationRepository aniListRepository, | ||
}) : _mediaInfoRepository = aniListRepository, | ||
super(const PageLoading(data: [], page: 1)); | ||
|
||
final String animeId; | ||
final MediaInformationRepository _mediaInfoRepository; | ||
|
||
@override | ||
Future<bool> createLoadPageTask({required int page}) async { | ||
final LoadResult result = | ||
await _mediaInfoRepository.loadCharacterPageByAnimeId( | ||
animeId: animeId, | ||
loadType: Append(page: page, perPage: Config.defaultPerPageCount), | ||
); | ||
switch (result) { | ||
case LoadSuccess<List<CharacterAndVoiceActorModel>>(data: final data): | ||
add(OnPageLoadedEvent(data, page)); | ||
return true; | ||
case LoadError<List<CharacterAndVoiceActorModel>>( | ||
exception: final exception | ||
): | ||
add(OnPageErrorEvent(exception)); | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
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,100 @@ | ||
import 'package:anime_tracker/core/data/media_information_repository.dart'; | ||
import 'package:anime_tracker/core/data/model/character_and_voice_actor_model.dart'; | ||
import 'package:anime_tracker/core/design_system/animetion/page_transaction_animetion.dart'; | ||
import 'package:anime_tracker/core/design_system/widget/anime_character_and_voice_actor.dart'; | ||
import 'package:anime_tracker/feature/character_page/bloc/character_page_bloc.dart'; | ||
import 'package:anime_tracker/feature/common/page_loading_state.dart'; | ||
import 'package:anime_tracker/feature/common/paging_bloc.dart'; | ||
import 'package:anime_tracker/feature/common/paging_content_widget.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class CharacterListPage extends Page { | ||
final String animeId; | ||
|
||
const CharacterListPage({required this.animeId, super.key}); | ||
|
||
@override | ||
Route createRoute(BuildContext context) { | ||
return CharacterListRoute(settings: this, animeId: animeId); | ||
} | ||
} | ||
|
||
class CharacterListRoute extends PageRoute with MaterialRouteTransitionMixin { | ||
final String animeId; | ||
|
||
CharacterListRoute({required this.animeId, super.settings}); | ||
|
||
@override | ||
Widget buildContent(BuildContext context) { | ||
return BlocProvider( | ||
create: (context) => CharacterPageBloc( | ||
animeId, | ||
aniListRepository: context.read<MediaInformationRepository>(), | ||
), | ||
child: const _CharacterListPageContent(), | ||
); | ||
} | ||
|
||
@override | ||
Widget buildTransitions(BuildContext context, Animation<double> animation, | ||
Animation<double> secondaryAnimation, Widget child) { | ||
return getFistPageTransaction( | ||
animation: animation, | ||
child: getSecondaryPageTransaction( | ||
animation: secondaryAnimation, | ||
child: child, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
bool get maintainState => true; | ||
} | ||
|
||
class _CharacterListPageContent extends StatelessWidget { | ||
const _CharacterListPageContent(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocBuilder<CharacterPageBloc, | ||
PagingState<List<CharacterAndVoiceActorModel>>>( | ||
builder: (context, state) { | ||
final pagingState = state; | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Characters'), | ||
leading: IconButton( | ||
icon: const Icon(Icons.arrow_back), | ||
onPressed: () { | ||
Navigator.maybePop(context); | ||
}, | ||
), | ||
), | ||
body: PagingContent( | ||
pagingState: pagingState, | ||
onBuildItem: (context, model) => _buildListItems(context, model), | ||
onRequestNewPage: () { | ||
context.read<CharacterPageBloc>().add(OnRequestLoadPageEvent()); | ||
}, | ||
onRetryLoadPage: () { | ||
context.read<CharacterPageBloc>().add(OnRetryLoadPageEvent()); | ||
}, | ||
), | ||
); | ||
}); | ||
} | ||
|
||
Widget _buildListItems( | ||
BuildContext context, CharacterAndVoiceActorModel model) { | ||
return SizedBox( | ||
height: 124, | ||
child: CharacterAndVoiceActorWidget( | ||
model: model, | ||
textStyle: Theme.of(context).textTheme.labelMedium, | ||
onCharacterTap: () {}, | ||
onVoiceActorTop: () {}, | ||
), | ||
); | ||
} | ||
} |
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
Oops, something went wrong.