Skip to content

Instantly share code, notes, and snippets.

@ben-xD
Last active December 1, 2022 18:06
Show Gist options
  • Save ben-xD/0e12aa0f4745213a7efa5b5ff8c4934e to your computer and use it in GitHub Desktop.
Save ben-xD/0e12aa0f4745213a7efa5b5ff8c4934e to your computer and use it in GitHub Desktop.
Example problem needing FutureOr<> in Dart
import 'dart:async';
import 'package:http/http.dart' as Http;
String callbackOne() => "hello";
Future<String> callbackTwo() async => (await Future.delayed(Duration(seconds: 1),() => "This is a sentence"));
Future<int> getLengthOfResult2(String Function() callback) async {
return callback().length;
}
main() async {
getLengthOfResult2(callbackOne);
getLengthOfResult2(callbackTwo);
}
// For solution, see: https://dartpad.dev/?id=be619b223f20656ad5833402f93487ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment