- Presentation Layer (UI, Cubit, States)
- Domain Layer (Use Cases, Repository Contracts)
- Data Layer (Repository Implementation, Services, Models)
- Dependency Injection using GetIt
- Cubit
- States
- BlocProvider
- BlocBuilder
- BlocConsumer
- State-driven UI
- Fetch a single post from API
- Convert JSON into PostModel
- Fetch a list of posts
- Parse JSON array into List
- Send data to API using Dio POST request
- Convert PostModel to JSON using toJson()
- Handle loading, success, and error states
Used Dio queryParameters:
_page=1
_limit=10
Used ScrollController to detect when the user reaches the bottom of the list.
Maintained current page number:
int page = 1;
Used:
allPosts.addAll(posts);
to append new data instead of replacing existing data.
Implemented separate loading state for pagination while keeping existing posts visible.
Used:
if (isLoadingMore) return;
to avoid multiple API calls.
Used:
bool hasMore = true;
and stopped API requests when an empty list was returned.
Managed:
- posts
- isLoadingMore
- hasMore
through state objects so the UI could react accordingly.
- ListView.builder
- ScrollController
- CircularProgressIndicator
- TextFormField
- ElevatedButton
- Card
- Scaffold
- AppBar
Used GetIt for:
- Services
- Repositories
- Use Cases
- Cubits
presentation/ ├── cubits ├── states ├── screens
domain/ ├── repositories ├── usecases
data/ ├── models ├── repositories ├── services