Skip to content

🐛 Fix offline map download issues and add UX improvements#5

Merged
MasuRii merged 4 commits intomainfrom
feature/modular-offline-maps
Dec 15, 2025
Merged

🐛 Fix offline map download issues and add UX improvements#5
MasuRii merged 4 commits intomainfrom
feature/modular-offline-maps

Conversation

@MasuRii
Copy link
Copy Markdown
Member

@MasuRii MasuRii commented Dec 15, 2025

📝 Summary

This PR fixes 4 critical offline map issues plus a regression bug, significantly improving the download experience with proper state management and new user-friendly features.

✨ Changes

  • 🗄️ Fixed HiveError: Added Hive initialization and adapter registration in main.dart
  • ⏹️ Fixed Stop Button: Download cancellation now properly resets region status
  • 📊 Added Percentage Display: Progress bar now shows "45%" alongside the visual indicator
  • 🗑️ Added Clear All Feature: New "Clear All Data" option in AppBar menu with confirmation dialog
  • 🔄 Fixed Download Restart Bug: Downloads now work after stopping without requiring app restart

📁 Files Changed

File Change Type Impact
lib/main.dart 🔧 Modified Hive initialization + adapter registration
lib/src/services/offline/offline_map_service.dart 🔧 Modified Cancellation flag + status reset logic
lib/src/presentation/screens/region_download_screen.dart 🔧 Modified Percentage display + Clear All menu
lib/src/models/map_region.dart 🔧 Modified Model updates
lib/src/repositories/region_repository.dart 🔧 Modified Repository updates
lib/src/core/di/injection.config.dart 🔧 Modified DI configuration
test/*.dart (5 files) 🧪 Modified Test updates

🧪 Testing Instructions

  1. Run flutter test - all 258 tests should pass
  2. Download an offline map region (e.g., Visayas)
  3. Stop the download mid-way
  4. Try to download again - should work without app restart
  5. Check that percentage shows alongside progress bar
  6. Use "Clear All Data" from menu to delete all offline maps

🔧 Technical Details

  • Root Cause of Stop Bug: _cancelRequested flag was not reset at the start of downloadRegion() and downloadIslandGroup()
  • Fix Applied: Reset _cancelRequested = false at the very start of both methods, before any early returns

📋 Checklist

  • All 258 tests pass locally
  • Code formatted with dart format
  • No analyzer warnings (dart analyze)
  • No sensitive data exposed

This commit finalizes the implementation of three major initiatives:

- **Routing Engine**: Implemented OSRM integration with configurable backend and Haversine fallback for offline calculation.
- **Offline Maps**: Integrated FMTC backend, added region download capabilities, created MapPickerScreen, and added `regions.json` asset.
- **Codebase Cleanup**: Refactored `MainScreen` from 1600+ lines to a modular architecture (~289 lines), improving maintainability and testability.

All 216 tests are passing.
This commit addresses multiple critical issues reported by the user:

- **Offline Maps Persistence**: Implemented Hive-based storage for offline map regions. The app now correctly remembers downloaded maps after a restart.
- **Restricted Regions**: Updated the available offline map regions to strictly "Luzon", "Visayas", and "Mindanao".
- **Geographic Accuracy**: Scientifically verified and updated the bounding box coordinates for these regions to ensure full coverage of outlying islands (e.g., Palawan, Batanes, Tawi-Tawi).
- **Connectivity Detection**: Replaced the single `google.com` check with a robust multi-endpoint check (1.1.1.1, microsoft.com, github.com) to fix false "offline" status in regions where Google is blocked.
- **Crash Prevention**: Fixed a startup crash caused by unhandled exceptions during FMTC backend initialization. Added defensive try-catch blocks to ensure the app launches gracefully even if offline maps fail to load.
This commit introduces a hierarchical offline map system allowing users
to download individual Philippine islands instead of entire regions.

Key changes:

Data Layer:
- Added 28 individual islands with accurate bounding boxes across
  Luzon (10), Visayas (11), and Mindanao (7) island groups
- Created hierarchical JSON schema with parent-child relationships
- Updated regions.json with 31 total regions (3 groups + 28 islands)

Model Layer:
- Added RegionType enum (islandGroup, island) with Hive persistence
- Extended MapRegion with type, parentId, priority fields
- Added fromJson/toJson serialization methods

Repository Layer:
- Created RegionRepository for dynamic JSON-based region loading
- Implemented hierarchical queries (getIslandGroups, getIslandsForGroup)
- Added caching to avoid repeated JSON parsing

Service Layer:
- Updated OfflineMapService to load regions dynamically
- Added downloadIslandGroup() for batch island downloads
- Implemented aggregated progress tracking for group downloads

Presentation Layer:
- Redesigned RegionDownloadScreen with expandable island groups
- Added "Download All" button per group
- Individual island toggles with size estimates

Documentation:
- Added architecture documentation
- Added island boundaries research data

All 258 tests passing.
📝 Summary:
Resolved 4 critical offline map issues plus a regression bug, improving
the download experience with proper state management and new features.

🔧 Changes:
- 🗄️ Fixed HiveError by adding Hive initialization and adapter registration
- ⏹️ Fixed download stop button not resetting status properly
- 📊 Added percentage display (e.g., "45%") next to progress bar
- 🗑️ Added "Clear All Data" feature in AppBar menu
- 🔄 Fixed regression: download now works after stop without app restart

🧪 All 258 tests passing.
@MasuRii MasuRii merged commit ae63113 into main Dec 15, 2025
9 checks passed
@MasuRii MasuRii deleted the feature/modular-offline-maps branch March 16, 2026 01:21
MasuRii added a commit that referenced this pull request Mar 16, 2026
…ine-maps

Fix offline map download issues and add UX improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant