所以,我有两个不同的滚动小部件,即 TextField 和 ListView (ListView.builder),附加有两个不同的滚动控制器,即。 _textEditingController 和 _scrollController。
这里的基本概念是使用 Stack 和可滚动小部件创建一个类似规则线的结构并在其顶部创建一个文本字段。如何通过另一个控制器的运动/滚动操作来移动一个控制器?
Stack(
children: [
SizedBox(
height:
((lines * 15) < MediaQuery.of(context).size.height)
? MediaQuery.of(context).size.height
: (lines * 15),
child: ListView.builder(
controller: _scrollController,
itemBuilder: (context, index) => const Padding(
padding: EdgeInsets.only(top: 5, bottom: 5),
child: Divider(
color: Colors.black,
height: 30,
thickness: 1.5,
),
),
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10)
.copyWith(top: 5),
child: TextField(
style: const TextStyle(
fontFamily: "WorkSans",
fontSize: 26,
fontStyle: FontStyle.italic,
height: 1.55,
),
decoration: const InputDecoration(
border: InputBorder.none,
),
cursorColor: Colors.black,
controller: _textEditingController,
maxLines: lines,
onChanged: (value) {
/* This function adds another line if I am at the end
of the text field, thus increasing the ListView's height */
final selection = _textEditingController.selection;
if (isAtLastLine(selection)) {
setState(() {
lines++;
});
}
},
),
),
],
),
您可以在ListView.builder和shrinkWrap中使用物理来解决高度问题
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: recommendedJobsList.length,
padding: const EdgeInsets.all(0),
itemBuilder: (BuildContext context, int index) {
return your code here;
});