typedef IndexBarSelectCallBack = void Function(int index, String title);
class IndexBar extends StatefulWidget {
IndexBar({
required this.dataSource,
required this.callBack
});
final List<String> dataSource;
final double _indexItemHeight = 22;
final IndexBarSelectCallBack callBack;
@override
_IndexBarState createState() => _IndexBarState();
}
调整事件处理及回调
onVerticalDragUpdate: (details) {
RenderBox box = context.findRenderObject() as RenderBox;
Offset point = box.globalToLocal(details.globalPosition);
int index = _currentIndex(point);
String title = widget.dataSource[index];
widget.callBack(index, title);
},
onTapUp: (details) {
RenderBox box = context.findRenderObject() as RenderBox;
Offset point = box.globalToLocal(details.globalPosition);
int index = _currentIndex(point);
String title = widget.dataSource[index];
widget.callBack(index, title);
},
外部传入回调
六、 Clamp 函数
在滑动偏移过大超出范围的时候会发生越界,出现下面的警告
RangeError (index): Invalid value: Not in inclusive range 0..10: 14