Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
55946fa
:art: added new core classes
sarbagyastha Dec 30, 2022
2b0c27a
:truck: reorganize classes
sarbagyastha Dec 30, 2022
94832ec
:truck: reorganize ui classes
sarbagyastha Dec 30, 2022
5b0d693
:truck: move example outside of the package
sarbagyastha Dec 30, 2022
0b289c8
:sparkles: added new example app
sarbagyastha Dec 30, 2022
4340712
:white_check_mark: added gateway test
sarbagyastha Jan 2, 2023
41bbf5b
:white_check_mark: added use case tests
sarbagyastha Jan 2, 2023
5033bca
:white_check_mark: added use case transformer tests
sarbagyastha Jan 2, 2023
2247aae
:white_check_mark: refined transformer tests
sarbagyastha Jan 2, 2023
5bba046
:rotating_light: made analyzer happy
sarbagyastha Jan 2, 2023
8765f80
Merge pull request #96 from MattHamburger/pv2-tests
sarbagya-acme Jan 2, 2023
3a488a6
:sparkles: everything is place for example
sarbagyastha Jan 3, 2023
2cf04e3
:bug: fixed issue while using old classes
sarbagyastha Jan 4, 2023
3b82918
:lipstick: added palette card
sarbagyastha Jan 4, 2023
b472d6a
:lipstick: design improvements
sarbagyastha Jan 4, 2023
50fab77
:lipstick: show pokemon name in caps
sarbagyastha Jan 4, 2023
f443dc0
:lipstick: design refinement
sarbagyastha Jan 4, 2023
b92e2b5
:bug: minor fix
sarbagyastha Jan 4, 2023
e8643f2
:sparkles: added pokemon search
sarbagyastha Jan 4, 2023
06394cd
:art: added pokemon search field widget
sarbagyastha Jan 4, 2023
63dc8fa
:art: added pokemon card widget
sarbagyastha Jan 4, 2023
d0ccfcc
:sparkles: added refresh indicator
sarbagyastha Jan 4, 2023
f61c0a8
:sparkles: added loading failed ui
sarbagyastha Jan 4, 2023
700e5d4
:sparkles: implemented router
sarbagyastha Jan 4, 2023
8fa64f0
:sparkles: added profile page
sarbagyastha Jan 4, 2023
c890420
:sparkles: added cached image
sarbagyastha Jan 4, 2023
43171bc
:sparkles: added spotlight image
sarbagyastha Jan 5, 2023
deb247a
:lipstick: improved transition
sarbagyastha Jan 5, 2023
5df94e9
:lipstick: setup spotlight
sarbagyastha Jan 5, 2023
8c70f46
:sparkles: added pokemon profile gateway
sarbagyastha Jan 5, 2023
dd1d739
:bug: minor fix
sarbagyastha Jan 5, 2023
b674d88
:sparkles: added pokemon type
sarbagyastha Jan 5, 2023
f13d95c
:sparkles: added pokemon description
sarbagyastha Jan 5, 2023
34a7a3e
:sparkles: added height weight
sarbagyastha Jan 5, 2023
f6d739a
:lipstick: fixed gradient
sarbagyastha Jan 5, 2023
339f24a
:lipstick: minor fix
sarbagyastha Jan 5, 2023
76b37e4
:truck: moved models to separate dir
sarbagyastha Jan 5, 2023
0a575db
:bug: minor fix
sarbagyastha Jan 5, 2023
27ef795
:art:
sarbagyastha Jan 5, 2023
55ee486
:sparkles: added stats
sarbagyastha Jan 5, 2023
be2df0e
:white_check_mark:
sarbagyastha Jan 5, 2023
ed6cd45
:white_check_mark: fixed failing test
sarbagyastha Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ added refresh indicator
  • Loading branch information
sarbagyastha committed Jan 4, 2023
commit d0ccfcc4ba2036ad30a711a7c77112b6b3cdfe81
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
import 'package:clean_framework/clean_framework_core.dart';

enum HomeStatus { initial, loading, loaded, failed }

enum HomeRefreshStatus { initial, succeeded, failed }

class HomeEntity extends Entity {
HomeEntity({
this.pokemons = const [],
this.pokemonNameQuery = '',
this.status = HomeStatus.initial,
this.isRefresh = false,
});

final List<PokemonModel> pokemons;
final String pokemonNameQuery;
final HomeStatus status;
final bool isRefresh;

@override
List<Object?> get props => [pokemons, pokemonNameQuery];
List<Object?> get props {
return [pokemons, pokemonNameQuery, status, isRefresh];
}

@override
HomeEntity copyWith({
List<PokemonModel>? pokemons,
String? pokemonNameQuery,
HomeStatus? status,
bool? isRefresh,
}) {
return HomeEntity(
pokemons: pokemons ?? this.pokemons,
pokemonNameQuery: pokemonNameQuery ?? this.pokemonNameQuery,
status: status ?? this.status,
isRefresh: isRefresh ?? this.isRefresh,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/features/home/domain/home_entity.dart';

class HomeUIOutput extends Output {
HomeUIOutput({required this.pokemons});
HomeUIOutput({
required this.pokemons,
required this.isRefresh,
});

final List<PokemonModel> pokemons;
final bool isRefresh;

@override
List<Object?> get props => [pokemons];
List<Object?> get props => [pokemons, isRefresh];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:clean_framework_example/features/home/domain/home_entity.dart';
import 'package:clean_framework_example/features/home/domain/home_ui_output.dart';
import 'package:clean_framework_example/features/home/external_interface/pokemon_collection_gateway.dart';

const _spritesBaseUrl =
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites';

class HomeUseCase extends UseCase<HomeEntity> {
HomeUseCase()
: super(
Expand All @@ -13,25 +16,40 @@ class HomeUseCase extends UseCase<HomeEntity> {
],
);

void init() {
request<PokemonCollectionGatewayOutput, PokemonCollectionSuccessInput>(
Future<void> fetchPokemons({bool isRefresh = false}) async {
if (!isRefresh) {
entity = entity.copyWith(status: HomeStatus.loading);
}

await request<PokemonCollectionGatewayOutput,
PokemonCollectionSuccessInput>(
PokemonCollectionGatewayOutput(),
onSuccess: (success) {
final pokemons = success.pokemonIdentities.map(_resolvePokemon);

return entity.copyWith(
pokemons: success.pokemonIdentities
.map(_resolvePokemon)
.toList(growable: false),
pokemons: pokemons.toList(growable: false),
status: HomeStatus.loaded,
isRefresh: isRefresh,
);
},
onFailure: (failure) {
return entity.copyWith(
status: HomeStatus.failed,
isRefresh: isRefresh,
);
},
onFailure: (failure) => entity,
);

if (isRefresh) {
entity = entity.copyWith(isRefresh: false);
}
}

PokemonModel _resolvePokemon(PokemonIdentity pokemon) {
return PokemonModel(
name: pokemon.name.toUpperCase(),
imageUrl:
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/dream-world/${pokemon.id}.svg',
imageUrl: '$_spritesBaseUrl/pokemon/other/dream-world/${pokemon.id}.svg',
);
}
}
Expand All @@ -56,6 +74,7 @@ class HomeUIOutputTransformer

return HomeUIOutput(
pokemons: filteredPokemons.toList(growable: false),
isRefresh: entity.isRefresh,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ class HomePresenter

@override
void onLayoutReady(BuildContext context, HomeUseCase useCase) {
useCase.init();
useCase.fetchPokemons();
}

@override
void onOutputUpdate(BuildContext context, HomeUIOutput output) {
if (output.isRefresh) {}
}

@override
HomeViewModel createViewModel(HomeUseCase useCase, HomeUIOutput output) {
return HomeViewModel(
pokemons: output.pokemons,
onSearch: (query) => useCase.setInput(PokemonSearchInput(name: query)),
onRefresh: () => useCase.fetchPokemons(isRefresh: true),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ class HomeUI extends UI<HomeViewModel> {
),
bottom: PokemonSearchField(onChanged: viewModel.onSearch),
),
body: ListView.builder(
prototypeItem: SizedBox(height: 176), // 160 + 16
padding: EdgeInsets.symmetric(horizontal: 16),
itemBuilder: (context, index) {
final pokemon = viewModel.pokemons[index];
body: RefreshIndicator(
onRefresh: viewModel.onRefresh,
child: Scrollbar(
thumbVisibility: true,
child: ListView.builder(
prototypeItem: SizedBox(height: 176), // 160 + 16
padding: EdgeInsets.symmetric(horizontal: 16),
itemBuilder: (context, index) {
final pokemon = viewModel.pokemons[index];

return PokemonCard(
imageUrl: pokemon.imageUrl,
name: pokemon.name,
);
},
itemCount: viewModel.pokemons.length,
return PokemonCard(
imageUrl: pokemon.imageUrl,
name: pokemon.name,
);
},
itemCount: viewModel.pokemons.length,
),
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import 'package:flutter/foundation.dart';
class HomeViewModel extends ViewModel {
HomeViewModel({
required this.pokemons,
required this.onRefresh,
required this.onSearch,
});

final List<PokemonModel> pokemons;

final AsyncCallback onRefresh;
final ValueChanged<String> onSearch;

@override
Expand Down