How to make ListWheelScrollView horizontal

后端 未结 3 1739
有刺的猬
有刺的猬 2021-01-18 04:07

I 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

3条回答
  •  温柔的废话
    2021-01-18 04:42

    Edit: I have published package based on this.

    pub.dev/packages/list_wheel_scroll_view_x

    Here's my workaround.

    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),
                );
              },
            ),
          ),
        );
      }
    }
    

提交回复
热议问题