Skip to content

Commit

Permalink
add loading more indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamstanlee committed Sep 8, 2022
1 parent 3eb146b commit 4859b02
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
9 changes: 4 additions & 5 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -121,7 +121,6 @@
B01AA3FAAED646FB2637D581 /* Pods-Runner.release.xcconfig */,
27CBCB929E40972BF6FA258F /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -356,7 +355,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = XRC8JJDBZU;
DEVELOPMENT_TEAM = M8XP95DY3H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -485,7 +484,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = XRC8JJDBZU;
DEVELOPMENT_TEAM = M8XP95DY3H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -508,7 +507,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = XRC8JJDBZU;
DEVELOPMENT_TEAM = M8XP95DY3H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
7 changes: 4 additions & 3 deletions lib/presentation/bloc/pokemon_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class PokemonCubit extends Cubit<BlocState<List<Pokemon>>> {

int _offset = 0;

void getPokemons() async {
emit(state.copyWith(status: PageStatusType.loading));
void getPokemons(
{PageStatusType bootstrapStatus = PageStatusType.loading}) async {
emit(state.copyWith(status: bootstrapStatus));
final failureOrPokemons = await pokemonRepository.getAllPokemon(_offset);
failureOrPokemons.fold(
(failure) => emit(
Expand All @@ -34,7 +35,7 @@ class PokemonCubit extends Cubit<BlocState<List<Pokemon>>> {
void getMorePokemons() async {
if (!state.isLoading) {
_offset += 24;
getPokemons();
getPokemons(bootstrapStatus: PageStatusType.loadingMore);
}
}

Expand Down
41 changes: 26 additions & 15 deletions lib/presentation/pokemon/all_pokemon_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,32 @@ class _AllPokemonTabState extends State<AllPokemonTab> {
final pokemons = state.data;

if (pokemons.isNotEmpty) {
return GridView.builder(
key: const PageStorageKey('all_pokemon_tab'),
controller: scrollController,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.all(Insets.sm),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisExtent: kMaxGridExtent,
mainAxisSpacing: Insets.sm,
crossAxisSpacing: Insets.sm,
),
itemCount: pokemons.length,
itemBuilder: (context, index) => PokemonGridItem(
pokemons[index],
),
return Column(
children: [
Expanded(
child: GridView.builder(
key: const PageStorageKey('all_pokemon_tab'),
controller: scrollController,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.all(Insets.sm),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisExtent: kMaxGridExtent,
mainAxisSpacing: Insets.sm,
crossAxisSpacing: Insets.sm,
),
itemCount: pokemons.length,
itemBuilder: (context, index) => PokemonGridItem(
pokemons[index],
),
),
),
if (state.isLoadingMore)
const Padding(
padding: EdgeInsets.symmetric(vertical: 32),
child: LoadingIndicator(),
),
],
);
}

Expand Down
22 changes: 11 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
version: "1.15.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -245,7 +245,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.2.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -400,7 +400,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
version: "0.6.3"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -442,7 +442,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -498,7 +498,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.0"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -685,7 +685,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.8.1"
sqflite:
dependency: transitive
description:
Expand Down Expand Up @@ -748,21 +748,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.20.2"
version: "1.19.5"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.8"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.11"
version: "0.4.9"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -797,7 +797,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
version: "2.1.1"
vm_service:
dependency: transitive
description:
Expand Down Expand Up @@ -855,5 +855,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.17.0-0 <3.0.0"
dart: ">=2.16.2 <3.0.0"
flutter: ">=2.8.1"
2 changes: 1 addition & 1 deletion test/presentation/bloc/pokemon_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void main() {
act: (bloc) => bloc.getMorePokemons(),
expect: () => [
BlocState.initial(const <Pokemon>[]).copyWith(
status: PageStatusType.loading,
status: PageStatusType.loadingMore,
data: [mockPokemon],
),
BlocState.initial(const <Pokemon>[]).copyWith(
Expand Down

0 comments on commit 4859b02

Please sign in to comment.