flutter - 如何在 Flutter 中退出键盘后更改小部件
问题描述
我正在尝试设计一个应用程序,我的注册表似乎很大。我希望能够在键盘退出后删除徽标,并在键盘消失后将其取回。换句话说,我想要一个小部件对键盘做出反应。有可能吗?
下面是报名表
import 'package:flutter/material.dart';
import 'package:flutter_signin_button/button_list.dart';
import 'package:tembea/components/rounded_button.dart';
import 'package:tembea/constants.dart';
import 'package:flutter_signin_button/flutter_signin_button.dart';
class RegistrationScreen extends StatelessWidget {
const RegistrationScreen({Key? key}) : super(key: key);
static const String id = 'registration_screen';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Padding(
padding:const EdgeInsets.symmetric(horizontal: 24.0),
child: Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Hero(
tag: 'logo',
child: SizedBox(
height: 100,
child: Image.asset('images/logo.png'),
),
),
],
),
const SizedBox(
height: 20.0,
),
TextField(
textAlign: TextAlign.center,
style:const TextStyle(
color: Colors.white,
),
onChanged: (value){},
decoration: kInputDecoration.copyWith(
hintText: 'Enter username',
),
),
const SizedBox(
height: 20.0,
),
TextField(
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
),
onChanged: (value){},
decoration: kInputDecoration.copyWith(
hintText: 'Enter email',
),
),
const SizedBox(
height: 20.0,
),
TextField(
textAlign: TextAlign.center,
obscureText: true,
style: const TextStyle(
color: Colors.white,
),
onChanged: (value){},
decoration: kInputDecoration.copyWith(
hintText: 'Enter password',
),
),
const SizedBox(
height: 20.0,
),
TextField(
textAlign: TextAlign.center,
obscureText: true,
style: const TextStyle(
color: Colors.white,
),
onChanged: (value){},
decoration: kInputDecoration.copyWith(
hintText: 'Confirm password',
),
),
const SizedBox(
height: 20.0,
),
RoundedButton(
buttonName: 'Register',
color: Colors.lightGreen,
onPressed: (){},
),
const SizedBox(
height: 20,
),
SignInButton(
Buttons.Google,
text: 'Sign Up with Google',
onPressed: (){},
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Already have an account?',
style: TextStyle(
color: Colors.white,
),
),
const SizedBox(
height: 5.0,
),
TextButton(
onPressed: (){},
child: const Text(
'Sign In',
style: TextStyle(
color: Colors.green,
),
),
),
],
),
],
),
),
),
);
}
}
请告诉我
解决方案
您可以检查键盘是否不可见,如果是,则显示您的徽标小部件:
if(MediaQuery.of(context).viewInsets.bottom==0)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Hero(
tag: 'logo',
child: SizedBox(
height: 100,
child: Image.asset('images/logo.png'),
),
),
],
),
推荐阅读
- html - Divs 没有在 flex 容器内垂直对齐
- xcode - 如何修复 iOS ITMS-90809?
- tensorflow - “ValueError:无法将大小为 278540 的数组重塑为形状 (256,128,3,3)” 将 YOLOv3 .weights 转换为 .pb
- vhdl - 制作计数器时操作数出错
- html - 为什么 nth-of-type 不能正常工作
- visual-studio-code - VSCode 中的部分是灰色的?
- python-requests - 使用twill和python3.6下载文件
- c++ - 类模板实例化或表达式中的内联(“单行”)函数定义
- html - 可以为元素添加淡入淡出动画使元素闪烁吗?
- javascript - 通过 express.js 中的 res.render() 传递函数并从 pug 文件中访问该函数