Flutter 颤振:如何创建两列布局,每个列中具有不同大小的可滚动列表视图

Flutter 颤振:如何创建两列布局,每个列中具有不同大小的可滚动列表视图,flutter,flutter-layout,Flutter,Flutter Layout,我试图在Flutter中创建一个两列布局,左侧有一个ListView,右侧有一列中有三个容器。我遇到的问题是,右边的容器需要能够随着数据的变化而扩展,这最终会导致RenderFlex溢出 使用SingleChildScrollView时,列滚动正常,但一旦超过视口约束,就会出现错误。我已经使用MediaQuery设置了行的高度,但这似乎没有效果。 下面的示例代码模拟了这种情况。。。单击AppBar中的“添加”按钮以增加容器中文本的大小 import 'package:flutter/materi

我试图在Flutter中创建一个两列布局,左侧有一个ListView,右侧有一列中有三个容器。我遇到的问题是,右边的容器需要能够随着数据的变化而扩展,这最终会导致RenderFlex溢出

使用SingleChildScrollView时,列滚动正常,但一旦超过视口约束,就会出现错误。我已经使用MediaQuery设置了行的高度,但这似乎没有效果。 下面的示例代码模拟了这种情况。。。单击AppBar中的“添加”按钮以增加容器中文本的大小

import 'package:flutter/material.dart';

class Test extends StatefulWidget {
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  List<String> _students = ['Gianluca','Lindsay','Leah','U','Marco','Liam','Harrison','Charise','Ting Wei','Ryan','Deena','Xiao Yuan','Benjamin','Calvin','Claudia','Kok Hao','Michalina','Ruby','Rachel','Nadir','Dan','Raaid','Nadia','Matilda','Lloyd','Arielle','Jun','Desmond','Miah','Aiden','Kira','Nathan','Thung Thung','Miki','Yongyou','Brogan','Zai Chern','Gondini','Ella','Germaine'];
  String textData = "";
  int current = 0;
  bool init = true;

  @override
  void initState() {
    addName();
    super.initState();
  }

  addName(){
    if(init){
      for(int i=0; i<_students.length;i++){
        textData+= _students[i]+ "   ";
      }
    } else {
      textData += _students[current] + "   ";
      if (current > _students.length) {
        current = 0;
      } else {
        current++;
      }
    }
    setState(() {
    });
    print(textData);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          FlatButton(
            onPressed: (){
              addName();
            },
            child: Icon(
              Icons.add,
            ),
          ),
        ],
      ),
      body: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    color: Colors.yellow,
                    height: MediaQuery.of(context).size.height,
                    child: ListView.builder(
                      itemCount: _students.length,
                      itemBuilder: (context, index) {
                        return new Text(_students[index]);
                      },
                    ),
                  ),
                ],
              ),
            ),
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    color: Colors.green,
                    height: MediaQuery.of(context).size.height,
                    child: Column(
                      children: <Widget>[
                        Container(
                          color: Colors.red,
                          child: Text(textData),
                        ),
                        Container(
                          color: Colors.green,
                          child: Text(textData),
                        ),
                        Container(
                          color: Colors.blue,
                          child: Text(textData),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
类测试扩展了StatefulWidget{
@凌驾
_TestState createState();
}
类_TestState扩展状态{
名单_学生=“吉安路政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政政迪尼,埃拉,“日尔曼”];
字符串textData=“”;
int电流=0;
bool init=true;
@凌驾
void initState(){
addName();
super.initState();
}
addName(){
if(init){
for(int i=0;i_students.length){
电流=0;
}否则{
电流++;
}
}
设置状态(){
});
打印(文本数据);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
行动:[
扁平按钮(
已按下:(){
addName();
},
子:图标(
Icons.add,
),
),
],
),
正文:世界其他地区(
mainAxisAlignment:mainAxisAlignment.space,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
扩大(
子:SingleChildScrollView(
子:列(
儿童:[
容器(
颜色:颜色,黄色,
高度:MediaQuery.of(context).size.height,
子项:ListView.builder(
itemCount:_students.length,
itemBuilder:(上下文,索引){
返回新文本(_students[index]);
},
),
),
],
),
),
),
扩大(
子:SingleChildScrollView(
子:列(
儿童:[
容器(
颜色:颜色。绿色,
高度:MediaQuery.of(context).size.height,
子:列(
儿童:[
容器(
颜色:颜色,红色,
子项:文本(textData),
),
容器(
颜色:颜色。绿色,
子项:文本(textData),
),
容器(
颜色:颜色,蓝色,
子项:文本(textData),
),
],
),
),
],
),
),
),
],
),
);
}
}

您可以简化对两个
列使用
列表视图的过程:

导入“包装:颤振/材料.省道”;
void main(){
runApp(
材料聚丙烯(
标题:“使用扫描”,
家:脚手架(
正文:Test(),
),
),
);
}
类测试扩展了StatefulWidget{
@凌驾
_TestState createState();
}
类_TestState扩展状态{
名单_学生=[
“吉安卢卡”,
“林赛”,
“利亚”,
"U",,
“马可”,
“Liam”,
“哈里森”,
“查里斯”,
"丁伟",,
“Ryan”,
“迪娜”,
"小远",,
“本杰明”,
“卡尔文”,
“克劳迪娅”,
"角豪",,
“Michalina”,
“红宝石”,
“瑞秋”,
“最低点”,
“丹”,
“Raaid”,
“娜迪亚”,
“玛蒂尔达”,
“劳埃德”,
“阿里尔”,
"六月",,
“德斯蒙德”,
“米娅”,
“艾登”,
“基拉”,
“内森”,
"咚咚",,
“Miki”,
"用友",,
“布罗根”,
"在臣",,
“冈迪尼”,
“埃拉”,
“日尔曼”
];
字符串textData=“”;
int电流=0;
bool init=true;
@凌驾
void initState(){
addName();
super.initState();
}
addName(){
if(init){
对于(int i=0;i<\u students.length;i++){
textData+=_学生[i]+';
}
}否则{
text数据+=_学生[当前]+“”;
如果(当前>\u students.length){
电流=0;
}否则{
电流++;
}
}
setState((){});
打印(文本数据);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
行动:[
扁平按钮(
已按下:(){
addName();
},
子:图标(
Icons.add,
),
),
],
),
正文:世界其他地区(
mainAxisAlignment:mainAxisAlignment.space,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
扩大(
子项:列表视图(子项:[
容器(
颜色:颜色,黄色,
高度:MediaQuery.of(context).size.height,
子项:ListView.builder(
itemCount:_students.length,
itemBuilder:(上下文,索引){
返回新文本(_students[index]);
},
),
),
]),
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      title: 'Scan with',
      home: Scaffold(
        body: Test(),
      ),
    ),
  );
}

class Test extends StatefulWidget {
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  List<String> _students = [
    'Gianluca',
    'Lindsay',
    'Leah',
    'U',
    'Marco',
    'Liam',
    'Harrison',
    'Charise',
    'Ting Wei',
    'Ryan',
    'Deena',
    'Xiao Yuan',
    'Benjamin',
    'Calvin',
    'Claudia',
    'Kok Hao',
    'Michalina',
    'Ruby',
    'Rachel',
    'Nadir',
    'Dan',
    'Raaid',
    'Nadia',
    'Matilda',
    'Lloyd',
    'Arielle',
    'Jun',
    'Desmond',
    'Miah',
    'Aiden',
    'Kira',
    'Nathan',
    'Thung Thung',
    'Miki',
    'Yongyou',
    'Brogan',
    'Zai Chern',
    'Gondini',
    'Ella',
    'Germaine'
  ];
  String textData = "";
  int current = 0;
  bool init = true;

  @override
  void initState() {
    addName();
    super.initState();
  }

  addName() {
    if (init) {
      for (int i = 0; i < _students.length; i++) {
        textData += _students[i] + "   ";
      }
    } else {
      textData += _students[current] + "   ";
      if (current > _students.length) {
        current = 0;
      } else {
        current++;
      }
    }
    setState(() {});
    print(textData);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          FlatButton(
            onPressed: () {
              addName();
            },
            child: Icon(
              Icons.add,
            ),
          ),
        ],
      ),
      body: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: ListView(children: [
              Container(
                color: Colors.yellow,
                height: MediaQuery.of(context).size.height,
                child: ListView.builder(
                  itemCount: _students.length,
                  itemBuilder: (context, index) {
                    return new Text(_students[index]);
                  },
                ),
              ),
            ]),
          ),
          Expanded(
            child: ListView(
              children: [
                Container(
                  color: Colors.red,
                  child: Text(textData),
                ),
                Container(
                  color: Colors.green,
                  child: Text(textData),
                ),
                Container(
                  color: Colors.blue,
                  child: Text(textData),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
Row(
children:[
Expanded(flex: 1, child: Text('List 1'),),
Expanded(flex: 2, child: Text('List 2'),),
]
),