gpt4 book ai didi

material-design - 出现屏幕键盘时隐藏 FAB

转载 作者:IT老高 更新时间:2023-10-28 12:36:41 27 4
gpt4 key购买 nike

在 Flutter 中,如何制作 FAB button出现屏幕键盘时隐藏?

FAB 按钮在屏幕键盘上显示时会覆盖其他元素。

enter image description here

最佳答案

您可以通过使用 viewInsets 检查键盘可见性来实现它。并基于它隐藏 fab。

例子:

import 'package:flutter/material.dart';

void main() {
runApp(new MaterialApp(
title: "Example",
home: new FabHideOnKeyboard(),
));
}

class FabHideOnKeyboard extends StatefulWidget {
@override
_FabHideOnKeyboardState createState() => new _FabHideOnKeyboardState();
}

class _FabHideOnKeyboardState extends State<FabHideOnKeyboard> {
@override
Widget build(BuildContext context) {
final bool showFab = MediaQuery.of(context).viewInsets.bottom==0.0;
return Scaffold(
resizeToAvoidBottomPadding: true,
body:Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("TextField:"),
TextField()
],
),
),
floatingActionButton: showFab?Icon(Icons.add):null,
);
}
}

关于material-design - 出现屏幕键盘时隐藏 FAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48337422/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com