I like to simulate an asynchronous web service call in my Dart application for testing. To simulate the randomness of these mock calls responding (possibly out of order) I\
This a useful mock that can take an optional parameter to mock an error:
Future _mockService([dynamic error]) { return new Future.delayed(const Duration(seconds: 2), () { if (error != null) { throw error; } }); }
You can use it like this:
await _mockService(new Exception('network error'));