【问题标题】:How to show more element of number picker list in flutter?如何在颤动中显示更多数字选择器列表的元素?
【发布时间】:2019-06-23 10:45:28
【问题描述】:

我使用this 为我的颤振应用程序开发了一个数字选择器,但它仅显示数字选择器中数字列表的三个元素。我想显示更多元素(例如 7),此外,我希望所选元素恰好是中间元素(在我的情况下是 3 个元素之前和 3 个之后)应该更改库代码的哪一部分?

当只是更改“_listViewHeight = 3 * itemExtent”时,在库中我们会看到我在下图中提到的问题。首先选中的Item不是最大值旁边的中间那个是不能选中的。

【问题讨论】:

    标签: flutter dart numberpicker


    【解决方案1】:

    我遇到了同样的问题,并且在深入研究 numberpicker 代码并进行一些更改后,能够让它在 3 或更大的奇数显示数字长度下工作。 Here is a diff of the changes I made。这适用于我使用我的repo。您也可以将我的仓库中的 lib/numberpicker.dart 文件复制到您的项目中并包含该文件。希望能在某个时候将其引入 numberpicker 项目。以下是我一次显示 7 个数字的示例:

    NumberPicker.horizontal(
        initialValue: _currentValue,
        minValue: 1,
        maxValue: 10,
        numberToDisplay: 7,
        onChanged: (newValue) =>
            setState(() => _currentValue = newValue));
    

    并滚动到第一个数字

    您可以为 numberToDisplay 参数选择不同的奇数,例如 5

    删除参数将使用默认值 3。

    更多信息here

    【讨论】:

      【解决方案2】:

      herehere

      改变

        _listViewHeight = 3 * itemExtent,
      

        _listViewHeight =  noOfElements * itemExtent,
      

      其中noOfElements 是您要显示的元素数。

      【讨论】:

      • 我知道这一点,但所选项目仍然是第二个,而不是显示列表的中间...
      猜你喜欢
      • 1970-01-01
      • 2020-08-15
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多