Home > Net >  Exception caught by widgets library Incorrect use of ParentDataWidget
Exception caught by widgets library Incorrect use of ParentDataWidget

Time:07-26

When I am trying to display the data present in firebase realtime database. I am getting the error stating Exception caught by widgets library Incorrect use of ParentDataWidget.

   class NotificationView extends StatefulWidget {
      const NotificationView({Key key}) : super(key: key);
    
      @override
      State<NotificationView> createState() => _NotificationViewState();
    }
    
    class _NotificationViewState extends State<NotificationView> {
      Map data;
      List key;
      @override
      void initState() {
        fetchData();
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        Size size = MediaQuery.of(context).size;
        return Scaffold(
            backgroundColor: Colors.white,
            body: Container(
                child: FutureBuilder(
                    future: fetchData(),
                    builder: (context, snapshot) {
                      if (data != null) {
                        return ListView.builder(
                            itemCount: data.values.length,
                            itemBuilder: (BuildContext context, int index) {
                              return Container(
                                height: 100,
                                child: Card(
                                  margin: EdgeInsets.fromLTRB(15, 5, 15, 15),
                                  color: Colors.yellow[100],
                                  elevation: 10,
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(10)),
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(15, 5, 15, 15),
                                    child: Expanded(
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Text(data[key[index]]['title']),
                                          SizedBox(height: size.height * 0.01),
                                          Text(data[key[index]]['message']),
                                        ],
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            });
                      } else {
                        return Center(child: CircularProgressIndicator());
                      }
                    })));
      }
    
      fetchData() async {
        var userId = SharedUtils.getString('UserId');
        final ref = FirebaseDatabase.instance.ref();
        final snapshot =
            await ref.child('users/62cfc3faf3e5df6648d32684/inApp').get();
        debugPrint(snapshot.key   'KEyyyyyyyyyyyyyyyyyyyyy');
        data = snapshot.value;
        key = data.keys.toList();
        debugPrint(
            'Listttttttttttttttofffffffffffkeyyyyyyyyyyyyyy&&&77'   key.toString());
      }
    }

CodePudding user response:

You are using "Expanded" as the child of the container which is wrong. Be aware that, you can use the "Expanded" widget only as the child of columns, rows, and flex. That's why you are getting this "Incorrect use of ParentDataWidget".

More details for Expanded widget.

  • Related