An error called "Null check operator used on a null value" appeared to use flutter 'custom_info_window: ^1.0.1'. How should I solve this?

class _HomeScreenState extends State<HomeScreen> {

  CustomInfoWindowController _customInfoWindowController =
  CustomInfoWindowController();

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

  final user = FirebaseAuth.instance.currentUser!.email!;

  final curloc = FirebaseFirestore.instance
      .collection('users')
      .doc(FirebaseAuth.instance.currentUser!.email);

  Completer<GoogleMapController> _controller = Completer();
  late BitmapDescriptor sourceIcon;
  late BitmapDescriptor destinationIcon;

  Map<MarkerId, Marker> _markers = <MarkerId, Marker>{};

  void initMarker(specify, specifyID) async {
    final LatLng _latLng = LatLng(specify['lat'], specify['lng']);
    var markerIdval = specifyID;
    final MarkerId markerId = MarkerId(markerIdval);
    final Marker marker = Marker(
      markerId: markerId,
      icon: destinationIcon,
      position: LatLng(specify['lat'], specify['lng']),
      onTap: () {
        _customInfoWindowController.addInfoWindow!(
          Column(
            children: [
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Icon(
                          Icons.account_circle,
                          color: Colors.white,
                          size: 30,
                        ),
                        SizedBox(
                          width: 8.0,
                        ),
                        Text(
                          "I am here",
                          style:
                          Theme.of(context).textTheme.headline6!.copyWith(
                            color: Colors.white,
                          ),
                        )
                      ],
                    ),
                  ),
                  width: double.infinity,
                  height: double.infinity,
                ),
              ),
              Triangle.isosceles(
                edge: Edge.BOTTOM,
                child: Container(
                  color: Colors.blue,
                  width: 20.0,
                  height: 10.0,
                ),
              ),
            ],
          ),
          _latLng,
        );
      },
    );
    setState(() {
      _markers[markerId] = marker;
    });
  }

I used custom_info_window 1.0.1 in pub.dev. It says null safety, but I'm not sure why this problem occurred.

I really want to customize the infowindow on the marker of Google Map.

Please let me know how to solve this problem.

Thank you.


Solution 1: VaasFPS

You are using force-unwrap (exclamation-mark !) here : _customInfoWindowController.addInfoWindow!(

instead of using force-unwrap make it optional by using ? and providing a default value so whenever it is null the app won't crash.