https://github.com/itsnayan/sample_project
Sample Project
https://github.com/itsnayan/sample_project
dart dartpackage flutter flutter-apps http provider
Last synced: 9 months ago
JSON representation
Sample Project
- Host: GitHub
- URL: https://github.com/itsnayan/sample_project
- Owner: ITSNAYAN
- Created: 2025-07-09T12:28:47.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-07-10T06:38:50.000Z (9 months ago)
- Last Synced: 2025-07-10T15:10:59.437Z (9 months ago)
- Topics: dart, dartpackage, flutter, flutter-apps, http, provider
- Language: C++
- Homepage:
- Size: 272 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Objective:
Build a simple mobile app that shows a list of articles fetched from a dummy API, with a detail screen for each article.
What I Have Implemented (As per the given requirements):
List Screen:
Fetched data from: https://jsonplaceholder.typicode.com/posts
Displayed article titles in a scrollable ListView
Showed a loading indicator while data is being fetched
Added pull-to-refresh using RefreshIndicator
Kept the loading screen visible as the API server can be slow
Detail Screen:
Navigated to a detail screen when a list item is tapped
Displayed the full article title and body
Code Structure:
Used a proper folder structure:
models/ for data models
screens/ for UI screens
controllers/ for logic
services/ for API
components/ for reusable widgets
Used Provider for state management
Kept the code clean and readable
Bonus Features:
Added a favorite button to each list item and detail screen
Tracked favorite articles using a Map based on article ID
Created a separate Favorite screen to display liked articles only
Favorites are stored in app state using Provider logic
Challenges Faced:
API Call Timing in initState:
Initially used Provider.of(...).getAllApiData() in initState()
Faced issue where the loading spinner kept showing and no data appeared
Realized initState() runs before the widget tree builds completely, causing context issues
Tried WidgetsBinding.instance.addPostFrameCallback(), still inconsistent
Final solution was Future.delayed(Duration.zero) to ensure UI builds first, then API loads
Favorite Icon Toggling All Items:
Initially used a single boolean to manage favorite state
Tapping one favorite icon affected all items in the list
Solved by using each article’s unique ID and storing favorite states in a Map
Now each item toggles its favorite state independently and updates correctly