颤振:ListWheelScrollView放大镜不起作用

时间:2020-08-23 10:28:56

标签: android flutter listview dart

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未发现任何问题时显示错误)

enter image description here

1 个答案:

答案 0 :(得分:2)

  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(),
),

结果:

res

  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(),
),

结果:

res2