如何在Flutter中更改键盘

  • 本文关键字:键盘 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'),
),
),
],
),

相关内容

  • 没有找到相关文章