T M
T M

Reputation: 221

(Flutter/Dart) - How to convert double? to double

anyways to convert double? to double

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

Upvotes: 0

Views: 1671

Answers (3)

Sathya Prakash
Sathya Prakash

Reputation: 26

define : double latitude = 0.0;

Upvotes: 0

jbmcle
jbmcle

Reputation: 811

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.

Upvotes: 0

Amirhussein
Amirhussein

Reputation: 105

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

Upvotes: 2

Related Questions