I have a customwidget that displays a map and a marker. If works fine when I call it from the first page, but when I call the custom widget from the second class it gives me a unsopported operation: infinity or NaN toInt error.
customWidget.dart
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
class CustomMap extends StatelessWidget {
String? choice;
CustomMap({required this.choice});
@override
Widget build(BuildContext context) {
return FlutterMap(
options: const MapOptions (
initialCenter: LatLng(38.8977, -77.0365),
initialZoom: 19,
interactionOptions:
InteractionOptions(flags: ~InteractiveFlag.doubleTapZoom)
),
children: [
openStreetMapTileLayer,
CircleLayer(
circles: [
CircleMarker(
point: const LatLng(38.8977, -77.0365),
radius: 30,
borderColor: Colors.blue,
borderStrokeWidth: 5,
useRadiusInMeter: true,
color: const Color.fromARGB(255, 206, 192, 192).withOpacity(0.5))
]
),
],
);
}
}
TileLayer get openStreetMapTileLayer => TileLayer (
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
);
I call it from main.dart here and works just fine
body: Stack(
children: [
FlutterMap(
options: const MapOptions(),
children: [
CustomMap(
choice: "two",
),
//content(),
error starts when I call it from SecondPage where I route to from main.dart using MaterialPageRoute
import 'package:flutter/material.dart';
import 'package:my_flutter_app/customWidget.dart';
class SecondPage extends StatefulWidget {
// This is a String for the sake of an example.
// You can use any type you want.
const SecondPage({super.key});
@override
// ignore: library_private_types_in_public_api
_SecondPageState createState() => _SecondPageState();
}
class _SecondPageState extends State<SecondPage> {
final String data = "123";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('Map 2'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CustomMap(
choice: "one",
),
Text(
data,
style: const TextStyle(fontSize: 20),
),
],
),
),
);
}
}
I added a ? to the string variable because it would complain about nullable errors without it. and also I made it required to pass a string. But somewhere its still complaining about NaN.
Any help would be appreciated