首页 > 解决方案 > 颤振:ListWheelScrollView 放大镜不起作用

问题描述

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 -v并且flutter doctor -v没有发现问题)

在此处输入图像描述

标签: androidflutterlistviewdart

解决方案


  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和水平:paddingCenterContainer
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(),
),

结果:

资源2


推荐阅读