Home > OS >  (Flutter/Dart) - How to convert double? to double
(Flutter/Dart) - How to convert double? to double

Time:03-25

anyways to convert double? to double

because i got this message with no auto fix enter image description here

CodePudding user response:

The error you get is from null-safety, the type double? means that it could be either a double, or null, but your parameter only accepts a double, and no null.

For this, you can "force" the use of 'non-null' variable by adding a ! at the end of your variable, but be careful when doing this.

CameraPosition(
    target: LatLng(l.latitude!, l.longitude!),
    zoom: 15,
)

You can learn more about null-safety syntax and principles on the official documentation: https://flutter.dev/docs/null-safety

CodePudding user response:

Type? // nullable
Type  // non-null

The ? at the end of any type (in this case double) indicates that the value could be null. While double only ensures it is non-null.

Read dart null safety.

CodePudding user response:

define : double latitude = 0.0;

  • Related