如何解决当 ComboBox 更改时在 Flutter 中,我如何更改 TextFormField 中的文本?
但是当我更改下拉值时,即使我更改了它的值,用户和密码也不会更改。
看代码:
import 'dart:html';
import 'package:Flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appTitle = 'Test App';
return MaterialApp(
title: appTitle,home: Scaffold(
appBar: AppBar(
title: Text(appTitle),),body: MyForm(),);
}
}
class MyForm extends StatefulWidget {
const MyForm({Key? key}) : super(key: key);
@override
MyFormState createState() => MyFormState();
}
class MyFormState extends State<StatefulWidget> {
String _dbms = 'Postgresql';
String _user = 'postgres';
String _pasw = 'postgres';
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,children: [
Text('DBMS'),Container(
width: 150.0,child: DropdownButton(
value: _dbms,items: <String>['sqlite','Firebird','MysqL','Postgresql']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,child: Text(value),);
}).toList(),onChanged: (String? newValue) {
setState(() {
_dbms = newValue!;
switch (_dbms) {
case 'Postgresql':
_user = 'postgres';
_pasw = 'postgres';
break;
case 'MysqL':
_user = 'root';
_pasw = '';
break;
case 'Firebird':
_user = 'SYSDBA';
_pasw = 'masterkey';
break;
default:
_user = '';
_pasw = '';
break;
}
});
},Text('User'),child: TextFormField(
initialValue: '$_user',onChanged: (value) => _host,Text('Password'),child: TextFormField(
initialValue: _pasw,onChanged: (value) => _pasw,],);
}
}
我更改了属性的值,但未反映在组件上。
我该怎么做?
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。