最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dart - How do I animate columnrow size with Flutter TableView? - Stack Overflow

programmeradmin2浏览0评论

Using the package two_dimensional_scrollables I want to expand and animate the size of a specific column when tapping on it. The code below listens to the user action to change the column size and ref.read(poolSizeControllerProvider).cellWidth(index) calculates the size for the specific column. When a column size changes, I would like to animate the size of that column. How can I achieve this? I guess I need to somehow wrap FixedTableSpanExtent(columnWidth) in an animator, or loop over the width and rebuild the whole table for each iteration but that does not feel very efficient.

  Widget build(BuildContext context) {
    final cells = widget.tableDetails.getCells();

    ref.watch(tableSizeControllerProvider);

    final cellHeight = ref.read(tableSizeControllerProvider).cellHeight;

    return SizedBox(
        height: cells.length * cellHeight,
        child: TableView.list(
          horizontalDetails: _horizontalScrollableDetails,
          verticalDetails: _verticalScrollableDetails,
          mainAxis: Axis.horizontal,
          diagonalDragBehavior: DiagonalDragBehavior.free,
          pinnedColumnCount: 2,
          pinnedRowCount: 1,
          columnBuilder: _columnBuildSpan,
          rowBuilder: _rowBuildSpan,
          cells: cells,
        ),
    );
  }

  TableSpan _columnBuildSpan(int index) {
    final columnWidth = ref.read(tableSizeControllerProvider).cellWidth(index);

    const TableSpanDecoration decoration = TableSpanDecoration();
    return TableSpan(
      backgroundDecoration: decoration,
      extent: FixedTableSpanExtent(columnWidth),
      cursor: SystemMouseCursors.click,
    );
  }

  TableSpan _rowBuildSpan(int index) {
    final columnHeight = ref.read(tableSizeControllerProvider).cellHeight;

    const TableSpanDecoration decoration = TableSpanDecoration();
    return TableSpan(
      backgroundDecoration: decoration,
      extent: FixedTableSpanExtent(columnHeight),
      cursor: SystemMouseCursors.click,
    );
  }

发布评论

评论列表(0)

  1. 暂无评论