Last active
December 1, 2022 18:06
-
-
Save ben-xD/0e12aa0f4745213a7efa5b5ff8c4934e to your computer and use it in GitHub Desktop.
Example problem needing FutureOr<> in Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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