在TextField中提交值时,如何保持键盘显示?

时间:2020-06-08 18:00:00

标签: flutter dart

我是新手,我正在寻找一种方法,可以在按键盘上的Submit按钮后保持键盘显示。

即将多个值提交到TextEditingController后,键盘会停留在键盘上,并且只能通过键盘上的“后退/关闭”按钮将其关闭吗?

任何帮助将不胜感激:)谢谢!

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:keyboard_attachable/keyboard_attachable.dart';

import './add_button.dart';
import '../providers/data_provider.dart';


class KeyboardAttachableFooter extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _KeyboardAttachableFooterState();
  }
}

class _KeyboardAttachableFooterState extends State<KeyboardAttachableFooter> {
  @override
  Widget build(BuildContext context) {
    var dataProvider = Provider.of<DataProvider>(context);
    return KeyboardAttachable(
      backgroundColor: Colors.white,
      child: Container(
          padding: const EdgeInsets.all(10),
          color: Colors.white,
          child: Row(
            children: <Widget>[
              SizedBox(
                width: 10,
              ),
              Expanded(
                child: TextField(
                  controller: dataProvider.nameController,
                  onSubmitted: (submitted) => dataProvider.addToList(),
                  autofocus: true,
                  decoration: InputDecoration.collapsed(
                    hintText: "Add player name here",
                    fillColor: Colors.white,
                    filled: true,
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                ),
              ),
              SizedBox(
                width: 10,
              ),
              MyFabButton(),
            ],
          )),
    );
  }
}

0 个答案:

没有答案