You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flutter中实现可拖拽边角调整大小的表格

实现Flutter表格的拖拽缩放功能

预期效果

预期效果示意图

我用Flutter开发了一个表格,希望无需修改代码,直接在应用内通过拖拽表格边角(如图所示)来调整表格大小。此前找到过一个针对图片的拖拽缩放实现方案,但无法成功集成到我的表格代码中。

补充说明:我还找到过一个表格相关的问题案例,但它依赖无法使用的私有包,仅作参考。

我的表格实现代码

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget{
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}


class HomePage extends StatelessWidget{
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white, // 导航栏背景色
        ),
        body: Container(
            padding: const EdgeInsets.all(15),
            child:Table(
              border: TableBorder.all(width:1, color:Colors.black45), // 表格边框样式
              children: const [

                TableRow(
                    children: [
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("序号")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("姓名")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("地址")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("国籍")
                          )
                      )
                    ]
                ),

                TableRow(
                    children: [
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("1.")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("Krishna Karki")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("尼泊尔·加德满都")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("尼泊尔")
                          )
                      )
                    ]
                ),

                TableRow(
                    children: [
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("2.")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("John Wick")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("美国·纽约")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("美国")
                          )
                      )
                    ]
                ),

                TableRow(
                    children: [
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("3.")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("Fedrick May")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("德国·柏林")
                          )
                      ),
                      TableCell(
                          child: Padding(
                              padding: EdgeInsets.all(10),
                              child:Text("德国")
                          )
                      )
                    ]
                ),
              ],)
        )
    );
  }
}

当前效果展示

当前表格效果示意图


内容的提问来源于stack exchange,提问作者Maria Grigoryan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 05:10:33