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

Categories

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

flutter - Layout error due to ListView and PageView

Widget build(BuildContext context) {
    super.build(context);

    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
      ),
      child: Scaffold(
          key: _scaffoldKeyProfilePage,
          backgroundColor: Colors.white,
          body: user == null
      ? Center(
          child: CircularProgressIndicator(),
        )
      : RefreshIndicator(
          onRefresh: _onRefresh,
          child: ListView(
              shrinkWrap: true,
              padding: EdgeInsets.all(0),
               
                  children: [
                    BuildMainProfile(
           ....//build profile (with heiht = ScreenHeight/1.4)
          ),
                   
                    Container(
                   ...//to build bio section 
                    ),
                 
                    Flexible(
                            child: PageView(
            
            children: [
              ListView.builder(
                            
                        shrinkWrap: true,
                          itemCount: 30,
                          itemBuilder: (BuildContext context, int index) {
                          return Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Container(color: index%2==0?Colors.red:Colors.green,height: 30.0,width: double.infinity,),
                          );
                         },
                        ),
           Container(height: 400,width: 200,color: Colors.green,),
            Container(height: 400,width: 200,color: Colors.blue,),
             Container(height: 400,width: 200,color: Colors.pink,)
            ],
                  ),
                    )
                  ],
                ),
        ),
        ),
    );
  

I am getting an error saying :

The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a I/flutter ( 9926): RenderObject, which has been set up to accept ParentData of incompatible type ParentData. I/flutter ( 9926): Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, I/flutter ( 9926): Flexible widgets are placed directly inside Flex widgets. I/flutter ( 9926): The offending Flexible is currently placed inside a RepaintBoundary widget.
.
.
.
.
Another exception was thrown: Horizontal viewport was given unbounded height. I/flutter ( 9926): Another exception was thrown: RenderBox was not laid out: RenderViewport#4dd2b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE I/flutter ( 9926): Another exception was thrown: RenderBox was not laid out: RenderViewport#4dd2b NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

How can this error be removed, I have even used Flexible over PageView and shrinkWrap in listView.


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

1 Answer

0 votes
by (71.8m points)

You cannot directly use Flexible in ListView. Maybe you must try something like this

return DefaultTabController(
  length: 3,
  child: Scaffold(
    appBar: AppBar(
      title: Text(Translator.of(context).translate("ratingsandreviews"),),
      bottom: TabBar(
        indicator: UnderlineTabIndicator(),
        tabs: <Widget>[
          Tab(child: Icon(Icons.grid_on_outlined),),
          Tab(child: Icon(Icons.timeline),),
          Tab(child: Icon(Icons.account_box),),
        ],
      ),
    ),
    body: TabBarView(
      children: <Widget>[
        ListView(
          children: [
            BuildMainProfile(),
            Container(
              //to build bio section 
            ),
            Expanded(
              child: GridView.builder(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemCount: POSTLIST.length,
                itemBuilder: (context, index) {
                  return Container(); // or what you want
                },
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  childAspectRatio: 1.0,
                ),
              ),
            ),
          ],
        ),
        SecondPage(), // second page
        ThirdPage(), // third page
        Fourth(), // fourth page
        // RideSharingReviewsPage(),
      ],
    ),
  ),
);

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

2.1m questions

2.1m answers

63 comments

56.6k users

...