小编Gab*_*iel的帖子

Flutter - 键盘高度的媒体查询始终返回零

我正在尝试从屏幕的高度中减去键盘的高度,以便我可以将该值应用于我的 listview 容器的 height 属性。这样我的键盘就不会与我的列表视图重叠。

double sheetHeight;
double keyboardHeight;
Run Code Online (Sandbox Code Playgroud)

我使用 MediaQuery,它为屏幕高度返回 683,但始终为键盘高度返回 0。

sheetHeight = MediaQuery.of(context).size.height;
keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
Run Code Online (Sandbox Code Playgroud)

这总是使我的列表视图覆盖整个屏幕,与我想要的相反。为什么 MediaQuery.of(context).viewInsets.bottom 总是返回 0?我认为这可能与上下文有关,但我不确定。还值得注意的是,当键盘最初出现时,我的断点没有被触发。我认为这也是问题的一部分。非常感谢任何输入或资源。

return Card(
  child: Container(
  height: sheetHeight - keyboardHeight,
Run Code Online (Sandbox Code Playgroud)

为了确定键盘是否可见,我使用了一个 keyboard_visibility 包。如果键盘可见,我使用 MediaQuery 设置高度。如果没有,我将它设置为 0。虽然它返回 true,但键盘高度仍然保持值为 0。这是错误的方法吗?

super.initState();
WidgetsBinding.instance.addObserver(this);
KeyboardVisibilityNotification().addNewListener(
  onChange: (bool visible) {
    print(visible);
    if (visible == true) {
      keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
    } else {
      keyboardHeight = 0.0;
    }
  }
);
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout

5
推荐指数
1
解决办法
3765
查看次数

C++ Square Root Function Bug

我有一个c ++算法,可以计算整数的平方根.除了一个缺陷外,该程序可以正常运行.它无法计算低于1的数字的平方根.例如,它无法计算.5或.9或.0000001等的平方根,但在所有其他情况下按计划工作.我有X设置所以它不允许负输入,但我仍然不明白为什么它不会返回任何小于1的值.

include <iostream>
#include <cmath>
#include <cassert>

using namespace std;

double squareroot(double x)

{ /* computes the square root of x */

  /* make sure x is not negative .. no math crimes allowed! */
    assert(x >= 0);
    if (x == 0) return 0;

    /* the sqrt must be between xhi and xlo */
    double xhi = x;
    double xlo = 0;
    double guess = x / 2;

    /* We stop when guess*guess-x is very small */

    while (abs(guess*guess …
Run Code Online (Sandbox Code Playgroud)

c++ square-root

2
推荐指数
1
解决办法
682
查看次数

Dart:根据另一个列表过滤一个列表

我有两个看起来像这样的对象:

class Field extends RESTModel {
  int id;
  String name;
  String dataType;
  int objectId;
}

class FieldKeywordMap extends RESTModel {
  int id;
  String keywordName;
  int objectConfigurationId;
  int fieldId;
}
Run Code Online (Sandbox Code Playgroud)

我有一个名为 _fieldKeywordMaps 的 FieldKeywordMap 列表和一个名为 _selectedFields 的字段列表。我正在编写一个函数来根据两个条件返回 _fieldKeywordMaps 的过滤版本:

  1. 其中 objectConfigurationId 等于 selectedObjectConfiguration().id
  2. 其中 fieldId 等于 _selectedFields 中项目的 id。

基于第一个条件的过滤有效,但我无法确定如何迭代我的 _selectedFields 列表并将其与 _fieldKeywordMaps 中的对象进行比较。这是代码:

    selectObjectKeywordMaps() async {
    if (selectedObjectConfiguration() != null && selectedObject() != null) {
      List<FieldKeywordMap> _maps = _fieldKeywordMaps
          .where((keywordMap) =>
              keywordMap.objectConfigurationId == selectedObjectConfiguration().id)
          .where((filteredKeywordMap) =>
              _selectedFields.map((field) => field.id).contains(filteredKeywordMap.id))
          .toList(); …
Run Code Online (Sandbox Code Playgroud)

dart flutter

2
推荐指数
1
解决办法
3571
查看次数

标签 统计

dart ×2

flutter ×2

c++ ×1

flutter-layout ×1

square-root ×1