简体   繁体   English

在 Flutter 中键盘退出后如何更改小部件

[英]How to change widget once the keyboard is out in Flutter

I am trying to design an app and my registration form appear to be quite big.我正在尝试设计一个应用程序,但我的注册表看起来很大。 I would like to be able to remove the logo once the keyboard is out and get it back once the keyboard disappear.我希望能够在键盘退出后移除徽标并在键盘消失后将其取回。 In other term I want a widget to react to the keyboard.换句话说,我想要一个小部件对键盘做出反应。 Will it be possible?有可能吗?

Below is the registration form下面是报名表

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,
                        ),
                      ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Kindly let me know请让我知道

You could check if the keyboard is not visible, and if so then show your logo widget:您可以检查键盘是否不可见,如果是,则显示您的徽标小部件:

            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'),
                      ),
                  ),
                ],
              ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM