3

Flutter source files contains many times code similar to this:

 @override
  double computeMinIntrinsicWidth(double height) {
    if (child != null)
      return child!.getMinIntrinsicWidth(height);
    return 0.0;
  }

Please explain "!." I can't find it on list of dart operators.

Piotr Temp
  • 385
  • 5
  • 12
  • 1
    Probably something like "null assertion" operator? –  Nov 16 '20 at 15:39
  • There is conditional member access operator "?." in dart, but I'm asking about "!.". – Piotr Temp Nov 16 '20 at 15:43
  • Ok. I think maybe somewhere in code there is overloaded operator "!", so child!.getMinIntrinsicWidth(height) is in fact child.operator!().getMinIntrinsicWidth(height) ... – Piotr Temp Nov 16 '20 at 15:53
  • Related SO question? https://stackoverflow.com/questions/60068435 –  Nov 16 '20 at 16:13

2 Answers2

3

A postfix exclamation mark (!) takes the expression on the left and casts it to its underlying non-nullable type. So it changes:

String toString() {
  if (code == 200) return 'OK';
  return 'ERROR $code ${(error as String).toUpperCase()}';
}

to something like this:

String toString() {
  if (code == 200) return 'OK';
  return 'ERROR $code ${error!.toUpperCase()}';
}

You can read more about null safety in this document.

Payam Asefi
  • 2,677
  • 2
  • 15
  • 26
0

It's the "(not)null assertion operator" which becomes part of Dart with the Null Safety feature in the next release.

WebMaster
  • 3,050
  • 4
  • 25
  • 77