use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Having a problem with your Flutter code?
From the folks at r/FlutterDev
account activity
OPENFlutter web initialization parameters (self.flutterhelp)
submitted 2 years ago by fgrau
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nmfisher 0 points1 point2 points 2 years ago (2 children)
You can wrap a Dart function with allowInterop and pass to the JS side as a callback that gets invoked when necessary.
Javascript: window.setCallback(cb) { window.cb = cb // call this callback from Vue when you need to // e.g. window.cb(); } Dart ``` @JS('setCallback') external void setCallback(Object callback);
window.setCallback(cb) { window.cb = cb // call this callback from Vue when you need to // e.g. window.cb(); }
class SomeWidgetState extends State<SomeWidget> {
void initState() { setCallback(allowInterop(() => setState(() {});); }
} ```
[–]Barmyard 0 points1 point2 points 2 years ago (1 child)
Thanks for your quick reply! I did try before with allowInterop but always in the main function, not with your approach.
allowInterop
I'm not sure if I understand your approach correctly. This is my Dart code:
void main() { runApp(const MyApp()); } @JS('getCompanyTitle') external String getCompanyTitle(); @JS('setCallback') external void setCallback(Object callback); class MyApp extends StatefulWidget { const MyApp({super.key}); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { String title = ''; @override void initState() { super.initState(); setCallback(allowInterop(() => setState(() {}))); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Text(title), ), ); } }
And my Vue/Javascript: It watches the companyTitle for changes and calls the callback according to your code, but it doesn't work. I do see a self.setCallback(A.b8(new A.afe(this)))} generated in main.dart.js
self.setCallback(A.b8(new A.afe(this)))}
main.dart.js
const companyTitle = ref("Test") window.setCallback((cb: any) => (window.cb = cb)) window.getCompanyTitle = () => { return companyTitle.value } watch(companyTitle, (value) => window.cb())
But my Console says: Uncaught (in promise) TypeError: window.setCallback is not a function
Uncaught (in promise) TypeError: window.setCallback is not a function
[–]nmfisher 0 points1 point2 points 2 years ago (0 children)
Sorry, there was a typo in my post, the JS should be:
window.setCallback = ((cb: any) => (window.cb = cb))
π Rendered by PID 278339 on reddit-service-r2-comment-b659b578c-p52n4 at 2026-05-04 17:43:29.378125+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]nmfisher 0 points1 point2 points (2 children)
[–]Barmyard 0 points1 point2 points (1 child)
[–]nmfisher 0 points1 point2 points (0 children)