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
✨ everything is place for example
  • Loading branch information
sarbagyastha committed Jan 3, 2023
commit 3a488a62864b1cd5916c10d474af6ecf8678cc41
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/core/pokemon/pokemon_request.dart';
import 'package:clean_framework_example/core/pokemon/pokemon_success_response.dart';
import 'package:dio/dio.dart';

class PokemonExternalInterface
extends ExternalInterface<PokemonRequest, PokemonSuccessResponse> {
PokemonExternalInterface({
Dio? dio,
}) : _dio = dio ?? Dio(BaseOptions(baseUrl: 'https://pokeapi.co/api/v2/'));

final Dio _dio;

@override
void handleRequest() {
on<GetPokemonRequest>(
(request, send) async {
final response = await _dio.get<Map<String, dynamic>>(
request.resource,
queryParameters: request.queryParams,
);

final data = response.data!;

send(PokemonSuccessResponse(data: data));
},
);
}

@override
FailureResponse onError(Object error) {
return UnknownFailureResponse(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:clean_framework/clean_framework_core.dart';

abstract class PokemonRequest extends Request {
Map<String, dynamic> get queryParams => {};
}

abstract class GetPokemonRequest extends PokemonRequest {
String get resource;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:clean_framework/clean_framework_core.dart';

class PokemonSuccessResponse extends SuccessResponse {
PokemonSuccessResponse({required this.data});

final Map<String, dynamic> data;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import 'package:clean_framework/clean_framework_core.dart';

class HomeEntity extends Entity {
HomeEntity({this.pokemons = const []});

final List<String> pokemons;

@override
List<Object?> get props => [pokemons];

@override
List<Object?> get props => [];
HomeEntity copyWith({List<String>? pokemons}) {
return HomeEntity(pokemons: pokemons ?? this.pokemons);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:clean_framework/clean_framework_core.dart';

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

final List<String> pokemons;

@override
List<Object?> get props => [pokemons];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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/external_interface/pokemon_collection_gateway.dart';

class HomeUseCase extends UseCase<HomeEntity> {
HomeUseCase()
: super(
entity: HomeEntity(),
transformers: [
HomeUIOutputTransformer(),
],
);

void init() {
request<PokemonCollectionGatewayOutput, PokemonCollectionSuccessInput>(
PokemonCollectionGatewayOutput(),
onSuccess: (success) => entity.copyWith(pokemons: success.pokemonNames),
onFailure: (failure) => entity,
);
}
}

class HomeUIOutputTransformer
extends OutputTransformer<HomeEntity, HomeUIOutput> {
@override
HomeUIOutput transform(HomeEntity entity) {
return HomeUIOutput(pokemons: entity.pokemons);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/core/pokemon/pokemon_request.dart';
import 'package:clean_framework_example/core/pokemon/pokemon_success_response.dart';

class PokemonCollectionGateway extends Gateway<
PokemonCollectionGatewayOutput,
PokemonCollectionRequest,
PokemonSuccessResponse,
PokemonCollectionSuccessInput> {
@override
PokemonCollectionRequest buildRequest(PokemonCollectionGatewayOutput output) {
return PokemonCollectionRequest();
}

@override
FailureInput onFailure(FailureResponse failureResponse) {
return FailureInput(message: failureResponse.message);
}

@override
PokemonCollectionSuccessInput onSuccess(PokemonSuccessResponse response) {
final deserializer = Deserializer(response.data);

return PokemonCollectionSuccessInput(
pokemonNames: deserializer.getList(
'results',
converter: (result) => result['name'],
),
);
}
}

class PokemonCollectionGatewayOutput extends Output {
@override
List<Object?> get props => [];
}

class PokemonCollectionSuccessInput extends SuccessInput {
PokemonCollectionSuccessInput({
required this.pokemonNames,
});

final List<String> pokemonNames;
}

class PokemonCollectionRequest extends GetPokemonRequest {
@override
String get resource => 'pokemon';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:clean_framework/clean_framework_core.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';
import 'package:clean_framework_example/providers.dart';
import 'package:flutter/material.dart';

class HomePresenter
extends Presenter<HomeViewModel, HomeUIOutput, HomeUseCase> {
HomePresenter({
required super.builder,
}) : super(provider: homeUseCaseProvider);

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

@override
HomeViewModel createViewModel(HomeUseCase useCase, HomeUIOutput output) {
return HomeViewModel(pokemons: output.pokemons);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/features/home/presentation/home_presenter.dart';
import 'package:clean_framework_example/features/home/presentation/home_view_model.dart';
import 'package:flutter/material.dart';

class HomeUI extends UI<HomeViewModel> {
@override
HomePresenter create(PresenterBuilder<HomeViewModel> builder) {
return HomePresenter(builder: builder);
}

@override
Widget build(BuildContext context, HomeViewModel viewModel) {
return Scaffold(
appBar: AppBar(
title: Text('Pokemon'),
),
body: ListView.builder(
itemBuilder: (context, index) => Text(viewModel.pokemons[index]),
itemCount: viewModel.pokemons.length,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:clean_framework/clean_framework_core.dart';

class HomeViewModel extends ViewModel {
HomeViewModel({required this.pokemons});

final List<String> pokemons;

@override
List<Object?> get props => [pokemons];
}
120 changes: 21 additions & 99 deletions packages/clean_framework/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,115 +1,37 @@
import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/features/home/presentation/home_ui.dart';
import 'package:clean_framework_example/providers.dart';
import 'package:flutter/material.dart';
import 'package:stack_trace/stack_trace.dart' as stack_trace;

final container = ProviderContainer();

void main() {
FlutterError.demangleStackTrace = (StackTrace stack) {
if (stack is stack_trace.Trace) return stack.vmTrace;
if (stack is stack_trace.Chain) return stack.toTrace().vmTrace;
return stack;
};
initializeExternalInterfaces(container);

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
return ProviderScope(
parent: container,
child: MaterialApp(
title: 'Clean Framework Example',
theme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent),
useMaterial3: true,
),
home: HomeUI(),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
20 changes: 20 additions & 0 deletions packages/clean_framework/example/lib/providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:clean_framework/clean_framework_core.dart';
import 'package:clean_framework_example/core/pokemon/pokemon_external_interface.dart';
import 'package:clean_framework_example/features/home/domain/home_use_case.dart';
import 'package:clean_framework_example/features/home/external_interface/pokemon_collection_gateway.dart';

final homeUseCaseProvider = UseCaseProvider(HomeUseCase.new);

final pokemonCollectionGateway = GatewayProvider(
PokemonCollectionGateway.new,
useCases: [homeUseCaseProvider],
);

final pokemonExternalInterfaceProvider = ExternalInterfaceProvider(
PokemonExternalInterface.new,
gateways: [pokemonCollectionGateway],
);

void initializeExternalInterfaces(ProviderContainer container) {
pokemonExternalInterfaceProvider.initializeFor(container);
}
1 change: 1 addition & 0 deletions packages/clean_framework/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
flutter:
sdk: flutter
clean_framework: ^1.5.0
dio: ^4.0.6

dev_dependencies:
flutter_test:
Expand Down
2 changes: 2 additions & 0 deletions packages/clean_framework/lib/clean_framework_core.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export 'package:clean_framework/src/core/core.dart';
export 'package:clean_framework/src/presentation/presentation.dart';
export 'package:flutter_riverpod/flutter_riverpod.dart'
show ProviderContainer, ProviderScope;
Loading