如何解决文本小部件始终保持在顶部并且在我滚动时不会消失
即使我向下滚动,我的文本小部件“更多”始终位于顶部,但我没有找到此问题的根源,
我已经尝试将它包装在 SingleChildScrollView 小部件中,但仍然没有任何变化,Text 小部件是否有任何参数允许它在我不知道的用户滚动时滚动?或者完全是别的什么?
代码:
class MorePage extends StatefulWidget {
@override
_MorePageState createState() => _MorePageState();
}
class _MorePageState extends State<MorePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: white,body: Stack(
// YESSSS
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,children: [
SizedBox(height: 45.0),Padding(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),child: SizedBox(
height: 25,child: Text(
"MORE",style: TextStyle(
color: black,fontFamily: "Raleway",fontWeight: FontWeight.w700,fontSize: 25),textAlign: TextAlign.center,),]),Container(
// YESSSS
child: getBody(),],);
}
解决方法
您正在使用 Stack(),Stack 会将子项叠加在其他子项之上。
,在使用 Stack
包裹固定大小的小部件时,它可以只是 Container()
,在使用堆栈时,使用对齐小部件作为子部件 => Center
,Align
,Positioned
,否则使用堆栈 fit
属性,
要了解有关 Stack
的更多信息,请访问 https://api.flutter.dev/flutter/widgets/Stack-class.html
import 'package:flutter/material.dart';
class MorePage extends StatefulWidget {
@override
_MorePageState createState() => _MorePageState();
}
class _MorePageState extends State<MorePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,body: SingleChildScrollView(
child: Container(
child: Stack(
// YESSSS
children: <Widget>[
Row(mainAxisAlignment: MainAxisAlignment.center,children: [
SizedBox(height: 45.0),Padding(
padding: const EdgeInsets.symmetric(horizontal: 22),child: SizedBox(
height: 25,child: Text(
"MORE",style: TextStyle(
color: Colors.black,fontFamily: "Raleway",fontWeight: FontWeight.w700,fontSize: 25),textAlign: TextAlign.center,),]),Center(
child: Container(
color: Colors.amber,// YESSSS
height: 1333,child: Text("Body")
// getBody(),],);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。