A Flutter-based news application that fetches real-time data from RESTful APIs, implements dynamic UI components, and follows best practices for state management and error handling. Built as part of Tharwat Samy's Flutter & Dart Development Course.
-
Dynamic UI:
ListView.builderfor optimized scrolling withBouncingScrollPhysics.CustomScrollViewandSliverListfor complex layouts.- Text truncation with
maxLinesandoverflow: TextOverflow.ellipsis. - Custom
BoxDecorationfor containers (border radius, images).
-
API Integration:
- RESTful API workflows using Dio (auto-JSON parsing).
- Secure authentication via API keys.
- Parameterized endpoints for data filtering.
-
State Management:
- Asynchronous data fetching using
FutureBuilder. - Lifecycle optimization with API calls in
initState. - Null-safety using
??,!, and conditional rendering.
- Asynchronous data fetching using
-
Error Handling:
try/catchblocks for network exceptions.- Loading indicators and UI feedback.
| Home Screen | Category View |
|---|---|
![]() |
![]() |
- Clone the repository:
git clone https://github.com/osaamaahmeed/News-App.git
- Install dependencies:
flutter pub get
- Run the app:
flutter run
Endpoints: Fetch news data using parameterized URLs (e.g., category filters).
Response Handling:
// Example using Dio
Future<List<NewsModel>> fetchNews() async {
final response = await Dio().get('https://newsapi.org/v2/top-headlines?country=us&apiKey=YourAPIKey&category=$category');
return (response.data as List).map((e) => NewsModel.fromJson(e)).toList();
}Note: Don't forget to use your API Key
JSON Parsing: Convert API responses to Dart objects using factory constructors:
factory NewsModel.fromJson(Map<String, dynamic> json) {
return NewsModel(
title: json['title'],
content: json['content'],
);
} lib/
├── models/ # Data classes (e.g., NewsModel)
├── services/ # API services (e.g., NewsService)
├── widgets/ # Reusable UI components
├── views/ # Screens (e.g., HomeScreen, CategoryScreen)
└── main.dart # App entry point-
UI Optimization: Avoided Expanded in ListView by using SizedBox for fixed heights.
-
Performance: Reduced rebuilds by separating logic into services/ and using shrinkWrap: true.
-
Debugging: Leveraged VS Code breakpoints to resolve state issues.
- Course Instructor: Tharwat Samy
- API Provider: NewsAPI.org

