FlutterError constructor

FlutterError(
  1. String message
)

Create an error message from a string.

The message may have newlines in it. The first line should be a terse description of the error, e.g. "Incorrect GlobalKey usage" or "setState() or markNeedsBuild() called during build". Subsequent lines should contain substantial additional information, ideally sufficient to develop a correct solution to the problem.

In some cases, when a FlutterError is reported to the user, only the first line is included. For example, Flutter will typically only fully report the first exception at runtime, displaying only the first line of subsequent errors.

All sentences in the error should be correctly punctuated (i.e., do end the error message with a period).

This constructor defers to the FlutterError.fromParts constructor. The first line is wrapped in an implied ErrorSummary, and subsequent lines are wrapped in implied ErrorDescriptions. Consider using the FlutterError.fromParts constructor to provide more detail, e.g. using ErrorHints or other DiagnosticsNodes.

Implementation

factory FlutterError(String message) {
  final List<String> lines = message.split('\n');
  return FlutterError.fromParts(<DiagnosticsNode>[
    ErrorSummary(lines.first),
    ...lines.skip(1).map<DiagnosticsNode>((String line) => ErrorDescription(line)),
  ]);
}