You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I want to implement FirebaseDatabase into my application but it doesn't write anything although I enable Realtime Database, init FirebaseApp
Here is my main.dart code
import'package:firebase_core/firebase_core.dart';
import'package:firebase_database/firebase_database.dart';
import'package:flutter/material.dart';
import'package:iot4home/ui/login.dart';
import'package:sizer/sizer.dart';
voidmain() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
classMyAppextendsStatelessWidget {
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnSizer(builder: (context, orientation, deviceType) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
// This is the theme of your application.//// Try running your application with "flutter run". You'll see the// application has a blue toolbar. Then, without quitting the app, try// changing the primarySwatch below to Colors.green and then invoke// "hot reload" (press "r" in the console where you ran "flutter run",// or simply save your changes to "hot reload" in a Flutter IDE).// Notice that the counter didn't reset back to zero; the application// is not restarted.
primarySwatch:Colors.blue,
),
home:MyHomePage(title:'IoT for Home'),
);
});
}
}
classMyHomePageextendsStatefulWidget {
MyHomePage({Key? key, requiredthis.title}) :super(key: key);
// This widget is the home page of your application. It is stateful, meaning// that it has a State object (defined below) that contains fields that affect// how it looks.// This class is the configuration for the state. It holds the values (in this// case the title) provided by the parent (in this case the App widget) and// used by the build method of the State. Fields in a Widget subclass are// always marked "final".finalString title;
@override_MyHomePageStatecreateState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
finalFuture<FirebaseApp> _initialization =Firebase.initializeApp();
@overrideWidgetbuild(BuildContext context) {
print(Theme.of(context).platform);
returnFutureBuilder(
// Initialize FlutterFire:
future: _initialization,
builder: (context, AsyncSnapshot<FirebaseApp> snapshot) {
// Check for errorsif (snapshot.hasError) {
returnText("Something went wrong");
}
// Once complete, show your applicationif (snapshot.connectionState ==ConnectionState.done) {
finalFirebaseDatabase database =FirebaseDatabase(app: snapshot.data);
DatabaseReference _messagesRef = database.reference().child('messages');
_messagesRef.set("Hello World");
returnScaffold(
appBar:AppBar(
// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.
title:Text(widget.title),
),
body:LoginUI());
}
// Otherwise, show something whilst waiting for initialization to completereturnScaffold(
body:Center(
child:CircularProgressIndicator(),
));
},
);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I want to implement FirebaseDatabase into my application but it doesn't write anything although I enable Realtime Database, init FirebaseApp
Here is my
main.dart
codeSorry for my bad English
Beta Was this translation helpful? Give feedback.
All reactions