Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
fix(EditBar): Update marker frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
moverval committed Jan 4, 2024
1 parent 0d26618 commit d506526
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
13 changes: 7 additions & 6 deletions lib/components/MapWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ class MapWidget extends StatefulWidget {
/// A function that is called when a marker is tapped
final Function(Bar)? onMarkerTap;

/// Map Start position
final LatLng? pos;

const MapWidget(
{super.key, required this.bars, this.onTap, this.onMarkerTap});
{super.key, required this.bars, this.onTap, this.onMarkerTap, this.pos});

@override
State<MapWidget> createState() => MapWidgetState();
Expand Down Expand Up @@ -67,13 +70,11 @@ class MapWidgetState extends State<MapWidget> {
} else {
if (selectedBar == bar) return;
// Hide the tooltip if it is visible above another marker
tooltipKey.currentState
?.deactivate();
tooltipKey.currentState?.deactivate();
// Set the selected bar to the tapped bar
selectedBar = bar;
// Show the tooltip above the tapped marker
tooltipKey.currentState
?.ensureTooltipVisible();
tooltipKey.currentState?.ensureTooltipVisible();
// Give haptic feedback
HapticFeedback.lightImpact();
}
Expand All @@ -95,7 +96,7 @@ class MapWidgetState extends State<MapWidget> {
future: MapCenter.get(),
builder: (context, snapshot) {
if (snapshot.hasData) {
var mapCenter = snapshot.data!;
var mapCenter = widget.pos ?? snapshot.data!;
return FutureBuilder<CacheStore>(
future: _cacheStoreFuture,
builder: (context, snapshot) {
Expand Down
25 changes: 16 additions & 9 deletions lib/pages/AddBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class _AddBarOverlayContentState extends State<AddBarOverlayContent> {
),
Expanded(
child: MapWidget(
pos: bars.firstOrNull?.location,
key: mapKey,
bars: bars,
onTap: (LatLng loc) {
Expand Down Expand Up @@ -300,20 +301,26 @@ class _AddBarOverlayContentState extends State<AddBarOverlayContent> {
bool testAddress =
formKeyAddress.currentState!.validate();

Bar bar = widget.initialBar ??
Bar(
id: Bar.generateUuid(),
name: barNameController.text,
location: bars.first.location,
address: barAddressController.text,
);

await reverseGeocodeLatLng(
bars.first.location.latitude,
bars.first.location.longitude,
);

bar.address = barAddressController.text;
// If all fields are valid, insert the bar into the database
if (testLokal && testAddress) {
if (editing) {
Bar bar = widget.initialBar!;
bar.name = barNameController.text;
bar.address = barAddressController.text;
await Bar.update(bar);
} else {
await Bar.insert(Bar(
id: Bar.generateUuid(),
name: barNameController.text,
location: bars.first.location,
address:
barAddressController.text));
await Bar.insert(bar);
}
Provider.of<BarChanged>(context,
listen: false)
Expand Down

0 comments on commit d506526

Please sign in to comment.