This widget renders with no errors except it is not scrollable
SingleChildScrollView(
child: Column(
children: [
ListView(
shrinkWrap: true,
children: [
ListTile(
title: Row(
children: const [
Expanded(child: Text('text'),),
Expanded(child: Text('text'),),
],
),
),
],
),
RapportList(), // this is not scrollable
],
),
),
Where RapportList()
is a statefull widget which builds a
ListView.builder(
shrinkWrap: true,
itemCount: _rapports.length,
itemBuilder: (context, index) {
return ListTile(
title: Row(
children: <Widget>[
...
I tried to wrap the ListView.builder
with SingleChildScrollView
but with no result. It is still not scrollable.
I think you just need to add
physics: const NeverScrollableScrollPhysics(),
to your RapportList().
Here is the code I tested:
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}")
],
),
);
},
),
],
),
),
);
}
}
In this way, RapportList() will not be scrollable and when you try to 'scroll' one of its element, you will scroll the entire SingleChildScrollView() ;)
用Expanded小部件包装SingleChildScrollView
@override Widget build(BuildContext context) { // TODO: implement build return Scaffold(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'),), ], ), ), ], ), SizedBox(height: 6000,), Text("...."), Container( ), ], ), ) ); } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.