Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Dec 20, 2024
1 parent c6925be commit 82ff2da
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 3 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ class _AppContainer extends StatelessWidget {
),
ChangeNotifierProvider(
create: (_) => DownloadConfigurationProvider(),
lazy: true,
),
ChangeNotifierProvider(
create: (_) => DownloadingProvider(),
// cannot be lazy as must persist when user disposed
lazy: true,
),
ChangeNotifierProvider(
create: (_) => RecoverableRegionsProvider(),
lazy: true,
),
],
child: MaterialApp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:latlong2/latlong.dart';
import 'package:provider/provider.dart';

import '../../../../../shared/state/general_provider.dart';
import '../../../../../shared/state/region_selection_provider.dart';

class RegionShape extends StatelessWidget {
Expand All @@ -13,7 +14,13 @@ class RegionShape extends StatelessWidget {
Widget build(BuildContext context) => Consumer<RegionSelectionProvider>(
builder: (context, provider, _) {
final ccc = provider.currentConstructingCoordinates;
final cnpp = provider.currentNewPointPos;
final cnpp = provider.currentNewPointPos ??
context
.watch<GeneralProvider>()
.animatedMapController
.mapController
.camera
.center;

late final renderConstructingRegion = provider.currentRegionType ==
RegionType.line
Expand Down
5 changes: 3 additions & 2 deletions example/lib/src/screens/main/map_view/map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class _MapViewState extends State<MapView> with TickerProviderStateMixin {

final provider = context.read<RegionSelectionProvider>();

final newPoint = provider.currentNewPointPos;
final newPoint = provider.currentNewPointPos ??
_mapController.mapController.camera.center;

switch (provider.currentRegionType) {
case RegionType.rectangle:
Expand Down Expand Up @@ -196,7 +197,7 @@ class _MapViewState extends State<MapView> with TickerProviderStateMixin {
.latLngToScreenPoint(coords.first)
.toOffset();
final centerPos = _mapController.mapController.camera
.latLngToScreenPoint(provider.currentNewPointPos)
.latLngToScreenPoint(provider.currentNewPointPos!)
.toOffset();
provider.customPolygonSnap = coords.first != coords.last &&
sqrt(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/src/shared/state/region_selection_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class RegionSelectionProvider extends ChangeNotifier {
notifyListeners();
}

LatLng _currentNewPointPos = const LatLng(51.509364, -0.128928);
LatLng get currentNewPointPos => _currentNewPointPos;
set currentNewPointPos(LatLng newPos) {
LatLng? _currentNewPointPos;
LatLng? get currentNewPointPos => _currentNewPointPos;
set currentNewPointPos(LatLng? newPos) {
_currentNewPointPos = newPos;
notifyListeners();
}
Expand Down
14 changes: 10 additions & 4 deletions lib/src/store/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,23 @@ class StoreDownload {
///
/// Does nothing (returns immediately) if there is no ongoing download or the
/// download is already paused.
Future<void> pause({Object instanceId = 0}) async =>
await DownloadInstance.get(instanceId)?.requestPause?.call();
Future<void> pause({Object instanceId = 0}) async {
final instance = DownloadInstance.get(instanceId);
if (instance == null || instance.isPaused) return;
await instance.requestPause!.call();
}

/// Resume (after a [pause]) the ongoing foreground download
///
/// {@macro num_instances}
///
/// Does nothing if there is no ongoing download or the download is already
/// running.
void resume({Object instanceId = 0}) =>
DownloadInstance.get(instanceId)?.requestResume?.call();
void resume({Object instanceId = 0}) {
final instance = DownloadInstance.get(instanceId);
if (instance == null || !instance.isPaused) return;
instance.requestResume!.call();
}

/// Whether the ongoing foreground download is currently paused after a call
/// to [pause] (and prior to [resume])
Expand Down

0 comments on commit 82ff2da

Please sign in to comment.