0

resultant page while remove singlechild scroolviewI was trying to make a dropdown like custom search -result page but it failed with some errors like RenderFlex children have non-zero flex but incoming height constraints are unbounded. Is there is any way to solve with out package?? when i remove single child scroll view everything except scroling is working but is there is any way to implement scrollable?

ListPage

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

class ListPage extends StatefulWidget {
  @override
  _ListPageState createState() => _ListPageState();
}

class _ListPageState extends State<ListPage> {
  List<Map<String, String>> studentList = [
    {"John Honai": "Tokio"},
    {"John Wick": "Cuba"}
  ];
  bool showList = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            SizedBox(
              height: 20,
            ),
            Container(
              height: 50,
              child: Text("container1 height 50"),color: Colors.lightBlue,
            ),
            SizedBox(
              height: 20,
            ),
            Container(
              height: 50,
              child: Text("container2 height 50"),color: Colors.orangeAccent,
            ),
            SizedBox(
              height: 20,
            ),
            ButtonSearchExpanded(
              onChangedText: (_) {
                setState(() {
                  showList = true;
                });
              },
              showList: showList,
              studentList: studentList,
            ),
            SizedBox(
              height: 20,
            ),
            Container(
              height: 50,
              child: Text("container3 height 50"),color: Colors.white54,
            ),
            SizedBox(
              height: 20,
            ),
            Container(
              height: 50,
              child: Text("container4 height 50"),color: Colors.cyanAccent,
            ),
          ],
        ),
      ),
    );
  }
}

Widgetpage textfield on changed response passed to the list page and passed back show studentList as true which show a list view.

import 'package:flutter/material.dart';

class ButtonSearchExpanded extends StatelessWidget {
  final List<Map<String, String>> studentList;
  final bool showList;
final Function onChangedText;
  ButtonSearchExpanded(
      {
      this.onChangedText,this.studentList,this.showList});
  @override
  Widget build(BuildContext context) {
    return Expanded(
        child: Container(
      child: Column(
        children: [
          Container(
            height: 60,
            child: Row(
              children: [Expanded(child:
               TextField(onChanged: onChangedText,)), Text("some other content"),

              ],
            ),
          ),showList?Expanded(child: ListView.builder(itemCount:studentList.length,itemBuilder: (context,index){
            return ListTile(title: Text(studentList[index].keys.first),trailing: Text(studentList[index].values.first),);
          })):Container()
        ],
      ),
    ));
  }


}
A.K.J.94
  • 492
  • 6
  • 14

2 Answers2

0

Did you tried by adding this line shrinkWrap: true, ?

ListView.builder(
shrinkwrap:true, // add this line 
itemBuilder: (context,index){
            return 
Aamil Silawat
  • 7,735
  • 3
  • 19
  • 37
  • yes i tried like so but i getting only 2 containers on the top of it and getting renderflex unbounded error – A.K.J.94 Jan 30 '21 at 06:17
0

it is not possible up-to my research that column->expanded-> listviewbuilder is mutually controverting each other because column shrinks it child while expanded expand child so I changed it to Flexible with property flexfit.loose and column property Main axis size min, hence it solved the problem. i got this answer from How to use Expanded in SingleChildScrollView?

  final List<Map<String, String>> studentList;
  final bool showList;
final Function onChangedText;
  ButtonSearchExpanded(
      {
      this.onChangedText,this.studentList,this.showList});
  @override
  Widget build(BuildContext context) {
    return Column(mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          height: 60,
          child: Row(
            children: [
             Expanded(child: TextField(onChanged: onChangedText,)), Text("some other content"),

            ],
          ),
        ),showList?Flexible(fit: FlexFit.loose,child: ListView.builder(shrinkWrap: true,itemCount: studentList.length,itemBuilder: (context,index){
          return ListTile(title: Text(studentList[index].keys.first),trailing: Text(studentList[index].values.first),);
        })):Container()
      ],
    );
  }


} 
A.K.J.94
  • 492
  • 6
  • 14