flutterfirebaselistviewflutter-streambuilder

RenderFlex error unsolved by shrinkWrap, SizedBox or Expanded


I am currently building an AlertDialog to show reviews for a specific dish. I get the following errors:

The following assertion was thrown during performLayout(): RenderShrinkWrappingViewport does not support returning intrinsic dimensions. Updated layout information required for RenderFlex#d31e4 relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics. 'package:flutter/src/rendering/object.dart': Failed assertion: line 3175 pos 12: '!_needsLayout'

The code I am using is the following

return AlertDialog(
title: Center(child: Text("Αξιολογήσεις")),
content: Column(
  mainAxisSize: MainAxisSize.min,
  children: [
      Divider(height: 5, color: Colors.blueGrey,),
      StreamBuilder<List<Review>>(
        stream: DatabaseService(collectionName: 'ratings').reviews,
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return CircularProgressIndicator();
          }
          final reviews = snapshot.data!;
          return ListView(
            shrinkWrap: true,
            children: reviews.map((review) => Review(rating: review.rating, username: review.timestamp, review: review.review, timestamp: review.timestamp,)).toList(),
          );
        },
      ),
  ],
),
);

The review widget:

class Review extends StatelessWidget{
  final String username;
  final double rating;
  final String review;
  final String timestamp;
  const Review({super.key, required this.rating, required this.username, required this.review, required this.timestamp});

  @override
  Widget build(BuildContext context){
    return ListTile(
        title: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
              CircleAvatar(
                backgroundImage: AssetImage('assets/logo_circle_white.png'),
                radius: 24.0,
              ),
              SizedBox(width: 8,),
              Expanded(child: Text("Ο χρήστης $username αναφέρει:",style: TextStyle(fontSize: 16, fontStyle: FontStyle.italic),))
            ]),
          ],
        ),
      subtitle: Column(
        children: [
          Text('Η κριτική υποβλήθηκε στις: $timestamp'),
          Divider()
        ],
      ),
      trailing: Text('$rating'),
    );
  }
}

and finally the database function

  //get item stream
  Stream<List<Review>> get reviews{
    return itemCollection.snapshots().map(_getRatingsFromSnapshot);
  }

  List<Review> _getRatingsFromSnapshot(QuerySnapshot snapshot){ // _ makes it private
    try {
      return snapshot.docs.map((doc) { // map cycles through document list
        return Review( //return a review for each one
          username: doc.get('username') ?? 'anonymous',
          rating: doc.get('rating').toDouble() ?? 0.0,
          review: doc.get('review') ?? '-',
          timestamp: doc.get('timestamp') ?? '00:00 00/00/00',
        );
      }).toList(); // convert iterable to list
    }
    catch(e){
      print(e.toString());
      return [];
    }
  }

I have tried placing the listview in an Expanded widget, a SizedBox with height, wrapping in a SingleChildScrollViewer and same for the Streambuilder. These solutions did not fix my problem. What could be the issue?


Solution

  • Instead of AlertDialog try Dialog

    return Dialog(
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
          Center(child: Text("Αξιολογήσεις")),
          Divider(height: 5, color: Colors.blueGrey,),
          StreamBuilder<List<Review>>(
            stream: DatabaseService(collectionName: 'ratings').reviews,
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return CircularProgressIndicator();
              }
              final reviews = snapshot.data!;
              return ListView(
                shrinkWrap: true,
                children: reviews.map((review) => Review(rating: review.rating, username: review.timestamp, review: review.review, timestamp: review.timestamp,)).toList(),
              );
            },
          ),
      ],
    ),
    );