Skip to content

Latest commit

Β 

History

History
205 lines (154 loc) Β· 5.29 KB

File metadata and controls

205 lines (154 loc) Β· 5.29 KB

🧠 Flutter Clean Architecture Learning App

A complete Flutter learning project built to demonstrate best practices for:

  • Fetching data from APIs
  • Using BLoC/Cubit for state management
  • Implementing the Repository pattern
  • Organizing code with clean architecture
  • Applying router navigation for screens
  • Adding search functionality
  • Using Hero animations for smooth navigation transitions
  • Customizing SliverAppBar for better UX
  • Following clean linting rules and project conventions

πŸš€ Features

βœ…- Fetch data from REST API using Dio / WebServices layer βœ…- Manage state using BLoC / Cubit βœ…- Organize project with Repository Pattern βœ…- Navigation via AppRouters class βœ…- Implement Search filter inside GridView βœ…- Add Hero widget for transition between Character list and details βœ…- Beautiful SliverAppBar in details screen βœ…- Handle loading, success, and error states gracefully βœ…- Clean, modular, and readable project structure βœ…- Proper lint rules configuration in analysis_options.yaml


πŸ“‚ Project Structure

lib/
β”œβ”€β”€ business_logic/
β”‚   └── cubit/
β”‚       └── character_cubit.dart
β”œβ”€β”€ constants/
β”‚   β”œβ”€β”€ colors.dart
β”‚   └── strings.dart
β”œβ”€β”€ core/
β”‚   └── bloc_observer.dart
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── character.dart
β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   └── characters_repository.dart
β”‚   └── web_services/
β”‚       └── characters_web_services.dart
β”œβ”€β”€ presentation/
β”‚   β”œβ”€β”€ screens/
β”‚   β”‚   β”œβ”€β”€ characters_screen.dart
β”‚   β”‚   └── characters_details.dart
β”‚   └── widgets/
β”‚       └── character_item.dart
└── app_router.dart

This structure follows Clean Architecture principles:

  • WebServices β†’ responsible for API calls
  • Repository β†’ connects data layer and business logic
  • Cubit/BLoC β†’ handles states and logic
  • Presentation β†’ displays data in UI

βš™οΈ Technologies & Packages

Package Purpose
flutter_bloc State management
dio API networking
equatable Easier Cubit state comparisons
cached_network_image Efficient image loading
flutter_lints Enforcing code style
google_fonts Custom typography
animations For Hero and transitions

πŸ” Search Feature

Users can search for characters by name (case-insensitive). It filters results dynamically inside the GridView using Cubit state updates.


🎨 UI Highlights

  • CharactersScreen: Displays all characters in a responsive grid
  • CharacterItem: Card with image and name
  • CharacterDetailsScreen: Opens with smooth Hero transition + SliverAppBar
  • Error & Loading states handled elegantly using widgets
  • Consistent spacing, rounded corners, and shadows for a clean look

🧩 Routing

App navigation is managed by AppRouters:

switch (settings.name) {
  case ConstantStrings.characterScreen:
    return MaterialPageRoute(
      builder: (_) => BlocProvider(
        create: (context) => CharacterCubit(repository),
        child: const CharactersScreen(),
      ),
    );
  case ConstantStrings.characterScreenDetails:
    final character = settings.arguments as Character;
    return MaterialPageRoute(
      builder: (_) => CharactersDetails(character: character),
    );
}

🧱 State Management

Each feature has its own Cubit class (e.g. CharacterCubit) that:

  • Fetches data via Repository
  • Emits Loading β†’ Success β†’ Error states
  • Allows filtering (search)

Example:

class CharacterCubit extends Cubit<CharacterState> {
  final CharactersRepository charactersRepository;

  CharacterCubit(this.charactersRepository) : super(CharacterInitial());

  void getAllCharacters() async {
    emit(CharacterLoading());
    try {
      final characters = await charactersRepository.getAllCharacters();
      emit(CharacterLoaded(characters));
    } catch (e) {
      emit(CharacterError(e.toString()));
    }
  }
}

🧭 How to Run

  1. Clone the repository:

    git clone https://github.com/your-username/Characters.git
  2. Navigate to project folder:

    cd Characters
  3. Get dependencies:

    flutter pub get
  4. Run the app:

    flutter run

πŸŽ“ Learning Goals

This project is perfect for anyone who wants to:

  • Learn Flutter + BLoC/Cubit from a real example
  • Understand Clean Architecture pattern
  • Practice API fetching + Repository separation
  • Master navigation, search, and Hero animation
  • Write clean and lint-approved Flutter code

🀝 Contributing

Feel free to fork, open issues, and submit pull requests. This project is meant for learning and collaboration!


πŸ’¬ Author

Mohammad Hmedat πŸ‘¨β€πŸ’» - Software Engineer | Flutter & .NET Developer πŸ“š - Passionate about clean code, architecture, and building learning projects πŸ“§ - [humedat23@gmail.com]