【问题标题】:Flutter: ListWheelScrollView magnifier not working颤振:ListWheelScrollView 放大镜不起作用
【发布时间】:2020-12-12 04:47:42
【问题描述】:

ListWheelScrollView 的放大镜是空的(只是一个白色的容器)

ListWheelScrollView(
  itemExtent: 60,
  magnification: 2,
  useMagnifier: true,
  children: List.generate(
     100,
      (index) => Card(
          key: ValueKey(index),
          color: Colors.blue,
          child: ListTile(
            title: Text(index.toString()),
          ))).toList(),
),

我做错了什么? (运行flutter run -vflutter doctor -v没有发现任何问题)

【问题讨论】:

    标签: android flutter listview dart


    【解决方案1】:
    1. 您可以使用Container 代替Card 并为其设置水平padding
    ListWheelScrollView(
      itemExtent: 60,
      magnification: 1.5,
      useMagnifier: true,
      squeeze: 0.7,
      children: List.generate(
        100,
        (index) => Container(
          key: ValueKey(index),
          padding: EdgeInsets.symmetric(horizontal: 100),
          decoration: BoxDecoration(
            color: Colors.blue,
            borderRadius: BorderRadius.circular(8),
          ),
          child: ListTile(
            title: Text(index.toString()),
          ),
        )).toList(),
    ),
    

    结果:

    1. 除了使用ListTile 和水平padding,您可以将文本放在Center 小部件内,该小部件直接放在Container 内:
    ListWheelScrollView(
      itemExtent: 60,
      magnification: 1.5,
      useMagnifier: true,
      squeeze: 0.7,
      children: List.generate(
        100,
        (index) => Container(
          key: ValueKey(index),
          decoration: BoxDecoration(
            color: Colors.blue,
            borderRadius: BorderRadius.circular(8),
          ),
          child: Center(
            child: Text(index.toString()),
          ),
        )).toList(),
    ),
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 2018-11-17
      • 2021-02-20
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      相关资源
      最近更新 更多