在“堆栈”>“不透明度”>“可滚动”下换行时出现颤动键盘问题

2024-01-01

在 flutter 应用程序中,当输入字段包含在 Scrollable、Opacity、Stack 中时,当键盘出现时,可滚动视图未正确放置。

当键盘出现时如何正确地使可滚动视图?

如果输入字段没有包含在 Scrollable 中,则键盘根本不会出现。可以通过改变来测试ListView与以下代码中的 Column 。

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class SecurePage extends StatelessWidget {
  final int index;

  SecurePage(this.index);

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Secure'),
      ),
      body: new Column(
        children: <Widget>[
          new Text('No $index'),
          new IconButton(
            icon: new Icon(Icons.verified_user),
            onPressed: () {
              Navigator.of(context).push(
                new MaterialPageRoute(
                  builder: (BuildContext context) {
                    return new VerifiedPage(index + 1);
                  },
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

class VerifiedPage extends StatelessWidget {
  final int index;

  VerifiedPage(this.index);

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Verity'),
      ),
      body: new ListView(
        children: <Widget>[
          new Text('No $index'),
          new Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: new TextField(
              autofocus: index % 2 == 1,
              decoration: const InputDecoration(
                hintText: 'Search',
              ),
            ),
          ),
          new IconButton(
            icon: new Icon(Icons.security),
            onPressed: () {
              Navigator.of(context).push(
                new MaterialPageRoute(
                  builder: (BuildContext context) {
                    return new SecurePage(index + 1);
                  },
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  int _page = 0;
  List<Widget> initialWidgets = <Widget>[
    new SecurePage(0),
    new VerifiedPage(0),
  ];

  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Stack(
        children: new List<Widget>.generate(initialWidgets.length, (int index) {
          return new IgnorePointer(
            ignoring: index != _page,
            child: new Opacity(
              opacity: _page == index ? 1.0 : 0.0,
              child: new Navigator(
                onGenerateRoute: (RouteSettings settings) {
                  return new MaterialPageRoute(
                    builder: (_) => initialWidgets[index],
                  );
                },
              ),
            ),
          );
        }),
      ),
      bottomNavigationBar: new BottomNavigationBar(
        currentIndex: _page,
        onTap: (int index) {
          setState(() {
            _page = index;
          });
        },
        items: <BottomNavigationBarItem>[
          new BottomNavigationBarItem(
            icon: new Icon(Icons.security),
            title: new Text('Secure'),
          ),
          new BottomNavigationBarItem(
            icon: new Icon(Icons.verified_user),
            title: new Text('Verified'),
          ),
        ],
      ),
    );
  }
}

问题是你正在嵌套一个Scaffold里面一个Scaffold每个脚手架都在尝试为键盘添加填充。你应该只使用一个Scaffold一次。而不是有内在的Scaffold,考虑使用Column定位你的AppBar在屏幕顶部。

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class SecurePage extends StatelessWidget {
  final int index;

  SecurePage(this.index);

  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new AppBar(
          title: new Text('Secure'),
        ),
        new Text('No $index'),
        new IconButton(
          icon: new Icon(Icons.verified_user),
          onPressed: () {
            Navigator.of(context).push(
              new MaterialPageRoute(
                builder: (BuildContext context) {
                  return new VerifiedPage(index + 1);
                },
              ),
            );
          },
        ),
      ],
    );
  }
}

class VerifiedPage extends StatelessWidget {
  final int index;

  VerifiedPage(this.index);

  Widget build(BuildContext context) {
    return new Column(
      children: <Widget>[
        new AppBar(
          title: new Text('Verity'),
        ),
        new Text('No $index'),
        new Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: new TextField(
            autofocus: index % 2 == 1,
            decoration: const InputDecoration(
              hintText: 'Search',
            ),
          ),
        ),
        new IconButton(
          icon: new Icon(Icons.security),
          onPressed: () {
            Navigator.of(context).push(
              new MaterialPageRoute(
                builder: (BuildContext context) {
                  return new SecurePage(index + 1);
                },
              ),
            );
          },
        ),
      ],
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  int _page = 0;
  List<Widget> initialWidgets = <Widget>[
    new SecurePage(0),
    new VerifiedPage(0),
  ];

  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Stack(
        children: new List<Widget>.generate(initialWidgets.length, (int index) {
          return new IgnorePointer(
            ignoring: index != _page,
            child: new Opacity(
              opacity: _page == index ? 1.0 : 0.0,
              child: new Navigator(
                onGenerateRoute: (RouteSettings settings) {
                  return new MaterialPageRoute(
                    builder: (_) => initialWidgets[index],
                  );
                },
              ),
            ),
          );
        }),
      ),
      bottomNavigationBar: new BottomNavigationBar(
        currentIndex: _page,
        onTap: (int index) {
          setState(() {
            _page = index;
          });
        },
        items: <BottomNavigationBarItem>[
          new BottomNavigationBarItem(
            icon: new Icon(Icons.security),
            title: new Text('Secure'),
          ),
          new BottomNavigationBarItem(
            icon: new Icon(Icons.verified_user),
            title: new Text('Verified'),
          ),
        ],
      ),
    );
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在“堆栈”>“不透明度”>“可滚动”下换行时出现颤动键盘问题 的相关文章

随机推荐

  • 如何获取 rq 队列中的作业数量?

    我用过rq http python rq org 和 RedisToGo 如何获取队列中的作业数量 我在文档中找不到它 Python 当我尝试时 print Before len q jobs result q enqueue worker
  • 如何备份SVN仓库? [复制]

    这个问题在这里已经有答案了 我经常听说拥有 SVN 存储库并不能消除备份的需要 这样的备份是如何完成的呢 我的意思是存储库会随着时间的推移而膨胀 不是吗 那么我是否每次都将其作为一个整体进行备份 或者我该怎么做 进行此类备份的最简单方法是什
  • 德墨忒尔定律 - 数据对象

    我试图遵循德米特法则 参见http en wikipedia org wiki Law of Demeter http en wikipedia org wiki Law of Demeter http misko hevery com c
  • Google Maps Javascript API 不响应 iOS 10 中的触摸事件

    我运行一个内置了许多自定义 Google 地图的网站 在搜索或生成往返某个位置的路线后在地图上显示各个位置 我为此使用 Google Maps Javascript API 我的用户开始报告说 在 iOS 10 上 这些地图不再响应触摸事件
  • 表字段中未显示验证图标

    当我进入表格的编辑模式时 我希望在用户超出任何验证约束范围时立即显示数据验证感叹号图标 首先 有几点注意事项 我使用的是 Vaadin 7 所以 Bean Validation 插件很遗憾无法工作 数据验证按预期进行 现在 我有一个完美的工
  • 是否可以在node.js的帮助下在Windows中将JSLint作为命令行运行?

    我的意思是像这样运行它 node exe lint js my js file js 然后将输出输出到控制台 我需要下载什么 我只需要保存吗http www jslint com 到磁盘 然后获取一些附加的 js 文件 或者我需要寻找 no
  • 如何将触摸从 UIView 传递到 UIScrollView

    如同这个线程 https stackoverflow com questions 5186479 passing swipe touches from uiview to underlying uiscrollview for proper
  • 构建 GDAL 时链接器错误

    我正在使用 MSVC 2015 64 位命令提示符从源代码构建 GDAL 我使用的是 Windows 8 在构建过程中 我收到以下错误 Creating library gdal i lib and object gdal i exp od
  • 如何让 Swagger UI 与 Swashbuckle 一起使用端口 443?

    在运行 RESTful Web 服务的 QA 和 Prod 环境中 端口 80 未开放 因此 目前当我尝试在 QA 中访问 Swagger UI 时 我收到此消息 但它只是挂起 fetching resource list http qa
  • JSon.NET 反序列化子项

    对于反序列化 我通常使用与 JSon 和中找到的属性名称相同的对象JsonConvert DeserializeObject
  • AngularJS工厂http返回空

    我是第一次尝试 AngularJS 我正在使用工厂从 http get 请求获取 JSON 数据 但在 ajax 请求完成之前 该对象返回为空 Factory myDemo factory photosFactory function ht
  • AWS API网关代理响应失败/丢弃

    Problem 使用 Postman 时 AWS API Gateway 代理不会传回我的后端服务的响应 但适用于curl 描述 我有一个想要通过 AWS API 网关公开的后端服务 在这种情况下 网关的使用纯粹是作为 HTTP 代理 所以
  • 是否可以在 gridview 的单元格中滚动?

    我的网格视图中有一些记录 但每条记录都存在一个问题 有一个单元格包含大量数据 我仍然想显示数据并允许用户向下滚动阅读 如果他们感兴趣 是否有可能允许在该单元格中滚动 EDIT 这是我参考的css AspNet GridView overfl
  • 为什么 -drawRect 比使用 CALayers/UIViews 用于 UITableViews 更快?

    我已经能听到一千名 iOS 开发者内心的痛苦 不 我不是菜鸟 为什么 UITableView 的 drawRect 性能比多个视图更快 据我所知 合成操作是在 GPU 上进行的 但合成是一种一次性操作 一旦这些层被提交到内存中 它就与缓存缓
  • 在 ASP.Net Ajax Async-Postback without JQuery 之后滚动到页面顶部

    我需要在更新面板中的异步回发后滚动到页面顶部 我尝试了几种方法 虽然它们都滚动到页面顶部 但它们都被 ASP Net Ajax 覆盖 从而将页面返回到发生回发时的位置 我已经在页面指令中设置MaintainScrollPositionOnP
  • 重用Android锁定模式

    我正在编写一个应用程序 应该用密码保护它 是否可以从具有不同图案的应用程序中使用 Android 的图案锁屏 而不是构建一个新的锁屏 首先 您必须通过手动设置来设置图案锁定 然后您可以使用下面的代码接收事件 import android a
  • 在 NodeJS 中创建可以处理多个安全域的反向代理

    我正在尝试在 NodeJS 中创建反向代理 但我一直遇到这样的问题 即使我想为多个域提供服务 我也只能在同一端口 443 上提供一组证书 密钥对 我已经完成了研究并不断遇到同样的障碍 可以从非安全本地源 http 本地访问和服务 https
  • 点加速最快路径

    这只是我自己想出的东西 但这似乎是一个有趣的问题 它让我难住了 您在二维空间中有一组点 其中一个点指定为 起点 一个点指定为 终点 每个点都有坐标 以米为单位距原点 但也有一个 加速度数 以米 秒的 delta V 为单位 到达某个点 包括
  • 如何在不使用 ZipArchive 的情况下在 Windows 8 Metro 中解压缩 ZIP 文件 (zlib.net)

    我有一个用 C 编写的 Windows 8 Metro 应用程序 我需要打开一个 ZIP 文件并读取其中包含的 XML 文件 我使用了 ZipArchive 类 但它在当前版本中出现了错误 并且不再起作用 还有别的办法吗 我尝试用谷歌搜索其
  • 在“堆栈”>“不透明度”>“可滚动”下换行时出现颤动键盘问题

    在 flutter 应用程序中 当输入字段包含在 Scrollable Opacity Stack 中时 当键盘出现时 可滚动视图未正确放置 当键盘出现时如何正确地使可滚动视图 如果输入字段没有包含在 Scrollable 中 则键盘根本不