close
0

What assert do in dart?

avatar
asked 14-09-2021

2 Answers


0
void openUrl({String url}) {
  assert(url.startsWith('https'), 'The url should start with https');
  
  // We can proceed as we 'https' in the url.
}
avatar
answered 14-09-2021

0

assert is similar to an Error in that it is for reporting bad states that should never happen. The difference is that asserts are only checked in debug mode. They are completely ignored in production mode.

Ex:

OverlayEntry({
  @required this.builder,
  bool opaque = false,
  bool maintainState = false,
}) : assert(builder != null),
      assert(opaque != null),
      assert(maintainState != null),
      _opaque = opaque,
      _maintainState = maintainState;
avatar
answered 14-09-2021