https://github.com/workwithafridi/nsm_flutter
A Flutter App build entirely using ChangeNotifier and InheritedNotifier, no 3rd party state management packages or setStates.
https://github.com/workwithafridi/nsm_flutter
Last synced: 3 months ago
JSON representation
A Flutter App build entirely using ChangeNotifier and InheritedNotifier, no 3rd party state management packages or setStates.
- Host: GitHub
- URL: https://github.com/workwithafridi/nsm_flutter
- Owner: WorkWithAfridi
- Created: 2025-02-17T12:34:22.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-17T12:44:06.000Z (3 months ago)
- Last Synced: 2025-02-17T13:38:29.889Z (3 months ago)
- Language: C++
- Size: 266 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flutter State Management (Without Packages)
## 📌 Overview
This Flutter project demonstrates **state management without external packages** like `provider` or `riverpod`. It includes:✅ **User authentication** (login/logout)
✅ **Fetching async data from an API**
✅ **Managing multiple ViewModels**
✅ **Efficient UI updates using ValueNotifier & InheritedNotifier**---
## 🏗 Project Structure
```
/lib
│── main.dart # App entry point
│
│── di
│ │── app_state.dart # Centralized store for all ViewModels
│ │── app_provider.dart # InheritedNotifier for state management
│
│── views
│ │── auth_v.dart # Login screen
│ │── home_v.dart # Home screen with API fetch & logout
│ │── counter_v.dart # Simple counter app
│
│── viewmodels
│ │── auth_vm.dart # Manages user authentication
│ │── posts_vm.dart # Handles API calls & data fetching
│ │── counter_vm.dart # Handles counter logic
│ │── theme_vm.dart # Handles theming data and logic
```---
## 🚀 How to Run
1. **Clone the repository**
```sh
git clone
cd
flutter pub get
```2. **Run the app**
```sh
flutter run
```---
## 📂 Explanation
### **🔹 State Management Approach**
- Uses **ValueNotifier** for efficient state updates.
- Uses **InheritedNotifier** (`AppProvider`) for dependency injection.### **🔹 Key Components**
- **Login Flow:** Users log in with a username → Stored in `AuthViewModel`
- **API Fetching:** Clicking 'Fetch Posts' fetches data asynchronously using `PostsViewModel`
- **Logout Flow:** Clicking logout clears session & redirects to login screen.---
## 🔧 Future Enhancements
- ✅ Persist user session using SharedPreferences
- ✅ Add error handling for network requests
- ✅ Implement a real backend API for authentication---
## 📝 License
This project is open-source and available for modification.