gpt4 book ai didi

flutter - 将行固定到其他 UI 小部件顶部的 ScrollView 底部

转载 作者:行者123 更新时间:2023-12-05 02:08:54 27 4
gpt4 key购买 nike

我试图在 ScrollView 中固定一个具有文本字段输入和相邻图标按钮的 Row 容器。不幸的是,Row 将保留在底部但不在屏幕 View 中,因此用户必须向下滚动才能看到 Row 容器。如何将底部栏固定到屏幕,使其始终位于屏幕 View 的底部并位于 ScrollView 中其他对象的顶部?

栏界面:

class TextBarAtBottom extends StatelessWidget {
TextEditingController commentController = TextEditingController();

@override
Widget build(BuildContext context) {
return Row(children: [
// First child is TextInput
Expanded(
child: Container(
child: TextFormField(
autocorrect: false,
decoration: new InputDecoration(
labelText: "Some Text",
labelStyle: TextStyle(fontSize: 16.0, color: Colors.black),
fillColor: Colors.black,
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black)),
),
),
)),
// Second child is button
IconButton(
icon: Icon(Icons.send),
iconSize: 16.0,
onPressed: () {},
)
]);
}
}

屏幕用户界面:

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('App'),
),
body: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Flexible(
fit: FlexFit.loose,
child: ExpandableTheme(
data: ExpandableThemeData(
iconColor: Colors.blue,
useInkWell: true,
animationDuration: const Duration(milliseconds: 500),
tapBodyToExpand: true,
tapHeaderToExpand: true,
tapBodyToCollapse: true,
hasIcon: true,
iconPlacement: ExpandablePanelIconPlacement.right),
child: ExpandablePanel(
header: Text(widget.postData.title,
style: TextStyle(fontSize: 24)),
collapsed: Text(widget.postData.text,
style: TextStyle(fontSize: 16),
softWrap: true,
maxLines: 10,
overflow: TextOverflow.ellipsis),
expanded: Text(widget.postData.text,
style: TextStyle(fontSize: 16),
softWrap: true)))),
// Second child is spacing
SizedBox(height: 16),
// Third child is list view of Cards that are populated from the request post
Flexible(
fit: FlexFit.loose,
child: Container(
child: FutureBuilder<Map<String, String>>(
future: post,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemExtent: 128.0,
itemBuilder: (BuildContext context, int index) {
return Card(Text('$index'));
});
} else if (snapshot.hasError) {
return Flex(direction: Axis.horizontal, children: [
Expanded(
child: new Container(),
)
]);
}
return CircularProgressIndicator();
},
),
)),
// Fourth child is text bar and send button
Flexible(fit: FlexFit.loose, child: TextBarAtBottom())
]))));
}

Screenshot

最佳答案

OutPut Screenshot

检查我的代码,它的底部有文本字段,中间有 ScrollView 。

您的代码有问题您在 ScrollView 中添加文本字段,因此总是在 SingleChildScrollview 的末尾。

解决方案:使用 Expanded 小部件在列 View 中添加 SingleChildScrollView。并将您的 Textfield 作为第二个 child 添加到 Column 小部件。现在 TextField 将位于底部,其余空间将由 SingleChildScrollView 占用。

import 'package:flutter/material.dart';

class Design extends StatefulWidget {
@override
_DesignState createState() => _DesignState();
}

class _DesignState extends State<Design> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TextField at Bottom'),
),
body: Column(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
Text('Flutter'),
],
),
),
),
Row(children: [
// First child is TextInput
Expanded(
child: Container(
child: TextFormField(
autocorrect: false,
decoration: new InputDecoration(
labelText: "Some Text",
labelStyle: TextStyle(fontSize: 16.0, color: Colors.black),
fillColor: Colors.black,
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black)),
),
),
)),
// Second child is button
IconButton(
icon: Icon(Icons.send),
iconSize: 16.0,
onPressed: () {},
)
])
],
),
);
}
}

关于flutter - 将行固定到其他 UI 小部件顶部的 ScrollView 底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60426214/

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