从多行退出焦点-颤振

时间:2020-05-31 18:35:01

标签: flutter textfield

我目前正在尝试制作一个在应用程序上做笔记的页面,因此我使用多行键盘类型来跟踪文本。但是,我很难逃避本文的重点。 Return带来了一个新行(我希望它执行此操作),但是我不确定何时拥有onSubmit或onEditingComplete,因为我从未真正使用多行提交任何东西。此外,在文本字段之外点击不会退出该字段的焦点。这是我编写的代码,如果您有任何建议,请告诉我!

import 'package:flutter/material.dart';

class NoteDetail extends StatefulWidget {
  @override
  _NoteDetailState createState() => _NoteDetailState();
}

class _NoteDetailState extends State<NoteDetail> {
  @override
  Widget build(BuildContext context) {
    final dimensions = MediaQuery.of(context).size;
    return LimitedBox(
      maxHeight: dimensions.height - 100,
      maxWidth: dimensions.width - 100,
      child: Column(
        children: <Widget>[
          SizedBox(
            height: dimensions.height * 0.10,
          ),
          TextField(
            keyboardType: TextInputType.multiline,
            //this allows the text to work with multiple lines
            maxLines: null,
            //no max lines making it scroll forever
            decoration: InputDecoration(
              hintText: 'Start taking some notes',
              //shows text before the user starts to text
              focusedBorder: InputBorder.none,
              enabledBorder: InputBorder.none,
              errorBorder: InputBorder.none,
              disabledBorder: InputBorder.none,
              //this removes the border all together
              contentPadding:
                  EdgeInsets.symmetric(horizontal: dimensions.width * 0.1),
              //giving the content some padding on the side
            ),
          ),
        ],
      ),
    );
  }
}

0 个答案:

没有答案