Skip to content

teasec4/flutter-crypto-app

Repository files navigation

πŸ’° Flutter Crypto App

A modern cryptocurrency and NFT tracking application built with Flutter, demonstrating Clean Architecture principles and best practices in modern mobile development.

Flutter Dart Architecture State Management


πŸ“Έ Screenshots

Market NFT
Market NFT

✨ Features

  • πŸ’° Cryptocurrency Tracking – Real-time crypto market data from CoinGecko
  • 🎨 NFT Marketplace – Browse NFT collections via Reservoir API
  • ⭐ Favorites System – Save and manage your favorite coins and NFTs
  • πŸ” Authentication – Secure user authentication with Supabase
  • πŸ“Š Detailed Analytics – View comprehensive coin and NFT details
  • πŸŒ™ Theme Support – Light and dark mode
  • πŸ“± Responsive Design – Optimized for all screen sizes

πŸ—οΈ Architecture

This project follows Clean Architecture principles with clear separation of concerns across three layers:

lib/
β”œβ”€β”€ core/                          # Shared utilities and base classes
β”‚   β”œβ”€β”€ di/                        # Dependency injection (GetIt)
β”‚   β”œβ”€β”€ routing/                   # Navigation configuration (GoRouter)
β”‚   β”œβ”€β”€ theme/                     # App theming
β”‚   β”œβ”€β”€ widgets/                   # Shared widgets
β”‚   β”œβ”€β”€ logger/                    # Logging utilities
β”‚   β”œβ”€β”€ utils/                     # Helper functions & retry strategies
β”‚   └── exceptions/                # Custom exceptions
β”œβ”€β”€ features/                      # Feature modules
β”‚   β”œβ”€β”€ coin/                      # Cryptocurrency feature
β”‚   β”‚   β”œβ”€β”€ data/                  # Data layer
β”‚   β”‚   β”‚   β”œβ”€β”€ coin_repository_impl.dart  # Repository implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ coin_mapper.dart   # Data mapping
β”‚   β”‚   β”‚   └── coin_service.dart  # API service (legacy)
β”‚   β”‚   β”œβ”€β”€ domain/                # Business logic layer
β”‚   β”‚   β”‚   β”œβ”€β”€ coin.dart          # Domain entity
β”‚   β”‚   β”‚   └── coin_repository.dart # Repository interface
β”‚   β”‚   └── presentation/          # UI layer
β”‚   β”‚       β”œβ”€β”€ pages/             # Screens
β”‚   β”‚       β”œβ”€β”€ bloc/              # BLoC for state management
β”‚   β”‚       └── widgets/           # Feature-specific widgets
β”‚   β”œβ”€β”€ auth/                      # Authentication feature
β”‚   β”‚   β”œβ”€β”€ data/                  # Auth service & data layer
β”‚   β”‚   β”œβ”€β”€ domain/                # User model
β”‚   β”‚   └── presentation/          # Login/Signup pages & Cubit
β”‚   β”œβ”€β”€ profile/                   # User profile feature
β”‚   └── globalmarket/              # Global market data feature

🧩 Architecture Layers

Data Layer

  • API services for external data sources
  • Data models with JSON serialization
  • Repository implementations
  • Local storage management

Domain Layer

  • Business entities
  • Repository interfaces
  • Use cases (business logic)

Presentation Layer

  • UI screens and widgets
  • Riverpod providers for state management
  • View models

πŸ› οΈ Tech Stack

Core

  • Flutter SDK: 3.9+
  • Dart: 3.9.2+
  • Architecture: Clean Architecture
  • State Management: BLoC / Cubit (flutter_bloc)
  • DI Container: GetIt
  • Navigation: GoRouter

Key Dependencies

Package Purpose
flutter_bloc State management (BLoC/Cubit pattern)
get_it Service locator & dependency injection
go_router Declarative routing & navigation
fpdart Functional programming (Either for error handling)
supabase_flutter Backend-as-a-Service (Auth + Database)
http HTTP client for API requests
equatable Value equality for BLoC states
shared_preferences Local data persistence

πŸ“¦ API Integrations

πŸͺ™ CoinGecko API

Free cryptocurrency data API providing:

  • Market data for 10,000+ cryptocurrencies
  • Price charts and historical data
  • Market statistics and trends
  • No API key required

Base URL: https://api.coingecko.com/api/v3/


🎨 Reservoir API

NFT marketplace aggregator providing:

  • NFT collection data
  • Floor prices and sales
  • Collection metadata

Base URL: https://api.reservoir.tools/
(May require API key for production)


🧰 Supabase

Used for:

  • User authentication (email/password)
  • Session management
  • Database operations

πŸš€ Getting Started

🧱 Prerequisites

  • Flutter SDK 3.9 or higher
  • Dart 3.9.2 or higher
  • iOS Simulator / Android Emulator or physical device
  • Supabase account (for authentication features)

πŸ”§ Installation

1️⃣ Clone the repository

git clone https://github.com/teasec4/flutter-crypto-app.git
cd flutter-crypto-app

2️⃣ Install dependencies

flutter pub get

3️⃣ Configure Supabase

Create file lib/core/secrets/app_secrets.dart:

class AppSecrets {
  static const String supabaseUrl = 'YOUR_SUPABASE_URL';
  static const String supabaseAnonKey = 'YOUR_SUPABASE_ANON_KEY';
}

Get your credentials from Supabase:

  • Create a new project
  • Go to Settings β†’ API
  • Copy the Project URL and anon/public key

4️⃣ Run the app

flutter run

5️⃣ Build for production

πŸ“± Android

flutter build apk --release
# or
flutter build appbundle --release

🍎 iOS

flutter build ios --release

🎯 Project Structure Highlights

🧩 Dependency Injection with GetIt

void setupServiceLocator() {
  // Register repositories
  getIt.registerSingleton<CoinRepository>(CoinRepositoryImpl());
  
  // Register BLoCs/Cubits
  getIt.registerSingleton<CoinBloc>(
    CoinBloc(getIt<CoinRepository>(), getIt<RetryStrategy>()),
  );
}

πŸŒ€ State Management with BLoC

class CoinBloc extends Bloc<CoinEvent, CoinState> {
  CoinBloc(this._repo, this._retryStrategy) : super(const CoinInitial()) {
    on<CoinInitialLoad>(_onInitialLoad);
    on<CoinLoadMore>(_onLoadMore);
  }
  
  Future<void> _onInitialLoad(CoinInitialLoad event, Emitter<CoinState> emit) async {
    emit(const CoinLoading());
    try {
      final coins = await _repo.getCoins(page: 1, perPage: 30);
      emit(CoinLoaded(coins: coins));
    } catch (e) {
      emit(CoinError(e.toString()));
    }
  }
}

🧠 Authentication with Cubit

class AuthCubit extends Cubit<AuthState> {
  AuthCubit(this._service) : super(const AuthInitial());
  
  Future<void> signIn({required String email, required String password}) async {
    emit(const AuthLoading());
    final result = await _service.signIn(email: email, password: password);
    result.match(
      (failure) => emit(AuthError(failure.message)),
      (user) => emit(AuthAuthenticated(user)),
    );
  }
}

πŸ—ΊοΈ Type-Safe Navigation with Go Router

GoRouter(
  redirect: (context, state) {
    final authState = getIt<AuthCubit>().state;
    final isAuthenticated = authState is AuthAuthenticated;
    // Smart redirects based on auth state
  },
  routes: [
    GoRoute(path: '/coins', builder: (context, state) => const CoinPage()),
    GoRoute(
      path: '/coins/details/:id',
      builder: (context, state) {
        final coin = state.extra as Coin;
        return CoinDetailPage(coin: coin);
      },
    ),
  ],
);

πŸ“š What You Can Learn

βœ… Clean Architecture – Proper separation of concerns
βœ… BLoC/Cubit Pattern – Scalable state management
βœ… GetIt – Service locator for dependency injection
βœ… Go Router – Type-safe declarative navigation
βœ… Repository Pattern – Clean data abstraction layer
βœ… Functional Programming – Either type for error handling
βœ… Supabase Integration – Firebase alternative for Auth & Database
βœ… API Integration – REST API consumption with proper error handling
βœ… Retry Strategy – Exponential backoff for resilient requests
βœ… Authentication Guards – Route protection based on auth state


πŸ§ͺ Testing

# Run all tests
flutter test

# Run with coverage
flutter test --coverage

# Run integration tests
flutter test integration_test

πŸ“± Features Breakdown

πŸͺ™ Coin Feature

  • Browse cryptocurrency market
  • Search and filter coins
  • View detailed coin information
  • Price charts and statistics
  • Add to favorites

🎨 NFT Feature

  • Explore NFT collections
  • View collection details
  • Floor prices and volume
  • Metadata display

⭐ Favorites Feature

  • Save favorite coins & NFTs
  • Local persistence
  • Quick access to saved items

πŸ” Auth Feature

  • Email/password authentication
  • Session management
  • Protected routes
  • User profile

βš™οΈ Configuration

Example environment config:

class EnvConfig {
  static const bool isProduction = bool.fromEnvironment('dart.vm.product');
  static const String apiBaseUrl = String.fromEnvironment(
    'API_BASE_URL',
    defaultValue: 'https://api.coingecko.com/api/v3/',
  );
}

Run with:

flutter run --dart-define=API_BASE_URL=https://your-api.com

🀝 Contributing

  1. Fork the project
  2. Create a feature branch:
    git checkout -b feature/AmazingFeature
  3. Commit your changes:
    git commit -m 'Add some AmazingFeature'
  4. Push to the branch:
    git push origin feature/AmazingFeature
  5. Open a Pull Request

πŸ“„ License

This project was created for educational purposes.


πŸ‘€ Author

teasec4


πŸ™ Acknowledgments

  • CoinGecko – for free crypto API
  • Reservoir – for NFT data
  • Supabase – for backend services
  • Flutter & Dart communities for excellent tools

πŸ“– Resources


⭐️ If this project helped you learn Flutter and Clean Architecture, give it a star!

About

Educational crypto & NFT tracking app built with Flutter, Riverpod, and Clean Architecture

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published