简体   繁体   中英

Layout issue with singlechildscrollview and stack

Why this code is not correct?

I have this error:

RenderBox was not laid out: RenderRepaintBoundary#681d3 relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1930 pos 12: 'hasSize'

The relevant error-causing widget was Scaffold lib…\\rank\\rankView.dart:23

Should I define size for scaffold?

SafeArea(
  child: Scaffold(
    resizeToAvoidBottomInset: false,
    body: SingleChildScrollView(
      child: Stack(children: <Widget>[
        Positioned(
            top: 550,
            left: 8,
            right: 8,
            bottom: 0,
            child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  for (final result in controller.results)
                    Container(height: 50, color: Colors.black),
                ]))

Why you are using scaffold inside a safearea. If you have this as a screen. they you can simply return a scaffold and add safearea as a child of scaffold.

return Scaffold(
 body: SafeArea(), ); 

like this

  1. You are using stack to position inside a scrollview. I don't think that's a good way. as you have only one widget inside a stack.

So better you can use container position it according to. and then add a child column to the container.

So your code might look like this,

Scaffold(
  resizeToAvoidBottomInset: false,
  body: SafeArea(
    child: SingleChildScrollView(
      child: Container(
 //you need to position from the top 550 and left right  8 units
 //that you can do by the margin or padding: 
       margin: EdgeInsets.only(top: 550, left: 8, right: 8),

            child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  for (final result in controller.results)
                    Container(height: 50, color: Colors.black),
                ],
              ),
            ),
         ),
        ),
      );

That should work perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM