Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么不允许rows更改,当我修改rows的内容,无论如何TForm都不会重新更新内部的rows变量 #12

Open
cn1001wang opened this issue Apr 27, 2021 · 1 comment

Comments

@cn1001wang
Copy link

cn1001wang commented Apr 27, 2021

问题如题,你的reload方法也只是刷新第一次传入的rows变量,你没有在改变的时候重新修改rows变量。
这样的话,比如我有一个需求是当A行改变时候会,将B,C行的value也改变;这样的需求将无法实现。
最后,这是你最初设计时的预想吗,求解惑!

import 'package:flutter/material.dart';
import 'package:tform/tform.dart';

class PartForm {
  String partNum;
  String partSpecification;
  String weight;
  PartForm({this.partNum, this.partSpecification, this.weight});
}

class TabResourcePage extends StatefulWidget {
  const TabResourcePage({Key key}) : super(key: key);

  @override
  _TabResourcePageState createState() => _TabResourcePageState();
}

class _TabResourcePageState extends State<TabResourcePage> {
  final GlobalKey _formKey = GlobalKey<TFormState>();

  var form = PartForm(partNum: "1", partSpecification: "2*2", weight: "100");
  var options = ["10", '2'];

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Text("form.partSpecification:${form.partSpecification}"),
            TextButton(
                onPressed: () {
                  setState(() {
                    form.partSpecification = "";
                  });
                },
                child: Text("clear")),
            TextButton(
                onPressed: () {
                  setState(() {
                    form.partSpecification += "123";
                  });
                },
                child: Text("add")),
            Expanded(
              child: TForm.builder(
                key: _formKey,
                rows: [
                  TFormRow.input(
                    title: "规格123",
                    placeholder: "规格",
                    value: form.partSpecification,
                    textAlign: TextAlign.right,
                    onChanged: (TFormRow row) {},
                  ),
                  // 我把这两列放开注释,hot Reload也不会将组件刷新
                  // TFormRow.input(
                  //   title: "数量",
                  //   placeholder: "数量",
                 //    value: form.partNum,
                 //    textAlign: TextAlign.right,
                 //    onChanged: (TFormRow row) {},
                 //  ),
                  // TFormRow.input(
                  //   title: "重量",
                  //   placeholder: "重量",
                  //   value: form.weight,
                  //   textAlign: TextAlign.right,
                  //   onChanged: (TFormRow row) {},
                  // ),
                ],
                divider: Divider(
                  height: .5,
                  thickness: .5,
                ),
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: IconButton(
        onPressed: () {
          setState(() {
            form.partSpecification += "refresh";
            print(form.partSpecification);
            // TForm.of(context).reload();
            (_formKey.currentState as TFormState).reload();
          });
        },
        icon: Icon(Icons.refresh),
      ),
    );
  }
}
@cn1001wang
Copy link
Author

你的源码我已经看过了,本来可以直接使用widget.rows。是不是因为你要满足动态表单,直接使用widget.rows有什么bug吗?用insert和delete不太响应式啊,和用户的直觉不太一样。
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant