Skip to content

MiroTheSuperDev/Assignment-1-and-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KaπŸ“„bar

Flutter β€’ Splash β†’ Onboarding β†’ Login β†’ Home

A modern Flutter application demonstrating a complete mobile authentication pipeline with Material Design 3. Built for university coursework showcasing API integration, state management, and professional UI/UX patterns.


Table of Contents


🧾 Overview

KaLbar is a Flutter application that demonstrates a typical mobile entry pipeline and authentication layer. The user experience progresses from a splash screen into a short onboarding sequence, followed by credential-based login and a post-authenticated home view.

Assignment Objectives

Assignment 1:

  • βœ… Splash screen implementation with animations
  • βœ… Onboarding screens (3 pages) with smooth transitions
  • βœ… Login screen GUI with form validation

Assignment 2:

  • βœ… Integration with DummyJSON Auth API
  • βœ… Dio package for HTTP requests
  • βœ… Success & failure result handling with user feedback

The project includes:

  • πŸ’¦ Splash screen with animated transitions
  • 🧭 Onboarding flow with page indicators
  • πŸ” Login screen with validation and error handling
  • 🏠 Home screen displaying authenticated user data
  • 🧩 Authentication model (AuthUser) and service (AuthService)

πŸ“± Features

  • Animated Splash Screen - Smooth entrance animation with fade and scale effects
  • Interactive Onboarding - Three-page walkthrough with swipe gestures
  • Form Validation - Real-time input validation with error messages
  • Loading States - Visual feedback during authentication
  • Error Handling - User-friendly error messages via SnackBar
  • Remember Me - Checkbox option for persistent sessions
  • Social Login UI - Facebook & Google button designs (UI-only)
  • Responsive Design - Adapts to various screen sizes
  • Material Design 3 - Modern theming with custom color scheme
  • Token Management - Access and refresh token handling

🧰 Core Components

πŸ’¦ Splash Screen

Renders a brief entrance animation with fade, scale, and lift effects, then automatically routes to onboarding after 1.4 seconds.

Features:

  • Animated logo with multiple synchronized animations
  • Precaches onboarding images for smooth transitions
  • Custom page route with fade transition

🧭 Onboarding Screen

Three swipeable pages implemented with PageView, featuring:

  • Dynamic page indicators (dots)
  • "Back" and "Next" navigation buttons
  • Animated button that expands to "Get Started" on final page
  • Smooth content animations on page change
  • Rounded card design with shadow effects

πŸ” Login Screen

Professional authentication interface with:

  • βœ… Required field validation (non-empty username and password)
  • ⏳ Loading state with circular progress indicator
  • 🎯 Success/failure result handling
  • πŸ”΄ Error indication with red border and close button
  • πŸ‘οΈ Password visibility toggle
  • β˜‘οΈ "Remember me" checkbox
  • πŸ”— "Forgot password" link (UI-only)
  • πŸ“± Social login buttons (UI-only)

🏠 Home Screen

Displays authenticated user information:

  • User avatar from API
  • Full name display
  • Username, email, and access token preview
  • Logout functionality with smooth transition

πŸš€ Getting Started

Prerequisites

  • βœ… Flutter SDK (3.0.0 or higher)
  • βœ… Dart SDK (3.0.0 or higher)
  • πŸ“± Android emulator, iOS simulator, or physical device
  • πŸ”§ Android Studio / VS Code with Flutter extensions

Installation

  1. Extract the project

    cd kalbar-app
  2. Install dependencies

    flutter pub get
  3. Run the app

    flutter run

Note: All assets (splash screen, onboarding images) are included in the project. No additional setup required!


πŸ” Navigation Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Splash    β”‚ (1.4s auto-transition)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Onboarding  β”‚ (3 pages, swipeable)
β”‚   Page 1    β”‚
β”‚   Page 2    β”‚
β”‚   Page 3    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚ "Get Started"
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Login    β”‚ (credential input)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚ Successful auth
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Home     β”‚ (user dashboard)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚ "Logout"
       └──────> Back to Login

All transitions use custom PageRouteBuilder with fade animations for a polished user experience.


πŸ” Authentication

Implementation

  • Service: AuthService (in-memory test accounts + DummyJSON API ready)
  • Model: AuthUser (contains id, username, email, name, tokens)
  • State Management: StatefulWidget with loading and error states

Contract

Future<AuthUser> AuthService.login({
required String username,
required String password,
})

Inputs:

  • username: String (trimmed, non-empty)
  • password: String (non-empty)

Output:

  • Returns AuthUser instance on success
  • Throws AuthException with error message on failure

Result Handling

βœ… Success Path

  1. 🧩 Returns populated AuthUser instance
  2. πŸ” Replaces login route with HomeScreen(user: user)
  3. πŸ’Ύ Displays user information on home screen

❌ Failure Path

  1. 🧯 Sets error state on username field (red border)
  2. πŸ’¬ Displays SnackBar with error message
  3. πŸ”΄ Shows close button to clear error state
  4. 🎯 Maintains form state for user correction

πŸ§ͺ Test Accounts

Use one of the following accounts to validate the success path:

Account Username Password
1 amir 123
2 test2 456
3 miro 789

To validate the failure path:

  • Submit an incorrect username and/or password
  • Observe error message: "Invalid username or password"
  • Note the red border on username field and SnackBar notification

πŸ“¦ Dependencies

Core Packages

dependencies:
  flutter:
    sdk: flutter
  google_fonts: ^6.1.0  # Poppins typography
  dio: ^5.4.0           # HTTP client for API integration

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0

Asset Configuration

flutter:
  assets:
    - assets/images/

Included Assets:

  • splash.png - App logo for splash screen
  • onboarding_1.png - First onboarding illustration
  • onboarding_2.png - Second onboarding illustration
  • onboarding_3.png - Third onboarding illustration

πŸ—οΈ Project Structure

lib/
β”œβ”€β”€ main.dart                    # App entry point and all components
β”‚   β”œβ”€β”€ KaLbarApp               # App shell with theme configuration
β”‚   β”œβ”€β”€ AppAssets               # Asset path constants
β”‚   β”œβ”€β”€ SplashScreen            # Animated splash screen
β”‚   β”œβ”€β”€ OnboardingScreen        # Three-page onboarding flow
β”‚   β”œβ”€β”€ LoginScreen             # Authentication UI with validation
β”‚   β”œβ”€β”€ HomeScreen              # Post-login dashboard
β”‚   β”œβ”€β”€ AuthUser                # User domain model
β”‚   β”œβ”€β”€ AuthService             # Authentication logic
β”‚   └── AuthException           # Custom exception class
β”‚
assets/
└── images/
    β”œβ”€β”€ splash.png
    β”œβ”€β”€ onboarding_1.png
    β”œβ”€β”€ onboarding_2.png
    └── onboarding_3.png

Note: This is a single-file implementation for educational purposes. Production apps should follow proper separation of concerns.


πŸ”Œ API Integration

DummyJSON Auth API

The app is designed to integrate with the DummyJSON Authentication API.

Endpoint

POST https://dummyjson.com/auth/login
Content-Type: application/json

Request Body

{
  "username": "emilys",
  "password": "emilyspass",
  "expiresInMins": 30
}

Success Response (200 OK)

{
  "id": 1,
  "username": "emilys",
  "email": "emily.johnson@x.dummyjson.com",
  "firstName": "Emily",
  "lastName": "Johnson",
  "gender": "female",
  "image": "https://dummyjson.com/icon/emilys/128",
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Error Response (400 Bad Request)

{
  "message": "Invalid credentials"
}

Dio Implementation Example

import 'package:dio/dio.dart';

class AuthService {
  static final Dio _dio = Dio(
    BaseOptions(
      baseUrl: 'https://dummyjson.com',
      connectTimeout: Duration(seconds: 5),
      receiveTimeout: Duration(seconds: 3),
      headers: {'Content-Type': 'application/json'},
    ),
  );

  static Future<AuthUser> login({
    required String username,
    required String password,
  }) async {
    try {
      final response = await _dio.post(
        '/auth/login',
        data: {
          'username': username,
          'password': password,
          'expiresInMins': 30,
        },
      );

      return AuthUser(
        id: response.data['id'],
        username: response.data['username'],
        email: response.data['email'],
        firstName: response.data['firstName'],
        lastName: response.data['lastName'],
        gender: response.data['gender'],
        image: response.data['image'],
        accessToken: response.data['accessToken'],
        refreshToken: response.data['refreshToken'],
      );
    } on DioException catch (e) {
      if (e.response?.statusCode == 400) {
        throw const AuthException('Invalid username or password');
      }
      throw AuthException('Network error: ${e.message}');
    } catch (e) {
      throw AuthException('Unexpected error: $e');
    }
  }
}

πŸ“ Notes

Current Limitations

  • ℹ️ Social Login: Facebook/Google buttons are UI-only (OAuth not implemented)
  • ℹ️ Password Recovery: "Forgot password" link is a placeholder
  • ℹ️ Registration: "Sign up" link is not functional
  • ℹ️ Persistence: "Remember me" checkbox doesn't persist data (no local storage)
  • ℹ️ Token Refresh: No automatic token refresh mechanism

Implementation

  • Splash screen with animations
  • Three-page onboarding flow
  • Login UI with validation
  • In-memory authentication service
  • Error handling and user feedback
  • Home screen with user data display

πŸ”— Resources

Documentation

Design Resources

Learning Resources


KaLbar - Built with Flutter πŸ’™

University Mobile Development Assignment β€’ 2024

About

Splash, onboarding and login screens with backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors