Skip to content

MToheed/api_learning_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What I Learned

Clean Architecture

  • Presentation Layer (UI, Cubit, States)
  • Domain Layer (Use Cases, Repository Contracts)
  • Data Layer (Repository Implementation, Services, Models)
  • Dependency Injection using GetIt

State Management

  • Cubit
  • States
  • BlocProvider
  • BlocBuilder
  • BlocConsumer
  • State-driven UI

REST APIs with Dio

GET Single Post

  • Fetch a single post from API
  • Convert JSON into PostModel

GET Posts List

  • Fetch a list of posts
  • Parse JSON array into List

POST Create Post

  • Send data to API using Dio POST request
  • Convert PostModel to JSON using toJson()
  • Handle loading, success, and error states

Pagination

Query Parameters

Used Dio queryParameters:

_page=1

_limit=10

ScrollController

Used ScrollController to detect when the user reaches the bottom of the list.

Page Tracking

Maintained current page number:

int page = 1;

Append vs Replace

Used:

allPosts.addAll(posts);

to append new data instead of replacing existing data.

Loading More

Implemented separate loading state for pagination while keeping existing posts visible.

Prevent Duplicate Requests

Used:

if (isLoadingMore) return;

to avoid multiple API calls.

End of Data Detection

Used:

bool hasMore = true;

and stopped API requests when an empty list was returned.

Pagination States

Managed:

  • posts
  • isLoadingMore
  • hasMore

through state objects so the UI could react accordingly.

Flutter Widgets Used

  • ListView.builder
  • ScrollController
  • CircularProgressIndicator
  • TextFormField
  • ElevatedButton
  • Card
  • Scaffold
  • AppBar

Dependency Injection

Used GetIt for:

  • Services
  • Repositories
  • Use Cases
  • Cubits

Project Structure

presentation/ ├── cubits ├── states ├── screens

domain/ ├── repositories ├── usecases

data/ ├── models ├── repositories ├── services

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors