此為參加 Flutter Best Architecture Challenge 活動的專案
-
Reso Coder's Flutter Clean Architecture Proposal, reference: TDD Clean Architecture
-
Separate into 3 layers:
- Presentation Layer
FetchPostsBloc
,FetchPostsEvent
,FetchPostsState
- Handles basic input conversion and validation.PostPage
PostView
- Doamin Layer
FetchPost
- Use case, handle business logic.FetchPostRepository
- Interface between domain and data layer.Post
,SortBy
- Entities.
- Data Layer
FetchPostRepositoryImpl
- Implementation of repositoryPostModel
- Model extends entities, knowing infrastructure detail.FetchPostDataRemoteDataSource
,FetchPostDataRemoteDataSourceImpl
- Interface & implementation of remote data source
- Presentation Layer
-
Graph:
-
Pros:
- Make testing easier.
- Allow independent development.
- More reusable components.
-
Cons:
- Split into many modules, more complex.
- Service Locator is an Anti-Pattern.
- Maybe more time comsuption.
- get_it - Setting up a service locator, for injecting dependencies
- flutter_bloc - For BLoC design pattern
- equatable - For value based equality
- dartz - For some functional programming tools
- bloc_test - Easy to test blocs
- mockito - APIs for Fakes, Mocks..etc
- build_runner - For for Dart code generation
- http - Future-based API for HTTP requests
- Use case tests: test fetch data when failure/empty/success (sorted by id/title).
- Repository tests: test fetch data when failure/empty/success.
- Remote data source tests: test fetch data when http status code is 200/404.
- Bloc tests: test initial state, load data state when failure/success.
Flutter 2.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 02c026b03c (5 weeks ago) • 2021-05-27 12:24:44 -0700
Engine • revision 0fdb562ac8
Tools • Dart 2.13.1