FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
98 stars 17 forks source link

Unable to build custom Google Map Widgets even when the code contains no bugs #2868

Closed koushikraj96 closed 1 week ago

koushikraj96 commented 1 week ago

Has your issue been reported?

Current Behavior

Facing the following error during build:

Unknown error compiling custom code. A common cause is a custom widget or action whose name in the code does not match the name provided in the editor.

Expected Behavior

A successful build since the code does not contain IDE errors

Steps to Reproduce

Build the following custom widget

// Automatic FlutterFlow imports import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/widgets/index.dart'; // Imports other custom widgets import '/custom_code/actions/index.dart'; // Imports custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom widget code // DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:google_maps_flutter/google_maps_flutter.dart' as gmaps;

class GoogleMapLocationPicker extends StatefulWidget { const GoogleMapLocationPicker({ super.key, this.width, this.height, this.initialCamera, this.initialMarker, this.initialZoom, });

final double? width; final double? height; final gmaps.LatLng? initialCamera; final gmaps.LatLng? initialMarker; final int? initialZoom;

@override State createState() => _GoogleMapLocationPickerState(); }

class _GoogleMapLocationPickerState extends State { gmaps.GoogleMapController? _mapController; gmaps.LatLng? _lastMapPosition;

void _onMapCreated(gmaps.GoogleMapController controller) { _mapController = controller; _updateMapPosition( (widget.initialCamera ?? gmaps.LatLng(0.0, 0.0)) as LatLng); }

void _onCameraMove(gmaps.CameraPosition position) { _lastMapPosition = position.target; }

void _onCameraIdle() { if (_lastMapPosition != null) { FFAppState().update(() { FFAppState().selectedLocationGlobalState = _lastMapPosition as LatLng; }); } }

void _updateMapPosition(LatLng position) { _mapController ?.moveCamera(gmaps.CameraUpdate.newLatLng(position as gmaps.LatLng)); FFAppState().selectedLocationGlobalState = position; }

@override Widget build(BuildContext context) { return SizedBox( width: widget.width ?? MediaQuery.of(context).size.width, height: widget.height ?? MediaQuery.of(context).size.height, child: gmaps.GoogleMap( onMapCreated: _onMapCreated, initialCameraPosition: gmaps.CameraPosition( target: widget.initialCamera ?? gmaps.LatLng(0.0, 0.0), zoom: widget.initialZoom?.toDouble() ?? 14.0, ), markers: { if (widget.initialMarker != null) gmaps.Marker( markerId: gmaps.MarkerId('initialMarker'), position: widget.initialMarker!, ), }, onCameraMove: _onCameraMove, onCameraIdle: _onCameraIdle, mapType: gmaps.MapType.normal, ), ); } }

Reproducible from Blank

Bug Report Code (Required)

IT4kz8r13It2xNtF1artbcdagSg7JnIiTL03qu0bGBYbCIzQB4YEacn7QFhuOLWoYXNtKEWGhjsFzNbvuN/TG/E5IRysbKJm1rtqZzqVIXu/aoS4PMy8OnwmO/lQBWXE3MCrqhJSBLFeSXAg2l+MJ9zKcCjaJ7H4Zwh9f6PHaOI=

Context

I am trying to implement a location picker where I can help the user pick the coordinates for a given address on a google Map running on iOS or Android.

Visual documentation

just building this widget in a blank app causes the following error,

Screenshot 2024-05-07 at 9 23 23 PM Screenshot 2024-05-07 at 9 23 53 PM

Unknown error compiling custom code. A common cause is a custom widget or action whose name in the code does not match the name provided in the editor.

Additional Info

No response

Environment

- FlutterFlow version: 4.1.48
- Platform: Mac OS Sonoma
- Browser name and version: FlutterFlow App for MacOS
- Operating system and version affected:  MacOS Sonoma 14.4.1

General

Relative to the time the changes were made, data was lost within

When following my steps to reproduce, data loss happens

msusviela commented 1 week ago

Hi @koushikraj96
I was able to reproduce the issue. You need that the parameters type defined in your custom code to match the parameter type defined in your Widget Settings.

Currently, some properties, such as the initial camera are defined like this:

final gmaps.LatLng? initialCamera;

This takes the definition of LatLng implemented in the google_maps_flutter package. However, at the Widget Settings section it is defined as LatIng, which uses the definition implemented in FlutterFlow.

One possible solution to this is to receive a initialCamera value type as defined in FlutterFlow (as an LatLng and not gmaps.LatLng), and then make the conversion to the type used in the package as a variable. Take this as an example:

final initialCameraLatLng = gmaps.LatLng(widget.initialCamera?.latitude ?? 0, widget.initialCamera?.longitude ?? 0);

This should solve your issue.

Thanks for the report!

koushikraj96 commented 1 week ago

Thanks for the prompt response @msusviela.