简体   繁体   English

单击保存按钮时如何使此列可编辑并保存编辑数据?

[英]how to make this column editable and save the edit data when click on save button?

How to make this column editable and save the edit data when click on save button?单击保存按钮时如何使此列可编辑并保存编辑数据?

I have create a table like below, but I cant figure out how to make the column can be edit and can be save after edit.我已经创建了一个如下所示的表格,但我无法弄清楚如何使该列可以编辑并在编辑后保存。

I have google around still cant find any solution for this.我有谷歌仍然找不到任何解决方案。 I want to the column can be edit and be save.我希望该列可以编辑并保存。 Any resource I can refer to make it work?我可以参考任何资源使其工作吗? Thanks谢谢

在此处输入图像描述

class _TableExample extends State<ggwp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text('Flutter Table Example'),
          ),
          body: Center(
              child: Column(children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 10),
              child: Table(
                defaultColumnWidth: FixedColumnWidth(126.0),
                border: TableBorder.all(
                    color: Colors.black, style: BorderStyle.solid, width: 2),
                children: [
                  TableRow(
                    children: [
                      Container(
                        padding: EdgeInsets.only(top: 15),
                        height: 50,
                        color: Colors.cyan,
                        child: Column(children: [
                          Text(
                            'Selection No',
                            style: TextStyle(fontSize: 20),
                          )
                        ]),
                      ),
                      TableCell(
                        verticalAlignment: TableCellVerticalAlignment.fill,
                        child: Container(
                          color: Colors.white,
                          child: Container(
                            padding: EdgeInsets.only(top: 15),
                            color: Colors.white,
                            child: Column(children: [
                              Text(
                                '001',
                                style: TextStyle(fontSize: 20),
                              )
                            ]),
                          ),
                        ),
                      ),
                      Container(
                        height: 50,
                        color: Colors.white,
                        child: Container(
                          padding: EdgeInsets.only(top: 15),
                          color: Colors.white,
                          child: Column(children: [
                            Text(
                              '002',
                              style: TextStyle(fontSize: 20),
                            )
                          ]),
                        ),
                      ),
                    ],
                  ),
                  TableRow(
                    children: [
                      Container(
                        padding: EdgeInsets.only(top: 15),
                        height: 50,
                        color: Colors.cyan,
                        child: Column(children: [
                          Text(
                            'Price',
                            style: TextStyle(fontSize: 20),
                          )
                        ]),
                      ),
                      TableCell(
                        verticalAlignment: TableCellVerticalAlignment.fill,
                        child: Container(
                          padding: EdgeInsets.only(top: 15),
                          color: Colors.white,
                          child: Column(children: [
                            Text(
                              '5.5',
                              style: TextStyle(fontSize: 20),
                            )
                          ]),
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.only(top: 15),
                        height: 50,
                        color: Colors.white,
                        child: Column(children: [
                          Text(
                            '6.9',
                            style: TextStyle(fontSize: 20),
                          )
                        ]),
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              child: ElevatedButton(
                onPressed: () {
                  // Code to execute when the button is pressed
                },
                child: Text('Save'),
              ),
            )
          ]))),
    );
  }
}

You can replace those text widget that you want to make editable with TextField .您可以用TextField替换您想要编辑的那些text小部件。 First define TextEditingController with default value like this:首先用这样的默认值定义TextEditingController

TextEditingController priceOneController = TextEditingController(text: '5.5');
TextEditingController priceTwoController = TextEditingController(text: '6.9');

then use them like this:然后像这样使用它们:

TableRow(
    children: [
      Container(
        padding: EdgeInsets.only(top: 15),
        height: 50,
        color: Colors.cyan,
        child: Column(children: [
          Text(
             'Price',
              style: TextStyle(fontSize: 20),
          )
        ]),
      ),
      TableCell(
        verticalAlignment: TableCellVerticalAlignment.fill,
        child: Container(
          padding: EdgeInsets.only(top: 15),
          color: Colors.white,
          child: Column(children: [
            TextField(
               controller: priceOneController,
               InputDecoration(border: InputBorder.none),
               style:  TextStyle(fontSize: 20),
            ),
          ]),
        ),
      ),
      Container(
        padding: EdgeInsets.only(top: 15),
        height: 50,
        color: Colors.white,
        child: Column(children: [
          TextField(
             controller: priceTwoController,
             InputDecoration(border: InputBorder.none),
             style:  TextStyle(fontSize: 20),
          ),
        ]),
      ),
    ],
  ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM