Error: TypeError: Instance of '_Exception': type '_Exception' is not a subtype of type 'JavaScriptObject'
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:flutter/material.dart'; import 'package:realtimedbtest/firebase_options.dart'; String result = ""; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); DatabaseReference ref = FirebaseDatabase.instance.ref('widget/image/name'); ref.onValue.listen((DatabaseEvent event) { result = event.snapshot.value.toString(); }); runApp(const MainApp()); } class MainApp extends StatelessWidget { const MainApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Text("result: $result"), ), ), ); } }
DatabaseReference ref = FirebaseDatabase.instance.ref('widget/image/name'); ref.onValue.listen((DatabaseEvent event) async { //<-- I put async here. result = event.snapshot.value.toString(); });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)