using SingleChildScrollView whit Flexible Widget

陌路散爱 提交于 2021-01-05 07:36:05

问题


i ran in to Problem while trying Textfield Widget :"bottom overflowed by 48pixels".after that i tried to use SingleChildScrollView widget,but it became more complicated,it shows now this error:

======== Exception caught by rendering library ===================================================== RenderBox was not laid out: RenderCustomPaint#7fee2 relayoutBoundary=up3 NEEDS-PAINT

any Suggestion how can i solve this Problem?!

emulator without use of SingleCHildScrollView

import 'package:flutter/material.dart';
import 'package:filter_list/filter_list.dart';



class FilterPage extends StatefulWidget {
  const FilterPage({Key key, this.allTextList}) : super(key: key);
  final List<String> allTextList;
  @override
  _FilterPageState createState() => _FilterPageState();
}
class _FilterPageState extends State<FilterPage> {
  @override
  Widget build(BuildContext context) {
    List<String> countList = [
      "Art",
      "Markt",
      "Photography",
   
    ];
    return Scaffold(
      
      appBar: AppBar(
      title: Text("Filter list Page"),
      ),
      body: SafeArea(

        child: SingleChildScrollView(
          child: Column(
                children: [
                  Flexible(
                    
                    flex: 2,
                    child: FilterListWidget(
                      allTextList: countList,
                      hideheaderText: true,
                      selectedTextBackgroundColor: Colors.red,
                      applyButonTextBackgroundColor: Colors.red,
                      allResetButonColor: Colors.grey,
                      onApplyButtonClick: (list) {
                        //Navigator.pop(context, list);
                      },
                    ),
                  ),
                  Flexible(
                
                    flex: 3,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Container(
                              width: 160,
                              child: TexstInput(lable: 'min-Upvote',icons: Icons.favorite,),
                            ),
                            Container(
                              width: 160,
                              child: TexstInput(lable: 'max-Upvote'),
                            ),
                          ],
                        ),
                        SizedBox(height: 25),
                        Row(
                          children: [
                            Container(
                              width: 160,
                              child: TexstInput(lable: 'min ',icons: Icons.person,),
                            ),
                            Container(
                              width: 160,
                              child: TexstInput(lable: 'max '),
                            ),
                          ],
                        ),
                        SizedBox(height: 25,),
                     Row(
                       children: [

                         SizedBox(width: 10),
                         RaisedButton(child:Text(
                                  'back'
                              ),onPressed: (){},),
                             
                       ],
                     ),

                         SizedBox(height: 25),
                         Row(
                          mainAxisAlignment: MainAxisAlignment.center,


                            children: [
                              RaisedButton(child:Text(
                                  'back'
                              ),onPressed: (){},),
                              SizedBox(width: 10,),
                              RaisedButton(child:Text(
                                  'apply'
                              ),onPressed: (){})
                            ],
                          ),


                      ],
                    ),
                  ),
                ],
              ),
        ),
          ),


    );
  }

}


class TexstInput extends StatelessWidget {
  TexstInput({
    @required this.lable, this.icons
  }) ;
  IconData icons;
  String lable;
  @override
  Widget build(BuildContext context) {
    return TextField(
      keyboardType: TextInputType.number,
      decoration: InputDecoration(
          icon: Icon(icons),
          contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
          labelText: lable,
          focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.red, width: 5.0),
          ),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.grey, width: 0.8),
          )
      ),
    );
  }
}

回答1:


I noticed that the error is coming from the FilterListWidget. Maybe this can solve your issue

Scaffold(
  appBar: AppBar(
    title: Text("Filter list Page"),
  ),
  body: Column(
    children: [
      Flexible(
        child: FilterListWidget(
          allTextList: countList,
          hideheaderText: true,
          selectedTextBackgroundColor: Colors.red,
          applyButonTextBackgroundColor: Colors.red,
          allResetButonColor: Colors.grey,
          onApplyButtonClick: (list) {
            //Navigator.pop(context, list);
          },
        ),
      ),
      Expanded(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    width: 160,
                    child: TexstInput(lable: 'min-Upvote',icons: Icons.favorite,),
                  ),
                  Container(
                    width: 160,
                    child: TexstInput(lable: 'max-Upvote'),
                  ),
                ],
              ),
              SizedBox(height: 25),
              Row(
                children: [
                  Container(
                    width: 160,
                    child: TexstInput(lable: 'min ',icons: Icons.person,),
                  ),
                  Container(
                    width: 160,
                    child: TexstInput(lable: 'max '),
                  ),
                ],
              ),
              SizedBox(height: 25,),
              Row(
                children: [

                  SizedBox(width: 10),
                  RaisedButton(child:Text(
                      'back'
                  ),onPressed: (){},),

                ],
              ),
              SizedBox(height: 25),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  RaisedButton(child:Text(
                      'back'
                  ),onPressed: (){},),
                  SizedBox(width: 10,),
                  RaisedButton(child:Text(
                      'apply'
                  ),onPressed: (){})
                ],
              ),
            ],
          ),
        ),
      ),
    ],
  ),
)


来源:https://stackoverflow.com/questions/65483783/using-singlechildscrollview-whit-flexible-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!