Skip to content

Latest commit

Β 

History

207 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌾 Smart Gebere - Intelligent Agriculture Assistant

Smart Gebere Logo

An AI-powered mobile application designed to revolutionize farming practices for Ethiopian farmers

Flutter Firebase Gemini AI License

Features β€’ Installation β€’ Architecture β€’ API Documentation β€’ Contributing


πŸ“‹ Table of Contents

  1. Overview
  2. Features
  3. Technology Stack
  4. Architecture
  5. Installation & Setup
  6. Configuration
  7. Project Structure
  8. Core Modules
  9. API Documentation
  10. Database Schema
  11. Localization
  12. Security
  13. Testing
  14. Deployment
  15. Troubleshooting
  16. Roadmap
  17. Contributing
  18. License

🌍 Overview

Smart Gebere (αˆ΅αˆ›αˆ­α‰΅ αŒˆα‰ αˆ¬ - "Smart Farmer" in Amharic) is a comprehensive agricultural assistant application built with Flutter. It leverages artificial intelligence, GPS technology, and real-time weather data to provide Ethiopian farmers with personalized crop recommendations, disease detection, yield predictions, and farm management tools.

Mission Statement

To empower Ethiopian farmers with cutting-edge technology, enabling data-driven decisions that increase crop yields, reduce losses, and promote sustainable farming practices.

Key Objectives

  • 🎯 Personalized Recommendations: AI-powered crop suggestions based on location, climate, and soil conditions
  • πŸ”¬ Disease Detection: Image-based plant disease diagnosis using computer vision
  • πŸ“… Smart Planning: Week-by-week farming guides tailored to specific crops and fields
  • πŸ“Š Yield Prediction: AI-powered harvest forecasting and market value estimation
  • πŸ—ΊοΈ Field Mapping: GPS-based land measurement and management
  • 🌐 Multi-language Support: Available in English, Amharic (αŠ αˆ›αˆ­αŠ›), and Afaan Oromo

✨ Features

🏠 Home Dashboard

The central hub of the application featuring:

Component Description
Weather Widget Real-time weather data for the farmer's location
Quick Actions One-tap access to key features
Created Tasks Slideshow of active crop plans with progress
Expected Events Upcoming farming tasks and deadlines
Navigation Drawer Access to all app features

🌱 AI Crop Recommendations

Location Data β†’ Weather API β†’ Elevation API β†’ Gemini AI β†’ Personalized Crop List

How it works:

  1. Fetches current GPS coordinates
  2. Retrieves elevation data from Open-Elevation API
  3. Gets real-time weather from OpenWeather API
  4. Optionally includes user's mapped field data (size, soil type)
  5. Sends comprehensive data to Gemini AI
  6. Returns ranked crop suggestions with suitability scores

Output includes:

  • Crop name and description
  • Suitability percentage (0-100%)
  • Climate suitability analysis
  • Soil requirements
  • Water needs assessment
  • Elevation factor analysis
  • Seasonal growth patterns

🩺 AI Crop Doctor

An intelligent chat assistant for farming questions and plant diagnosis.

Capabilities:

  • Real-time chat with Gemini AI
  • Photo-based plant disease diagnosis
  • Pest control advice (organic methods prioritized)
  • Irrigation and fertilization guidance
  • Crop-specific question answering
  • Multi-language responses

Technical Implementation:

// Image-based diagnosis
Content.multi([
  TextPart(prompt),
  DataPart('image/jpeg', imageBytes),
])

// Text-based chat
ChatSession.sendMessage(Content.text(userQuery))

πŸ”¬ Disease Detection

Advanced image analysis for plant disease identification.

Features:

  • Camera and gallery image input
  • Real-time disease detection
  • Confidence score display
  • Treatment recommendations
  • Detection history
  • Share results functionality

AI Prompt Structure:

Analyze this plant image and provide:
1. Plant identification
2. Disease/problem detection
3. Severity assessment
4. Treatment recommendations
5. Prevention tips

πŸ“… Crop Planning & Scheduling

Week-by-week farming guides generated by AI.

Data Structure:

{
  "week": 1,
  "date_range": ["2025-01-01", "2025-01-07"],
  "stage": "Land Preparation",
  "tasks": [
    "Test soil pH and adjust as necessary",
    "Plow the field to a depth of 15 cm",
    "Add organic compost"
  ],
  "completedTasks": [0, 2]
}

Stages Covered:

  1. πŸ—οΈ Land Preparation
  2. 🌱 Planting/Sowing
  3. πŸ“ˆ Growth & Maintenance
  4. 🌸 Flowering
  5. 🌾 Harvest

πŸ“Š Yield Prediction & Analytics

AI-powered harvest forecasting system.

Inputs:

  • Selected crop
  • Land size (hectares/acres/timad)
  • Seed amount
  • Fertilizer used
  • Field data (if mapped)

Outputs:

{
  "estimated_yield_min": 1500,
  "estimated_yield_max": 2500,
  "yield_per_hectare": 2000,
  "confidence_percentage": 85,
  "market_value_estimate_min": 45000,
  "market_value_estimate_max": 75000,
  "harvest_quality_prediction": "good",
  "optimal_harvest_timing": "When 90% of grains are golden",
  "factors_affecting_yield": [...],
  "recommendations": [...]
}

πŸ—ΊοΈ GPS Field Mapping

Precise land measurement using GPS coordinates.

Features:

  • Real-time GPS tracking
  • Walk-the-boundary mapping
  • Automatic area calculation (Shoelace formula)
  • Multiple soil type options
  • Save and manage multiple fields
  • Integration with crop recommendations

Area Calculation:

// Shoelace formula for polygon area
double _calculatePolygonArea(List<LatLng> points) {
  double area = 0;
  for (int i = 0; i < n; i++) {
    int j = (i + 1) % n;
    area += x1 * y2 - x2 * y1;
  }
  return (area.abs() / 2) / 10000; // hectares
}

Supported Soil Types:

  • Loam
  • Clay
  • Sandy
  • Silt
  • Vertisol (Black Cotton)
  • Nitosol (Red)
  • Andosol

πŸ“ˆ Market Prices

Real-time agricultural commodity prices.

Features:

  • Price trends visualization
  • Historical data charts
  • Regional price comparison
  • Price alerts (planned)

🌀️ Weather Advisor

Comprehensive weather information for farming decisions.

Data Provided:

  • Current temperature
  • Humidity levels
  • Weather conditions
  • 7-day forecast
  • Farming recommendations based on weather

πŸ“š Knowledge Base

Educational content for farmers.

Categories:

  • Crop guides
  • Pest management
  • Soil health
  • Water management
  • Post-harvest handling
  • Market information

πŸ“ Farm Records

Digital record-keeping for farm activities.

Record Types:

  • Planting records
  • Harvest records
  • Input purchases
  • Sales records
  • Expense tracking

πŸ‘€ Farmer Profile

User profile and farm information management.

Profile Data:

  • Personal information
  • Farm location
  • Land holdings
  • Crop history
  • Preferences

πŸ› οΈ Technology Stack

Frontend

Technology Purpose Version
Flutter Cross-platform UI framework 3.x
Dart Programming language 3.x
Provider State management 6.x
Google Fonts Typography 6.x
FL Chart Data visualization 0.69.x

Backend & Services

Service Purpose
Firebase Auth User authentication
Cloud Firestore NoSQL database
Google Gemini AI AI/ML capabilities
OpenWeather API Weather data
Open-Elevation API Elevation data

Core Packages

dependencies:
  # Firebase
  firebase_core: ^3.12.1
  firebase_auth: ^5.5.1
  cloud_firestore: ^5.6.5

  # AI & ML
  google_generative_ai: ^0.4.6

  # Location
  geolocator: ^13.0.2

  # Media
  image_picker: ^1.1.2

  # UI
  google_fonts: ^6.2.1
  fl_chart: ^0.69.2
  awesome_dialog: ^3.2.1

  # Storage
  shared_preferences: ^2.x
  hive: ^2.x
  hive_flutter: ^1.x

  # Utilities
  http: ^1.3.0
  intl: ^0.19.0
  flutter_dotenv: ^5.2.1
  provider: ^6.1.2
  uuid: ^4.5.1

πŸ—οΈ Architecture

Application Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      PRESENTATION LAYER                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚  Pages  β”‚ β”‚ Widgets β”‚ β”‚ Dialogs β”‚ β”‚  Cards  β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚           β”‚           β”‚           β”‚
        β–Ό           β–Ό           β–Ό           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       BUSINESS LAYER                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚  Services  β”‚ β”‚  Providers β”‚ β”‚   Models   β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚              β”‚              β”‚
         β–Ό              β–Ό              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        DATA LAYER                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Firebase  β”‚ β”‚ Gemini AI β”‚ β”‚  Weather  β”‚ β”‚   Local   β”‚   β”‚
β”‚  β”‚ Firestore β”‚ β”‚    API    β”‚ β”‚    API    β”‚ β”‚  Storage  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

User Action
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Widget    β”‚ ◄─── State Management (Provider/setState)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Service   β”‚ ◄─── Business Logic
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  External   β”‚ ◄─── Firebase / APIs / AI
β”‚   Service   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
   Response
       β”‚
       β–Ό
   UI Update

State Management

The app uses a combination of:

  1. Provider - For app-wide state (settings, user info)
  2. StatefulWidget - For local component state
  3. FutureBuilder/StreamBuilder - For async data
// Global state example
class AppSettings extends ChangeNotifier {
  Locale _locale = const Locale('en');
  
  Locale get locale => _locale;
  
  Future<void> setLocale(Locale newLocale) async {
    _locale = newLocale;
    await _persistLocale(newLocale);
    notifyListeners();
  }
}

πŸš€ Installation & Setup

Prerequisites

  • Flutter SDK 3.x or higher
  • Dart SDK 3.x or higher
  • Android Studio / VS Code
  • Firebase CLI
  • Git

Step 1: Clone Repository

git clone https://github.com/your-org/smart-gebere.git
cd smart-gebere/Smart_Gebere

Step 2: Install Dependencies

flutter pub get

Step 3: Firebase Setup

  1. Create a Firebase project at Firebase Console
  2. Enable Authentication (Email/Password)
  3. Enable Cloud Firestore
  4. Download configuration files:
    • google-services.json β†’ android/app/
    • GoogleService-Info.plist β†’ ios/Runner/

Step 4: Environment Configuration

Create .env file in project root:

# API Keys
API_KEY=your_gemini_api_key
GEMINI_API_KEY=your_gemini_api_key
OPENWEATHER_API_KEY=your_openweather_api_key

# Model Configuration
GEMINI_MODEL=gemini-1.5-flash

Step 5: Run Application

# Development
flutter run

# Web
flutter run -d chrome

# Android
flutter run -d android

# iOS
flutter run -d ios

# Build APK
flutter build apk --release

# Build iOS
flutter build ios --release

βš™οΈ Configuration

Environment Variables

Variable Description Required
API_KEY Gemini AI API key βœ…
GEMINI_API_KEY Alternative Gemini key βœ…
OPENWEATHER_API_KEY Weather API key βœ…
GEMINI_MODEL AI model name ❌ (default: gemini-1.5-flash)

Firebase Configuration

Firestore Security Rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Users collection
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    
    // Farmers collection
    match /Farmers/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    
    // Public content
    match /content/{document=**} {
      allow read: if request.auth != null;
      allow write: if false;
    }
  }
}

πŸ“ Project Structure

Smart_Gebere/
β”œβ”€β”€ android/                    # Android-specific code
β”œβ”€β”€ ios/                        # iOS-specific code
β”œβ”€β”€ web/                        # Web-specific code
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ main.dart              # Application entry point
β”‚   β”‚
β”‚   β”œβ”€β”€ auth/                  # Authentication
β”‚   β”‚   β”œβ”€β”€ login/
β”‚   β”‚   β”‚   └── login.dart     # Login page
β”‚   β”‚   └── signup/
β”‚   β”‚       └── sign_up.dart   # Registration page
β”‚   β”‚
β”‚   β”œβ”€β”€ Home/                  # Home module
β”‚   β”‚   β”œβ”€β”€ Home.dart          # Main dashboard
β”‚   β”‚   β”œβ”€β”€ task_creation.dart # Task creation cards
β”‚   β”‚   β”œβ”€β”€ created_task.dart  # Active crops display
β”‚   β”‚   β”œβ”€β”€ expected_event.dart # Upcoming tasks
β”‚   β”‚   β”œβ”€β”€ cropdetailpage.dart # Crop details
β”‚   β”‚   └── weeklydetailpage.dart # Weekly details
β”‚   β”‚
β”‚   β”œβ”€β”€ Disease_page/          # Disease detection
β”‚   β”‚   └── DiseaseDetection.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ geo_Location/          # Location services
β”‚   β”‚   └── location.dart      # GPS & weather
β”‚   β”‚
β”‚   β”œβ”€β”€ scheduling/            # Crop planning
β”‚   β”‚   └── schedule.dart      # Week-by-week planner
β”‚   β”‚
β”‚   β”œβ”€β”€ task_management/       # Task management
β”‚   β”‚   β”œβ”€β”€ descrition.dart    # Agriculture intro page
β”‚   β”‚   └── list_suggestion.dart # Crop suggestions
β”‚   β”‚
β”‚   β”œβ”€β”€ features/              # Feature modules
β”‚   β”‚   β”œβ”€β”€ ai_doctor/
β”‚   β”‚   β”‚   └── ai_crop_doctor_page.dart
β”‚   β”‚   β”œβ”€β”€ yield_prediction/
β”‚   β”‚   β”‚   └── yield_prediction_page.dart
β”‚   β”‚   β”œβ”€β”€ field_mapping/
β”‚   β”‚   β”‚   └── field_mapping_page.dart
β”‚   β”‚   β”œβ”€β”€ market_prices/
β”‚   β”‚   β”‚   └── market_prices_page.dart
β”‚   β”‚   β”œβ”€β”€ weather_advisor/
β”‚   β”‚   β”‚   └── weather_advisor_page.dart
β”‚   β”‚   β”œβ”€β”€ farm_records/
β”‚   β”‚   β”‚   └── farm_records_page.dart
β”‚   β”‚   β”œβ”€β”€ farm_profile/
β”‚   β”‚   β”‚   └── farm_profile_page.dart
β”‚   β”‚   β”œβ”€β”€ knowledge_base/
β”‚   β”‚   β”‚   └── knowledge_base_page.dart
β”‚   β”‚   └── privacy/
β”‚   β”‚       └── privacy_page.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ core/                  # Core services
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ connectivity_service.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ connectivity_io.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ connectivity_web.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ connectivity_stub.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ offline_storage.dart
β”‚   β”‚   β”‚   β”œβ”€β”€ ai_reliability.dart
β”‚   β”‚   β”‚   └── content_service.dart
β”‚   β”‚   └── models/
β”‚   β”‚       β”œβ”€β”€ farm_profile.dart
β”‚   β”‚       β”œβ”€β”€ farm_record.dart
β”‚   β”‚       β”œβ”€β”€ market_price.dart
β”‚   β”‚       β”œβ”€β”€ knowledge_article.dart
β”‚   β”‚       └── detection_history.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ settings/              # App settings
β”‚   β”‚   β”œβ”€β”€ app_settings.dart
β”‚   β”‚   β”œβ”€β”€ settings_page.dart
β”‚   β”‚   β”œβ”€β”€ locale_store.dart
β”‚   β”‚   β”œβ”€β”€ locale_store_io.dart
β”‚   β”‚   β”œβ”€β”€ locale_store_web.dart
β”‚   β”‚   └── locale_store_stub.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ l10n/                  # Localization
β”‚   β”‚   β”œβ”€β”€ app_localizations.dart
β”‚   β”‚   β”œβ”€β”€ fallback_localizations.dart
β”‚   β”‚   β”œβ”€β”€ app_en.arb
β”‚   β”‚   β”œβ”€β”€ app_am.arb
β”‚   β”‚   └── app_om.arb
β”‚   β”‚
β”‚   β”œβ”€β”€ stream/                # Auth state
β”‚   β”‚   └── stream_provider.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ splash/                # Splash screen
β”‚   β”‚   └── splash_screen.dart
β”‚   β”‚
β”‚   β”œβ”€β”€ onboarding/            # Onboarding
β”‚   β”‚   └── onboarding_page.dart
β”‚   β”‚
β”‚   └── Loading/               # Loading states
β”‚       └── loading.dart
β”‚
β”œβ”€β”€ assets/                    # Static assets
β”‚   β”œβ”€β”€ image_1.jpg
β”‚   └── ...
β”‚
β”œβ”€β”€ .env                       # Environment variables
β”œβ”€β”€ pubspec.yaml              # Dependencies
β”œβ”€β”€ firestore.rules           # Firestore rules
β”œβ”€β”€ firebase.json             # Firebase config
└── README.md                 # This file

🧩 Core Modules

1. Authentication Module

Location: lib/auth/

Handles user authentication using Firebase Auth.

// Login
await FirebaseAuth.instance.signInWithEmailAndPassword(
  email: email,
  password: password,
);

// Signup
await FirebaseAuth.instance.createUserWithEmailAndPassword(
  email: email,
  password: password,
);

// Logout
await FirebaseAuth.instance.signOut();

Features:

  • Email/password authentication
  • Password visibility toggle
  • Form validation
  • Error handling with user-friendly messages
  • Animated transitions

2. Location Service

Location: lib/geo_Location/location.dart

Provides GPS coordinates, elevation, and weather data.

class LocationService {
  // Get current location with all data
  Future<Map<String, dynamic>> getCurrentLocation();
  
  // Get elevation for coordinates
  Future<double> getElevation(double lat, double lon);
  
  // Get weather data
  Future<Map<String, dynamic>> getWeather(double lat, double lon);
  
  // Generate AI crop suggestions
  Future<List<Map<String, dynamic>>> generateCropSuggestions(
    Map<String, dynamic> locationData, {
    Map<String, dynamic>? fieldData,
  });
}

3. AI Integration

Multiple AI-powered features using Gemini:

// Initialize model
final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
  safetySettings: [...],
  systemInstruction: Content.text('...'),
);

// Text generation
final response = await model.generateContent([Content.text(prompt)]);

// Image analysis
final response = await model.generateContent([
  Content.multi([
    TextPart(prompt),
    DataPart('image/jpeg', imageBytes),
  ])
]);

// Chat session
final chatSession = model.startChat();
final response = await chatSession.sendMessage(Content.text(message));

4. Offline Storage

Location: lib/core/services/offline_storage.dart

Local data persistence using Hive.

class OfflineStorage {
  Future<void> init();
  Future<void> saveCrops(List<Map<String, dynamic>> crops);
  Future<List<Map<String, dynamic>>> getCrops();
  Future<void> savePendingSync(Map<String, dynamic> data);
  Future<List<Map<String, dynamic>>> getPendingSync();
}

5. Connectivity Service

Location: lib/core/services/connectivity_service.dart

Cross-platform network status monitoring.

abstract class ConnectivityService {
  Stream<bool> get onConnectivityChanged;
  Future<bool> isConnected();
}

// Platform-specific implementations
// - connectivity_io.dart (Mobile/Desktop)
// - connectivity_web.dart (Web)

πŸ“‘ API Documentation

External APIs

1. Gemini AI API

Endpoint: https://generativelanguage.googleapis.com/v1beta/

Authentication: API Key

Models Used:

  • gemini-1.5-flash (primary)
  • gemini-2.5-flash (preferred, with fallback)

Usage Examples:

// Crop recommendations
String prompt = """
Based on the following location data, provide crop recommendations:
- Latitude: ${lat}
- Longitude: ${lon}
- Elevation: ${elevation}m
- Temperature: ${temp}Β°C
...
""";

// Disease detection
String prompt = """
Analyze this plant image and provide:
1. Plant identification
2. Disease detection
3. Treatment recommendations
...
""";

2. OpenWeather API

Endpoint: https://api.openweathermap.org/data/2.5/weather

Parameters:

  • lat - Latitude
  • lon - Longitude
  • appid - API key
  • units - metric

Response:

{
  "main": {
    "temp": 25.5,
    "humidity": 65
  },
  "weather": [{
    "description": "scattered clouds"
  }]
}

3. Open-Elevation API

Endpoint: https://api.open-elevation.com/api/v1/lookup

Request:

{
  "locations": [
    {"latitude": 9.0, "longitude": 38.75}
  ]
}

Response:

{
  "results": [{
    "elevation": 2355
  }]
}

πŸ—„οΈ Database Schema

Firestore Collections

Farmers/{userId}

interface Farmer {
  // Profile
  name?: string;
  phone?: string;
  region?: string;
  
  // Fields (mapped GPS fields)
  fields?: Field[];
  
  // Crops (active crop plans)
  crops?: Crop[];
}

interface Field {
  id: string;
  name: string;
  soilType: string;
  areaHectares: number;
  points: {lat: number, lng: number}[];
  createdAt: string;
}

interface Crop {
  id: string;
  name: string;
  weeks: Week[];
  progressPercentage: number;
  daysSinceFirstPlanting: number;
  createdAt: string;
  fieldId?: string;
  fieldName?: string;
  fieldAreaHectares?: number;
  soilType?: string;
}

interface Week {
  week: number;
  date_range: [string, string];
  stage: string;
  tasks: string[];
  completedTasks?: number[];
}

users/{userId}

interface User {
  email: string;
  createdAt: Timestamp;
  lastLogin: Timestamp;
  settings?: UserSettings;
}

interface UserSettings {
  language: string;
  notifications: boolean;
}

🌐 Localization

Supported Languages

Language Code Status
English en βœ… Complete
Amharic (αŠ αˆ›αˆ­αŠ›) am βœ… Complete
Afaan Oromo om βœ… Complete

Implementation

Location: lib/l10n/

Usage:

final l10n = AppLocalizations.of(context);
Text(l10n.welcomeMessage);
Text(l10n.createTask);

Adding New Strings:

  1. Add to app_en.arb:
{
  "newString": "English text"
}
  1. Add to app_am.arb:
{
  "newString": "α‹¨αŠ αˆ›αˆ­αŠ› αŒ½αˆ‘α"
}
  1. Add to app_om.arb:
{
  "newString": "Afaan Oromo text"
}
  1. Add to AppLocalizations class:
String get newString => _localizedValues[locale.languageCode]?['newString'] ?? 'Default';

Changing Language

// In SettingsPage
await settings.setLocale(Locale('am')); // Switch to Amharic

πŸ”’ Security

Authentication

  • Firebase Authentication with email/password
  • Secure token management
  • Session persistence

Data Protection

  • Firestore security rules enforce user-level access
  • No cross-user data access
  • API keys stored in .env (not committed)

Best Practices

  1. API Keys: Never commit .env files
  2. User Data: Encrypt sensitive local storage
  3. Network: All API calls over HTTPS
  4. Validation: Server-side validation in Firestore rules

Security Rules

// Only authenticated users can access their own data
match /Farmers/{userId} {
  allow read, write: if request.auth != null 
                     && request.auth.uid == userId;
}

πŸ§ͺ Testing

Unit Tests

flutter test

Integration Tests

flutter test integration_test/

Widget Tests

testWidgets('Login button works', (tester) async {
  await tester.pumpWidget(MyApp());
  await tester.tap(find.text('Login'));
  await tester.pump();
  expect(find.text('Welcome'), findsOneWidget);
});

πŸ“¦ Deployment

Android

# Generate release APK
flutter build apk --release

# Generate App Bundle
flutter build appbundle --release

Output: build/app/outputs/flutter-apk/app-release.apk

iOS

flutter build ios --release

Then archive and upload via Xcode.

Web

flutter build web --release

Output: build/web/

Deploy to Firebase Hosting:

firebase deploy --only hosting

πŸ”§ Troubleshooting

Common Issues

1. AssetManifest.json Error (Web)

Error: Unable to load asset: "AssetManifest.json"

Solution:

flutter clean
flutter pub get
flutter run -d chrome

2. Firestore Permission Denied

Error: PERMISSION_DENIED

Solution:

  1. Deploy Firestore rules: firebase deploy --only firestore:rules
  2. Verify user is authenticated
  3. Check collection path matches rules

3. Gemini API Model Not Found

Error: model is not found

Solution:

  • Update GEMINI_MODEL in .env to gemini-1.5-flash
  • The app has automatic fallback to this model

4. Location Permission Denied

Solution:

  • Android: Check AndroidManifest.xml permissions
  • iOS: Check Info.plist usage descriptions
  • Request permission in app before accessing location

5. MissingPluginException on Web

MissingPluginException: No implementation found

Solution:

  • For shared_preferences: App uses cross-platform LocaleStore
  • For connectivity_plus: App uses platform-specific implementations
  • Ensure flutter pub get and full restart

πŸ—ΊοΈ Roadmap

Phase 1: Core Features βœ…

  • User authentication
  • GPS-based crop recommendations
  • Disease detection
  • Crop planning/scheduling
  • Multi-language support

Phase 2: Advanced Features βœ…

  • AI Crop Doctor chat
  • Yield prediction
  • GPS field mapping
  • Task completion tracking
  • Progress calculation

Phase 3: Enhancement (In Progress)

  • Push notifications
  • Offline-first mode
  • Voice input for chat
  • Community forums
  • Expert consultation

Phase 4: Future

  • IoT sensor integration
  • Drone imagery support
  • Marketplace integration
  • Government scheme information
  • Insurance integration

🀝 Contributing

Getting Started

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

Code Style

  • Follow Dart style guide
  • Use meaningful variable names
  • Add comments for complex logic
  • Write tests for new features

Commit Messages

feat: add yield prediction feature
fix: resolve login error on iOS
docs: update API documentation
style: format code with dartfmt
refactor: simplify location service
test: add unit tests for auth

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Team

Smart Gebere Development Team

  • Project Lead
  • Flutter Developers
  • UI/UX Designers
  • AI/ML Engineers
  • QA Engineers

πŸ“ž Support

For support, please:

  1. Check the Troubleshooting section
  2. Search existing Issues
  3. Create a new issue with:
    • Device/platform information
    • Steps to reproduce
    • Expected vs actual behavior
    • Screenshots if applicable

πŸ™ Acknowledgments


Made with ❀️ for Ethiopian Farmers

🌾 Smart Gebere - αˆ΅αˆ›αˆ­α‰΅ αŒˆα‰ αˆ¬ 🌾

Documentation

Developer docs live in docs/:

About

🌱 Smart Gebere is a Flutter-based AI app that helps farmers diagnose and manage crop diseases. Using machine learning, it analyzes plant images to detect diseases and provides tailored treatment recommendations.

Topics

Resources

Contributing

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages