liodali / osm_flutter

OpenStreetMap plugin for flutter
https://pub.dev/packages/flutter_osm_plugin
MIT License
240 stars 98 forks source link

Multiple widgets used the same GlobalKey. #519

Closed swarupbc closed 7 months ago

swarupbc commented 7 months ago

The following assertion was thrown while finalizing the widget tree: Multiple widgets used the same GlobalKey. The key [GlobalKey#e1875] was used by multiple widgets. The parents of those widgets were:

Code:

import 'package:flutter/material.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
import 'package:work_app/views/screens/constants.dart';
import 'package:work_app/widgets/primary_button.dart';

class AddAddressScreen extends StatefulWidget {
  const AddAddressScreen({super.key});

  @override
  State<AddAddressScreen> createState() => _AddAddressScreenState();
}

class _AddAddressScreenState extends State<AddAddressScreen> {
  MapController mapController = MapController(
    initPosition: GeoPoint(latitude: 47.4358055, longitude: 8.4737324),
    areaLimit: BoundingBox(
      east: 10.4922941,
      north: 47.8084648,
      south: 45.817995,
      west: 5.9559113,
    ),
  );

  @override
  void dispose() {
    mapController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Add New Address'),
      ),
      body: SafeArea(
          child: OSMFlutter(
              controller: mapController,
              osmOption: OSMOption(
                isPicker: true,
                showZoomController: true,
                userTrackingOption: const UserTrackingOption(
                  enableTracking: true,
                  unFollowUser: false,
                ),
                zoomOption: const ZoomOption(
                  initZoom: 8,
                  minZoomLevel: 3,
                  maxZoomLevel: 19,
                  stepZoom: 1.0,
                ),
                userLocationMarker: UserLocationMaker(
                  personMarker: const MarkerIcon(
                    icon: Icon(
                      Icons.location_history_rounded,
                      color: Colors.red,
                      size: 48,
                    ),
                  ),
                  directionArrowMarker: const MarkerIcon(
                    icon: Icon(
                      Icons.double_arrow,
                      size: 48,
                    ),
                  ),
                ),
                roadConfiguration: const RoadOption(
                  roadColor: Colors.yellowAccent,
                ),
                // markerOption: MarkerOption(
                //     defaultMarker: const MarkerIcon(
                //         icon: Icon(
                //           Icons.person_pin_circle,
                //           color: Colors.blue,
                //           size: 56,
                //         ),
                //     )
                // ),
              ))),
      bottomSheet: DraggableScrollableSheet(
        expand: false,
        maxChildSize: 0.7,
        snap: true,
        initialChildSize: 0.3,
        minChildSize: 0.2,
        builder: (BuildContext context, ScrollController scrollController) {
          return Container(
            color: const Color(0xFFE6E6E6),
            child: SingleChildScrollView(
              padding: const EdgeInsets.all(32),
              controller: scrollController,
              child: Column(
                // crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  primaryTitle('Type your address'),
                  heightGap20,
                  Wrap(
                    runSpacing: 30,
                    children: [
                      textInput(
                        label: 'Building Name/Street Name',
                      ),
                      textInput(
                        label: 'Locality/Area',
                      ),
                      textInput(
                        keyboardType: const TextInputType.numberWithOptions(),
                        label: 'Pin Code',
                        // keyboardType: TextInputType.number,
                      ),
                    ],
                  ),
                  heightGap40,
                  PrimaryButton(onPressed: () {}, label: 'Save Address')
                ],
              ),
            ),
          );
        },
      ),
    );
  }

  Widget textInput(
      {required String label,
      TextEditingController? controller,
      TextInputType? keyboardType}) {
    return TextFormField(
      controller: controller,
      keyboardType: keyboardType,
      decoration: InputDecoration(
        hintText: label,
        border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
      ),
    );
  }
}
liodali commented 7 months ago

i will do quick fix for it

Danilz-2706 commented 7 months ago

I got the same error when I got version 1.0.0 and also 1.0.1. Please help me.

liodali commented 7 months ago

i made the fix but i was fixing something else so i was lazy little bit to do update but will be in couple of minutes sorry for that

liodali commented 7 months ago

sorry for this there is issue in dart github action with publishing new version tp pub.dev so the new version will delayed little bit until find solution

tmp78 commented 7 months ago

I have the same problem after updating from 1.0.0-rc.6 to 1.0.1.

liodali commented 7 months ago

new version 1.0.2 has been published now

Danilz-2706 commented 7 months ago

Done, your team worked so quickly, thank you very much

tmp78 commented 7 months ago

Thanks.