在flutter中将下拉选择插入到数据库中

时间:2019-07-08 01:42:28

标签: flutter dart flutter-web

我想从下拉菜单中将数据输入数据库,但是使用此代码时,所有数据都不会进入数据库,例如此代码有问题。这是显示下拉菜单的代码

FutureBuilder(
    future: ClientController.getClient(),
    builder: (context, snapshot) {
    if (snapshot.hasData) {
        return new DropdownButton(
            hint: Text('Pilih Company'),
            value: _selectedClient,
            items: snapshot.data
                .map<DropdownMenuItem>((value) {
                    return DropdownMenuItem(
                        value: value,
                        child: Text(value["name"]),
                    );
                }).toList(),
            onChanged: (value) {
                setState(() {
                    _selectedClient = value;
                });
            },
        );
    } else {
        return CircularProgressIndicator();
    }
}),

,并将此代码输入数据库

if (result) {
    final response = await UserController.register({
        "username": txtUsername.text,
        "password": txtPassword.text,
        "email": txtEmail.text,
        "full_name": txtFullName.text,
        "company": _selectedClient,
    });

    if (response != null && response["success"]) {
        setState(() {});
    }
}

0 个答案:

没有答案