web-dev-qa-db-fra.com

L'objet RenderCustomMultiChildLayoutBox a reçu une taille infinie lors de la présentation. erreur de flottement

Je suis nouveau dans le flottement et j'essaie d'implémenter une vue de liste personnalisée dans le flottement. Son objet be RenderCustomMultiChildLayoutBox a reçu une taille infinie lors d'une erreur de mise en page

  1. Je ne parviens pas à savoir pour quel widget son erreur de lancement

2 Veuillez également suggérer comment déboguer ces erreurs de mise en page car la trace d'erreur n'a pas d'informations de widget spécifiques pour lesquelles l'erreur est levée

veuillez trouver le code ci-dessous pour le même:

      class ChatItemSreen extends StatelessWidget {
      var leftSection;
      var middleSection;
      var rightSection;
      ChatModel _chartObj;

      ChatItemSreen(ChatModel _chartObj) {
        this._chartObj = _chartObj;
        //.........the left section ...........................
        CircleAvatar image = new CircleAvatar(
          backgroundColor: Colors.lightGreen,
          backgroundImage: new NetworkImage(this._chartObj.geturl()),
          radius: 24.0,
        );

        leftSection = new Container(child: image);

        //.........the middle section ...........................
        middleSection = new Expanded(
            child: new Container(
          padding: new EdgeInsets.only(left: 8.0),
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              new Text(this._chartObj.getuserName(),
                  style: new TextStyle(
                      color: Colors.black,
                      fontWeight: FontWeight.w300,
                      fontSize: 16.0)),
              new Text(this._chartObj.getmessage(),
                  style: new TextStyle(color: Colors.grey))
            ],
          ),
        ));

        //.........the right section ...........................

        rightSection = new Container(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              new Text(this._chartObj.gettimeStamp()),
              new CircleAvatar(
                  backgroundColor: Colors.lightGreen,
                  radius: 12.0,
                  child: new Text(
                    this._chartObj.getunreadMsgNo(),
                    style: new TextStyle(color: Colors.white, fontSize: 12.0),
                  ))
            ],
          ),
        );
      }

      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          body: new Container(
              margin: new EdgeInsets.all(2.0),
              child: new Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[leftSection, middleSection, rightSection],
              )),
        );
      }
    }

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: "Shashank List", home: RandomWords());
  }
}

class RowItemState extends State<RandomWords>
{
  final List<ChatModel> items = new List();

  @override
  void initState()
  {
    super.initState();
    setState(()
    {
      items.add(new ChatModel("http://img2.thejournal.ie/inline/2470754/original?width=428&version=2470754", "9:35", "2", "Shashank", "Missed vedio call!!"));
      items.add(new ChatModel("http://img2.thejournal.ie/inline/2470754/original?width=428&version=2470754", "10:35", "3", "Kakroo", "Missed vedio call!!"));
      items.add(new ChatModel("http://img2.thejournal.ie/inline/2470754/original?width=428&version=2470754", "02:45", "4", "Alpha 1", "Missed vedio call!!"));
      items.add(new ChatModel("http://img2.thejournal.ie/inline/2470754/original?width=428&version=2470754", "12:30", "6", "Beta 2", "Missed vedio call!!"));

    });
  }

  @override
  Widget build(BuildContext context)
  {
    return MaterialApp(
        home: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context,position)
            {
              ChatModel obj = items.elementAt(position);
              return new ChatItemSreen(obj);
            }
        ),
    );
  }
}

me donne ci-dessous une erreur:

XCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (15078): The following assertion was thrown during performLayout():
I/flutter (15078): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
I/flutter (15078): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (15078): inside another render object that allows its children to pick their own size.
I/flutter (15078): The nearest ancestor providing an unbounded height constraint is:
I/flutter (15078):   RenderIndexedSemantics#a9825 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-Paint
I/flutter (15078):   creator: IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter (15078):   AutomaticKeepAlive ← SliverList ← MediaQuery ← SliverPadding ← Viewport ← _ScrollableScope ←
I/flutter (15078):   IgnorePointer-[GlobalKey#e8d9b] ← Semantics ← Listener ← ⋯
I/flutter (15078):   parentData: index=0; layoutOffset=0.0 (can use size)
I/flutter (15078):   constraints: BoxConstraints(w=411.4, 0.0<=h<=Infinity)
I/flutter (15078):   semantic boundary
I/flutter (15078):   size: MISSING
I/flutter (15078):   index: 0
I/flutter (15078): The constraints that applied to the RenderCustomMultiChildLayoutBox were:
I/flutter (15078):   BoxConstraints(w=411.4, 0.0<=h<=Infinity)
I/flutter (15078): The exact size it was given was:
I/flutter (15078):   Size(411.4, Infinity)
I/flutter (15078): See https://flutter.io/layout/ for more information.
11
shashank kakroo

J'ai eu ce problème exact en essayant d'inclure un widget PhotoView pincé et zoomable parmi des paragraphes de texte séparés.

Lorsque vous compilez et exécutez l'application, vous avez probablement remarqué que l'endroit où votre widget incriminé est censé se trouver est une zone noire infiniment longue.

La deuxième ligne de l'erreur indique

a reçu une taille infinie lors de la mise en page

ce qui implique que la taille du widget doit être contrainte.

Ma solution était d'envelopper le PhotoView dans un widget SizedBox.

...
   Text("Here's some text.\nAnd then there's this image:\n"),
   SizedBox(
      width: 200.0,
      height: 300.0,
      child: PhotoView(
            imageProvider: NetworkImage("http://image/url/here.jpg"),
            heroTag: "Lauren Mayberry",
            ),
   ),
   Text("And now more text"),
...

Dans cet exemple, j'ai utilisé une largeur et une hauteur fixes, mais vous pouvez toujours dimensionner dynamiquement votre widget en fonction du contenu qui y appartient.

Quant à la façon de mieux déboguer les erreurs de mise en page: ma seule suggestion est de supprimer les widgets un par un jusqu'à ce que l'erreur disparaisse. C'est certainement moins qu'idéal mais ça marche.

3