Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

firebase - StreamBuilder<Event>(dirty, state: _StreamBuilderBaseState<Event, AsyncSnapshot<Event>>#ac213):

i'm just learning flutter, and i'm find problem. i can't retrive data from firebase, previously I could retrieve data with the same code but now I can't. i found I found an error as listed below. and how did that happen? whereas before that it wasn't. I hope someone will help me

this is my code

``` StreamBuilder(
        stream: dbRef.child("Data").onValue,
        builder: (context, snapshot) {
          if (snapshot.hasData &&
              !snapshot.hasError &&
              snapshot.data.snapshot.value != null) {
            return Column(
              children: <Widget>[
                Container(
                    height: size.height * 1,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                            height: 40,
                            bottom: 520,
                            left: 0,
                            right: 0,
                            child: Container(
                              margin: EdgeInsets.symmetric(
                                  horizontal: kDefaultPadding),
                              padding: EdgeInsets.symmetric(
                                  horizontal: kDefaultPadding),
                              height: 10,
                              decoration: BoxDecoration(
                                color: Colors.cyan,
                                borderRadius: BorderRadius.circular(15),
                                boxShadow: [
                                  BoxShadow(
                                    offset: Offset(0, 10),
                                    blurRadius: 50,
                                    color: kPrimaryColor.withOpacity(0.5),
                                  ),
                                ],
                              ),
                              child: Center(
                                child: Text("PLANT MOISTURE CONTROLLER",
                                    style: TextStyle(fontSize: 18)),
                              ),
                            )),],))],)}}) ```

this is the error:

this is the error:

question from:https://stackoverflow.com/questions/65861202/streambuildereventdirty-state-streambuilderbasestateevent-asyncsnapshot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to return some widget while the data is loading, example:

StreamBuilder(
  stream: dbRef.child("Data").onValue,
  builder: (context, snapshot) {
    if (!snapshot.hasData)
      return Center(child: CircularProgressIndicator());
    
    return Container(child: Text('real content'));
  });  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...