如何使ListWheelScrollView水平 [英] How to make ListWheelScrollView horizontal

查看:421
本文介绍了如何使ListWheelScrollView水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用水平的ListView窗口小部件来放大中心项目。我尝试使用普通的ListView,但无法放大中心项目。然后,在搜索文档时,我遇到了ListWheelScrollView,但不幸的是,它似乎不支持水平子级布局。因此,基本上我希望创建一个具有中心项目放大倍数的水平ListView。如果有人能至少指出我正确的方向,我将不胜感激。谢谢

Am trying to have a horizontal ListView Widget that magnifies the center items. I tried using the normal ListView but i couldn't get the center items to magnify. Then while searching the flutter docs I came across ListWheelScrollView but unfortunately it dosen't seem to support horizontal children layout. So basically am looking to create a horizontal ListView with center items magnification. I'd appreciate if anyone can at least point me in the right direction. Thanks

推荐答案

这是我的解决方法。

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class ListWheelScrollViewX extends StatelessWidget {
  final Widget Function(BuildContext, int) builder;
  final Axis scrollDirection;
  final FixedExtentScrollController controller;
  final double itemExtent;
  final double diameterRatio;
  final void Function(int) onSelectedItemChanged;
  const ListWheelScrollViewX({
    Key key,
    @required this.builder,
    @required this.itemExtent,
    this.controller,
    this.onSelectedItemChanged,
    this.scrollDirection = Axis.vertical,
    this.diameterRatio = 100000,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RotatedBox(
      quarterTurns: scrollDirection == Axis.horizontal ? 3 : 0,
      child: ListWheelScrollView.useDelegate(
        onSelectedItemChanged: onSelectedItemChanged,
        controller: controller,
        itemExtent: itemExtent,
        diameterRatio: diameterRatio,
        physics: FixedExtentScrollPhysics(),
        childDelegate: ListWheelChildBuilderDelegate(
          builder: (context, index) {
            return RotatedBox(
              quarterTurns: scrollDirection == Axis.horizontal ? 1 : 0,
              child: builder(context, index),
            );
          },
        ),
      ),
    );
  }
}

这篇关于如何使ListWheelScrollView水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆