gpt4 book ai didi

flutter - SingleChildScrollView不可滚动

转载 作者:行者123 更新时间:2023-12-03 13:30:38 33 4
gpt4 key购买 nike

此小部件呈现不可滚动的外观,但不可滚动

SingleChildScrollView(
child: Column(
children: <Widget>[
ListView(
shrinkWrap: true,
children: <Widget>[
ListTile(
title: Row(
children: const <Widget>[
Expanded(child: Text('text'),),
Expanded(child: Text('text'),),
],
),
),
],
),
RapportList(), // this is not scrollable
],
),
),

其中 RapportList()是一个有状态的小部件,可构建一个
ListView.builder(
shrinkWrap: true,
itemCount: _rapports.length,
itemBuilder: (context, index) {
return ListTile(
title: Row(
children: <Widget>[
...

我试图用 ListView.builder包装 SingleChildScrollView,但是没有结果。它仍然是不可滚动的。

最佳答案

我想你只需要添加
physics: const NeverScrollableScrollPhysics(),
到您的RapportList()。

这是我测试过的代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
ListView(
shrinkWrap: true,
children: <Widget>[
ListTile(
title: Row(
children: const <Widget>[
Expanded(child: Text('text'),),
Expanded(child: Text('text'),),
],
),
),
],
),
ListView.builder( //<--RapportList().
physics: const NeverScrollableScrollPhysics(), //<--here
shrinkWrap: true,
itemCount: 100,
itemBuilder: (context, index){
return ListTile(
title: Row(
children: <Widget>[
Text("ListTile with index ${index}")
],
),
);
},
),
],
),
),
);
}
}

这样,RapportList()将无法滚动,并且当您尝试“滚动”其元素之一时,将滚动整个SingleChildScrollView();)

enter image description here

关于flutter - SingleChildScrollView不可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59510116/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com