键盘是我的 flutter 应用程序屏幕的一部分

问题描述 投票:0回答:1

我的应用程序只是使用文本字段添加联系人并删除它,但是当我添加超过 1 个联系人时,我发现文本字段的键盘由于其他小部件而溢出,所以我怎样才能使键盘不成为屏幕的一部分。仅供参考,当键盘关闭并且我按添加按钮时,在这种情况下不会出现错误。

我希望键盘是分离层或类似的东西。

import 'package:contactapp/button.dart';
import 'package:contactapp/info_col.dart';
import 'package:contactapp/new_contact.dart';
import 'package:flutter/material.dart';

class ContactScreen extends StatefulWidget {
  ContactScreen({super.key});

  @override
  State<ContactScreen> createState() => _ContactScreenState();
}

class _ContactScreenState extends State<ContactScreen> {
  late TextEditingController nameController;
  late TextEditingController phoneController;
  bool is_v = false;
  bool is_v1 = false;
  bool is_v2 = false;

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    nameController = TextEditingController();
    phoneController = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(
        title: Text("Contact Screen"),
      ),
      body: Column(
        children: [
          InfoColoumn("Enter Your Name Here", Icons.person, nameController,
              TextInputType.name),
          InfoColoumn("Enter Your Phone Here", Icons.call, phoneController,
              TextInputType.phone),
          SizedBox(
            height: 20,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(
                width: 20,
              ),
              Button("Add", Colors.blue, addCon),
              Button("Delete", Colors.red, delCon),
              SizedBox(
                width: 20,
              ),
            ],
          ),
          Visibility(
              visible: is_v,
              child: NewContact("Name: ${nameController.text}",
                  "Phone: ${phoneController.text}")),
          Visibility(
              visible: is_v1,
              child: NewContact("Name: ${nameController.text}",
                  "Phone: ${phoneController.text}")),
          Visibility(
              visible: is_v2,
              child: NewContact("Name: ${nameController.text}",
                  "Phone: ${phoneController.text}")),
        ],
      ),
    );
  }

  void addCon() {
    if (is_v == false) {
      is_v = true;
    } else {
      if (is_v1 == false) {
        is_v1 = true;
      } else if (is_v2 == false) {
        is_v2 = true;
      }
    }

    setState(() {});
  }

  void delCon() {
    if (is_v2 == true) {
      is_v2 = false;
    } else {
      if (is_v1 == true) {
        is_v1 = false;
      } else if (is_v == true) {
        is_v = false;
      }
    }
    setState(() {});
  }
}

android flutter dart mobile keyboard
1个回答
0
投票

我找到了解决方案。这很简单。在 Scaffold 中,属性

resizeToAvoidBottomInset
默认为 true,所以我将其更改为 true 并且有效。

Scaffold(
      resizeToAvoidBottomInset: false
    .......................)
© www.soinside.com 2019 - 2024. All rights reserved.