如何将数据分离到不同的数据库中?

How to separate data into different databases?

我有一个数据库,我想在其中添加和存储有关特定目的地或 activity 的信息。在插入信息页面中,我有一个部分,用户可以在其中 select 目的地或 activity 作为其类别。但是,所有这些都存储在一个数据库中,但我希望每个数据库都有不同的数据库。

这是将它们添加到一个数据库中的当前代码:

  void addDestOrAct(String name, String details, var category) {
    String key = destdatabaseref
        .child('Database')
        .child('DestinationsandActivities')
        .push()
        .key;
    destdatabaseref
        .child('Database')
        .child('DestinationsandActivities')
        .child(name)
        .set({
      'id': key,
      'name': name,
      'description': details,
      'category': category
    });
    nameController.clear();
    descriptionController.clear();

    Fluttertoast.showToast(
        timeInSecForIosWeb: 4,
        gravity: ToastGravity.CENTER,
        msg: "It has been added!");

    Navigator.pop(context);
  }

我想输入类似 if (category = 'Activity') 的内容,然后添加到 destdatabaseref.child('Database').child('Activities') 而不是 .child('DestinationsandActivities')

类别选择和插入数据代码:

                Padding(
                  padding: const EdgeInsets.only(right: 290),
                  child: Text(
                    'Category :',
                    style: TextStyle(fontSize: 15, color: Colors.grey),
                  ),
                ),
                SizedBox(height: 13),
                Container(
                  height: 40,
                  child: ListView(
                    scrollDirection: Axis.horizontal,
                    children: [
                      _categoryType('Destination'),
                      SizedBox(width: 10),
                      _categoryType('Activity'),
                    ],
                  ),
                ),
                SizedBox(height: 40),
                ElevatedButton(
                    style: ElevatedButton.styleFrom(
                        primary: Color(0xFF3d5a89),
                        padding:
                            EdgeInsets.symmetric(horizontal: 45, vertical: 10),
                        textStyle: TextStyle(
                            fontWeight: FontWeight.w500,
                            color: Colors.white,
                            fontSize: 15)),
                    onPressed: () {
                      if (_formKey.currentState!.validate()) {
                        if (nameController.text.isNotEmpty &&
                            descriptionController.text.isNotEmpty) {
                          addDestOrAct(nameController.text,
                              descriptionController.text, _categorySelected);
                        } else
                          return null;
                      }
                    },
                    child: Text('Add')
                    )

类别类型小部件代码:

Widget _categoryType(String title) {
    return InkWell(
      child: Container(
        height: 70,
        width: 120,
        decoration: BoxDecoration(
          color: _categorySelected == title
              ? Color(0xFF5a893d)
              : Color(0xFF3d5a89),
          borderRadius: BorderRadius.circular(15),
        ),
        child: Center(
          child: Text(
            title,
            style: TextStyle(fontSize: 13, color: Colors.white),
          ),
        ),
      ),
      onTap: () {
        setState(() {
          _categorySelected = title;
        });
      },
    );
  }

如何根据类别将信息添加到不同的数据库中?我现在有数据库 'DestinationsandActivities',但我真的更希望它是 'Destinations''Activities'

感谢@Frank van Puffelen,这很简单:

    if (category == 'Activity') {
      //code here
      });
    }

    if (category == 'Destination') {
      //code here
      });
    }