toDouble method

double? toDouble()

Converts a string todouble if possible.

If conversion fails, null is returned.

Example

String foo = '4';
int fooInt = foo.toDouble(); // returns 4.0;
String foo = '4f';
var fooNull = foo.toDouble(); // returns null;

Implementation

double? toDouble() {
  if (this == null) return null;
  if (this!.isEmpty) return null;
  return double.tryParse(this!);
}