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 loading failed ui
  • Loading branch information
sarbagyastha committed Jan 4, 2023
commit f61c0a818593bfba1bf166ab2c7dac50fa6f2ccd
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ 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 [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import 'package:clean_framework_example/features/home/domain/home_entity.dart';
class HomeUIOutput extends Output {
HomeUIOutput({
required this.pokemons,
required this.status,
required this.isRefresh,
});

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

@override
List<Object?> get props => [pokemons, isRefresh];
List<Object?> get props => [pokemons, status, isRefresh];
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class HomeUIOutputTransformer

return HomeUIOutput(
pokemons: filteredPokemons.toList(growable: false),
status: entity.status,
isRefresh: entity.isRefresh,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:clean_framework/clean_framework_core.dart';
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/domain/home_use_case.dart';
import 'package:clean_framework_example/features/home/presentation/home_view_model.dart';
Expand All @@ -16,17 +17,30 @@ class HomePresenter
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),
onRetry: useCase.fetchPokemons,
isLoading: output.status == HomeStatus.loading,
hasFailedLoading: output.status == HomeStatus.failed,
);
}

@override
void onOutputUpdate(BuildContext context, HomeUIOutput output) {
if (output.isRefresh) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
output.status == HomeStatus.failed
? 'Sorry, failed refreshing pokemons!'
: 'Refreshed pokemons successfully!',
),
),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ class HomeUI extends UI<HomeViewModel> {
Widget build(BuildContext context, HomeViewModel viewModel) {
final textTheme = Theme.of(context).textTheme;

return Scaffold(
appBar: AppBar(
title: Text('Pokémon'),
centerTitle: false,
titleTextStyle: textTheme.displaySmall!.copyWith(
fontWeight: FontWeight.w300,
),
bottom: PokemonSearchField(onChanged: viewModel.onSearch),
),
body: RefreshIndicator(
Widget child;
if (viewModel.isLoading) {
child = Center(child: CircularProgressIndicator());
} else if (viewModel.hasFailedLoading) {
child = _LoadingFailed(onRetry: viewModel.onRetry);
} else {
child = RefreshIndicator(
onRefresh: viewModel.onRefresh,
child: Scrollbar(
thumbVisibility: true,
Expand All @@ -42,6 +39,55 @@ class HomeUI extends UI<HomeViewModel> {
itemCount: viewModel.pokemons.length,
),
),
);
}

return Scaffold(
appBar: AppBar(
title: Text('Pokémon'),
centerTitle: false,
titleTextStyle: textTheme.displaySmall!.copyWith(
fontWeight: FontWeight.w300,
),
bottom: viewModel.isLoading || viewModel.hasFailedLoading
? null
: PokemonSearchField(onChanged: viewModel.onSearch),
),
body: child,
);
}
}

class _LoadingFailed extends StatelessWidget {
const _LoadingFailed({required this.onRetry});

final VoidCallback onRetry;

@override
Widget build(BuildContext context) {
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Image.asset('assets/sad-flareon.png', height: 300),
),
const SizedBox(height: 8),
Text(
'Oops',
style: Theme.of(context).textTheme.displaySmall,
),
const SizedBox(height: 8),
Text('I lost my fellow Pokémons'),
const SizedBox(height: 24),
OutlinedButton(
onPressed: onRetry,
child: Text('Help Flareon, find her friends'),
),
const SizedBox(height: 64),
],
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import 'package:flutter/foundation.dart';
class HomeViewModel extends ViewModel {
HomeViewModel({
required this.pokemons,
required this.isLoading,
required this.hasFailedLoading,
required this.onRetry,
required this.onRefresh,
required this.onSearch,
});

final List<PokemonModel> pokemons;
final bool isLoading;
final bool hasFailedLoading;

final VoidCallback onRetry;
final AsyncCallback onRefresh;
final ValueChanged<String> onSearch;

@override
List<Object?> get props => [pokemons];
List<Object?> get props => [pokemons, isLoading, hasFailedLoading];
}
5 changes: 4 additions & 1 deletion packages/clean_framework/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ dev_dependencies:
sdk: flutter

flutter:
uses-material-design: true
uses-material-design: true

assets:
- assets/