我是flutter框架的新手,我对dropdownbutton有一些问题。如何将所选的下拉按钮保存到mysql数据库中
此代码实际上可以保存到mysqldb中作为文本字段。但是如何获取所选的dropdownbutton值
signed int
插入数据库代码:
function wpd_date_404_template( $template = '' ){
global $wp_query;
if(
isset($wp_query->query['year']) ||
isset($wp_query->query['monthnum']) ||
isset($wp_query->query['day'])
) {
$template = locate_template( 'archive.php', false );
if ( isset( $wp_query->query['post_type'] ) ) {
$located = locate_template( 'archive-' . $wp_query->query['post_type'] . '.php', false );
$template = $located !== '' ? $located : locate_template( 'archive.php', false );
}
}
return $template;
}
add_filter( '404_template', 'wpd_date_404_template' );
显示下拉按钮值的代码
class FormOrtuView extends StatefulWidget {
@override
_FormOrtuViewState createState() => _FormOrtuViewState();
}
class _FormOrtuViewState extends State<FormOrtuView> {
String _dropdownValueAgm = 'Katolik';
final _key = new GlobalKey<FormState>();
返回代码以显示ui
sumbit(String namaAyah,agamaAyah) async {
var ayah = {
"id_register": idReg,
"nama_ayah": namaAyah,
"agama_ayah": agamaAyah,
};
final response = await http.post(BaseUrl.ayah, body: {
'id_register': ayah['id_register'],
'nama_ayah': ayah['nama_ayah'],
'agama_ayah': ayah['agama_ayah'],
});
print(response.statusCode);
final data = jsonDecode(response.body);
print(data);
}
下拉按钮代码
DropdownButton<String> _buildDropdownButtonAgama() {
return DropdownButton<String>(
value: _dropdownValueAgm,
onChanged: (String agamaAyah) {
setState(() {
_dropdownValueAgm = agamaAyah;
});
},
items: <String>[
'Katolik',
'Kristen',
'Islam',
'Hindu',
'Buddha',
'Kong Hu Chu',
'Kepercayaan'
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
}
答案 0 :(得分:0)
我认为您可以在提交数学方法时尝试以下代码:-
sumbit(String namaAyah,agamaAyah) async {
var ayah = {
"id_register": idReg,
"nama_ayah": namaAyah,
"agama_ayah": _dropdownValueAgm, //here i have change.
};
final response = await http.post(BaseUrl.ayah, body: {
'id_register': ayah['id_register'],
'nama_ayah': ayah['nama_ayah'],
'agama_ayah': ayah['agama_ayah'],
});
print(response.statusCode);
final data = jsonDecode(response.body);
print(data);
}