Jas*_*des 12
编辑:我已经基于此发布了包。
pub.dev/packages/list_wheel_scroll_view_x
这是我的解决方法。
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),
);
},
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
mah*_*mnj 12
这并不是一个真正的解决方案,而是一个天真的黑客,您可以使用内置的 ListWheelScrollView 通过将其与RotatedBox.
RotatedBox(
quarterTurns: -1,
child: ListWheelScrollView(
controller: _scrollController,
itemExtent: itemWidth,
onSelectedItemChanged: (newIndex) {
setState(() {
selectedIndex = newIndex;
});
},
children: List.generate(
itemCount,
(index) => RotatedBox(
quarterTurns: 1,
child: AnimatedContainer(
duration: Duration(milliseconds: 400),
width: index == selectedIndex ? 60 : 50,
height: index == selectedIndex ? 60 : 50,
alignment: Alignment.center,
decoration: BoxDecoration(
color: index == selectedIndex ? Colors.red : Colors.grey,
shape: BoxShape.circle,
),
child: Text('$index'),
),
),
),
),
);
Run Code Online (Sandbox Code Playgroud)
我建议使用此方法,直到此问题得到解决
| 归档时间: |
|
| 查看次数: |
4309 次 |
| 最近记录: |