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

load form from firestore document ? #198

Closed
antoniosap opened this issue Dec 11, 2019 · 1 comment
Closed

load form from firestore document ? #198

antoniosap opened this issue Dec 11, 2019 · 1 comment
Labels
solved A solution for this issue had been found

Comments

@antoniosap
Copy link

Form data from firestore is empty.
Some idea / example for loading data ?
writing form data is OK.

...
  Widget _showUserPage(BuildContext context) {
    _userRead();

    return Column(
        children: <Widget>[
          FormBuilder(
            key: _fbKey,
            autovalidate: true,
            initialValue: {
              'RagSoc': widget.RagSoc,
              'ResDom': widget.ResDom,
              'CFPiva': widget.CFPiva,
              'Ubicaz': widget.Ubicaz,
              'Autorz': widget.Autorz,
              'AutorzDate': widget.AutorzDate,
            },
            child: Column(
                children: <Widget>[
...
  void _userRead() async {
    await Firestore.instance
        .collection('USERS')
        .document(widget.userId)
        .get()
        .then((DocumentSnapshot ds) {
      if (ds.exists) {
        widget.RagSoc = ds.data['RagSoc'].toString();
        widget.ResDom = ds.data['ResDom'].toString();
        widget.CFPiva = ds.data['CFPiva'].toString();
        widget.Ubicaz = ds.data['Ubicaz'].toString();
        widget.Autorz = ds.data['Autorz'].toString();
        widget.AutorzDate = ds.data['AutorzDate'].toString();
      }
    });
  }
@yarmel
Copy link

yarmel commented Dec 26, 2019

`My working example 
===
void _getData(id) async {
    try {
      await repository.getHabitById(id).then((result) {
        initData = result.toJson();
      });
    } catch (e) {
      print(e);
    } finally {
      setState(() {
        isLoaded = true;
      });
    }
  }

  Widget _buildForm() {
    switch (action) {
      case "update":
        return FormBuilder(
          key: _habitKey,
          initialValue: isLoaded == true ? initData : {},
          autovalidate: false,
          child: Expanded(
            child: isLoaded == true ? HabitForm() : Container(),
          ),
        );
        break;
      default:
        return FormBuilder(
          key: _habitKey,
          initialValue: {},
          autovalidate: false,
          child: Expanded(
            child: HabitForm(),
          ),
        );
    }
  }`

@danvick danvick added the solved A solution for this issue had been found label May 7, 2020
@danvick danvick closed this as completed May 7, 2020
@danvick danvick reopened this May 7, 2020
@danvick danvick closed this as completed Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved A solution for this issue had been found
Projects
None yet
Development

No branches or pull requests

3 participants