微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

文本小部件始终保持在顶部并且在我滚动时不会消失

如何解决文本小部件始终保持在顶部并且在我滚动时不会消失

即使我向下滚动,我的文本小部件“更多”始终位于顶部,但我没有找到此问题的根源,

我已经尝试将它包装在 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?