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