ho lee shet

This commit is contained in:
stopflock
2025-08-22 21:04:30 -05:00
parent 1f3849cd84
commit 63ebc2b682
6 changed files with 119 additions and 4 deletions
+32 -1
View File
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:provider/provider.dart';
import 'dart:math' as math;
import '../app_state.dart';
import '../dev_config.dart';
import '../services/offline_area_service.dart';
import '../services/offline_areas/offline_tile_utils.dart';
@@ -85,8 +87,10 @@ class _DownloadAreaDialogState extends State<DownloadAreaDialog> {
@override
Widget build(BuildContext context) {
final appState = context.watch<AppState>();
final bounds = widget.controller.camera.visibleBounds;
final maxZoom = _zoom.toInt();
final isOfflineMode = appState.offlineMode;
// Use the calculated max possible zoom instead of fixed span
final sliderMin = _minZoom?.toDouble() ?? 12.0;
@@ -190,6 +194,33 @@ class _DownloadAreaDialogState extends State<DownloadAreaDialog> {
),
),
),
if (isOfflineMode)
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.orange.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.orange.withOpacity(0.3)),
),
child: Row(
children: [
Icon(Icons.wifi_off, color: Colors.orange[700], size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
'Downloads disabled while in offline mode. Disable offline mode to download new areas.',
style: TextStyle(
fontSize: 12,
color: Colors.orange[700],
),
),
),
],
),
),
),
],
),
),
@@ -199,7 +230,7 @@ class _DownloadAreaDialogState extends State<DownloadAreaDialog> {
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () async {
onPressed: isOfflineMode ? null : () async {
try {
final id = DateTime.now().toIso8601String().replaceAll(':', '-');
final appDocDir = await OfflineAreaService().getOfflineAreaDir();
+15 -2
View File
@@ -5,16 +5,25 @@ import 'package:flutter/services.dart';
import '../services/map_data_provider.dart';
import '../app_state.dart';
/// Singleton in-memory tile cache and async provider for custom tiles.
/// In-memory tile cache and async provider for custom tiles.
class TileProviderWithCache extends TileProvider with ChangeNotifier {
static final Map<String, Uint8List> _tileCache = {};
static Map<String, Uint8List> get tileCache => _tileCache;
bool _disposed = false;
TileProviderWithCache();
@override
void dispose() {
_disposed = true;
super.dispose();
}
@override
ImageProvider getImage(TileCoordinates coords, TileLayer options, {MapSource source = MapSource.auto}) {
final key = '${coords.z}/${coords.x}/${coords.y}';
if (_tileCache.containsKey(key)) {
final bytes = _tileCache[key]!;
return MemoryImage(bytes);
@@ -33,6 +42,7 @@ class TileProviderWithCache extends TileProvider with ChangeNotifier {
void _fetchAndCacheTile(TileCoordinates coords, String key, {MapSource source = MapSource.auto}) async {
// Don't fire multiple fetches for the same tile simultaneously
if (_tileCache.containsKey(key)) return;
try {
final bytes = await MapDataProvider().getTile(
z: coords.z, x: coords.x, y: coords.y, source: source,
@@ -40,7 +50,10 @@ class TileProviderWithCache extends TileProvider with ChangeNotifier {
if (bytes.isNotEmpty) {
_tileCache[key] = Uint8List.fromList(bytes);
print('[TileProviderWithCache] Cached tile $key, bytes=${bytes.length}');
notifyListeners(); // This updates any listening widgets
// Only notify listeners if not disposed
if (!_disposed) {
notifyListeners(); // This updates any listening widgets
}
}
// If bytes were empty, don't cache (will re-attempt next time)
} catch (e) {