Данные обновления поля текстовой формы Flutter, если они были изменены, если обновлять данные иначе на основе начального значения - PullRequest
0 голосов
/ 06 мая 2020

У меня треплет форма обновления данных. Я создал поле текстовой формы для требуемых данных, в котором начальное значение каждого поля установлено на значение, уже сохраненное в хранилище огня. Мой код не показывает ошибок и обновляет данные. Но если нет необходимости редактировать конкретное поле, я не меняю его, тогда для поля устанавливается значение null, мне нужно, чтобы это не менялось и имело то же значение, что и предыдущее. Мой код следующий.

 @override
  Widget build(BuildContext context) {
    return Scaffold(
        drawer: newdrawer(),
        appBar: AppBar(
          title: Text('Edit Task'),
        ),
        body: SingleChildScrollView(
          child: ConstrainedBox(
            constraints: BoxConstraints(),
            child: Center(
              child: Column(
                // mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  TextFormField(
                    decoration: InputDecoration(
                    labelText: 'Title',
                    ),
                    initialValue: widget.postid.data['Title'],
                    onChanged: (value){
                      this.Title=value;
                    },

                  ),
                  SizedBox(height: 5.0),
                  Container(
                    height: maxLines * 24.0,
                    child: TextFormField(
                      maxLines: maxLines,
                      decoration: InputDecoration(
                        hintText: 'Enter Summary',
                        contentPadding: new EdgeInsets.symmetric(
                            vertical: 25.0, horizontal: 10.0),
                      ),
                      initialValue: widget.postid.data['Summary'],
                      onChanged: (value) {
                        this.Summary = value;
                      },
                    ),
                  ),
                  SizedBox(height: 5.0),
                  SizedBox(height: 5.0),
                  TextFormField(
                    decoration: InputDecoration(
                      hintText: 'Task to be given to',
                      contentPadding: new EdgeInsets.symmetric(
                          vertical: 25.0, horizontal: 10.0),
                    ),
                    initialValue: widget.postid.data['Taskgivento'],
                    //TODO: use tagging system or search when typed system
                    onChanged: (value) {
                      this.Taskgivento = value;
                    },
                  ),
                  SizedBox(height: 5.0),
                  TextFormField(
                    decoration: InputDecoration(
                      hintText: 'Status',
                      contentPadding: new EdgeInsets.symmetric(
                          vertical: 25.0, horizontal: 10.0),
                    ),
                    initialValue: widget.postid.data['Status'],
                    onChanged: (value) {
                      this.Status = value;
                    },
                  ),
                  DateTimeField(
                    format: dateformat,
                    onShowPicker: (context, currentValue) {
                      return showDatePicker(
                          context: context,
                          firstDate: DateTime(1900),
                          initialDate: currentValue ?? DateTime.now(),
                          lastDate: DateTime(2100));
                    },
                    decoration: InputDecoration(
                      hintText: 'Enter Date to be completed',
                      contentPadding: new EdgeInsets.symmetric(
                          vertical: 25.0, horizontal: 10.0),
                    ),
                    initialValue: widget.postid.data['Completion'].toDate(),
                    onChanged: (value) {
                      this.Completion = value;
                    },
                  ),
                  SizedBox(height: 25.0),
                  SizedBox(
                    width: 90.0,
                    height: 50.0,
                    child: FlatButton(
                      color: Colors.blue,
                      textColor: Colors.white,
                      disabledColor: Colors.grey,
                      disabledTextColor: Colors.black,
                      padding: EdgeInsets.all(8.0),
                      splashColor: Colors.blueAccent,
                      child: Text('Update Task'),
                      onPressed: () {
                        Firestore.instance.collection('Task').document(_postdocid()).updateData({
                          'Title': this.Title,
                          'Summary': this.Summary,
                          'Taskgivento': this.Taskgivento,
                          //'Status': 'Active',
                          'Completion': this.Completion,
                        });
                        Navigator.of(context).pop();
                      },
                    ),
                  )
                ],
              ),
            ),
          ),
        ));
  }
}

1 Ответ

0 голосов
/ 06 мая 2020

Присвойте значения заголовку, сводке и так далее ...

this.Title = widget.postid.data['Title'],
this.Summary = widget.postid.data['Summary'],

and so on ...

вы указываете начальное значение TextFormField для отображения, а не переменной, которую вы используете позже. если вы не редактируете какое-либо поле TextForm, тогда значение этой переменной равно null,

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...