标签: texteditingcontroller

如何在flutter fieldViewBuilder中访问TextEditingController

TextEditingController在 fieldViewBuilder 中有一个,但是,我无法在 RawAutocomplete 小部件之外访问它。

RawAutocomplete<String>(
                  optionsBuilder: (TextEditingValue textEditingValue) {
                    return foodTags.where((String option) {
                      return option
                          .contains(textEditingValue.text.toLowerCase());
                    });
                  },
                  onSelected: (String selection) {
                    setState(() {
                      _autocompleteSelection = selection;
                    });
                  },
                  fieldViewBuilder: (BuildContext context,
                      TextEditingController textEditingController,
                      FocusNode focusNode,
                      VoidCallback onFieldSubmitted) {
                    return TextFormField(
                      textInputAction: TextInputAction.next,
                      style: const TextStyle(color: Colors.white),
                      controller: textEditingController,
                      focusNode: focusNode,
                      onFieldSubmitted: (String value) {
                        onFieldSubmitted();
                      },
                      validator: (String? value) {
                        if (!foodTags.contains(value)) {
                          return 'Nothing selected.';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                        contentPadding: const EdgeInsets.all(20),
                        labelText: …
Run Code Online (Sandbox Code Playgroud)

widget textfield flutter google-cloud-firestore texteditingcontroller

5
推荐指数
1
解决办法
1434
查看次数

使用 TextEditingController 设置初始值后,在 TextField 中编辑值

我将一些用户信息从第一个屏幕传递到第二个屏幕,在第二个屏幕上,我尝试在文本字段内编辑该信息。我的第二个屏幕的代码如下。

class EditProfile extends StatefulWidget {
  String profName;
  String profOcc;
  EditProfile({Key? key, required this.profName, required this.profOcc,}): super(key: key);

  @override
  _EditProfileState createState() => _EditProfileState();
}

class _EditProfileState extends State<EditProfile> {

  @override
  Widget build(BuildContext context) {
    var nameController = TextEditingController()..text = widget.profName;
    var occController = TextEditingController()..text = widget.profOcc;

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        elevation: 1,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: Color(0xFF6f6bdb),
          ),
          onPressed: (){
            Navigator.pop(context);
          },
          ),
    ),
    body: Container(
      padding: EdgeInsets.fromLTRB(30.0, 30.0, 30.0, 0.0),
      child: GestureDetector(
        onTap: () {FocusScope.of(context).unfocus();}, …
Run Code Online (Sandbox Code Playgroud)

flutter texteditingcontroller

2
推荐指数
1
解决办法
5527
查看次数