dispatchFunction method

  1. @override
void dispatchFunction(
  1. ListViewModel viewModel,
  2. String functionName,
  3. VoltronArray array, {
  4. Promise? promise,
})
override

Implementation

@override
void dispatchFunction(
  ListViewModel viewModel,
  String functionName,
  VoltronArray array, {
  Promise? promise,
}) {
  super.dispatchFunction(viewModel, functionName, array, promise: promise);
  if (functionName == kFuncScrollToIndex) {
    // list滑动到某个item
    var yIndex = array.get<int>(1) ?? -1;
    var animated = array.get<bool>(2) ?? false;
    var duration = array.get<int>(3) ?? 0; //1.2.7 增加滚动时间 ms,animated==true时生效

    if (duration <= 100) {
      // 保证duration最小为100ms
      duration = 100;
    }
    LogUtils.d("list_scroll", "scroll to index:$yIndex");
    viewModel.scrollToIndex(yIndex, duration, animated);
  } else if (functionName == kFuncScrollToContentOffset) {
    // list滑动到某个距离
    var yOffset = array.get<double>(1) ?? array.get<int>(1)?.toDouble() ?? 0.0;
    var animated = array.get<bool>(2) ?? false;
    var duration = array.get<int>(3) ?? 0; //1.2.7 增加滚动时间 ms,animated==true时生效

    if (duration <= 100) {
      // 保证duration最小为100ms
      duration = 100;
    }

    LogUtils.d("list_scroll", "scroll to offset:$yOffset");

    viewModel.scrollToOffset(yOffset, duration, animated);
  }
}