fetch()
imported via js_interop
using extension typesThis example uses imported via dart:js_interop
raw fetch()
function, and gets content via extension type.
See the output in browser developer console.
Actual code:
import 'dart:js_interop'; @JS() external JSPromisefetch(JSString resource); extension type Response(JSObject _) implements JSObject { @JS() external JSPromise text(); } final Response resp = await fetch('https://httpbin.org/anything'.toJS).toDart; final txt = await resp.text().toDart; print('body: ${txt}');