当键盘弹出时如何隐藏图像小部件?

How can i hide image widget when keyboard pops in flutter?

大家好我需要你的帮助,我只是想在键盘弹出时隐藏图像小部件, 但是当我单击文本字段并打开键盘时,它一直关闭,你能帮我解决这个问题吗?我附上我的代码谢谢!

import 'package:flutter/material.dart';
import 'package:ovsursadmin/screens/authentication/login_card.dart';

class Login extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      backgroundColor: Colors.blue[900],
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: ExactAssetImage('assets/bg-admin.png'),
            fit: BoxFit.cover,
            colorFilter: ColorFilter.mode(Colors.blue[900].withOpacity(0.1), BlendMode.dstATop),
          )
        ),
        child: SafeArea(
          child: Container(
            child : Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                SizedBox(height: 10.0,),
// this code i want to fix it keeps closing the keyboard when pops
                MediaQuery.of(context).viewInsets.bottom != 0 ? Container() : Image.asset('assets/urs.png',
                height: 100,
                width: 100,),
                SizedBox(height: 25.0,),
                Text('Admin Login', style: TextStyle(color: Colors.white),),
                Text('Online Voting System', style: TextStyle(color: Colors.white),),
                LoginCard(),
              ],
            )
          ),
        ),
      ),
    );
  }

}

This is my problem it keeps closing when you click the text field and open the keyboard

正在使用

添加依赖:

依赖项: keyboard_visibility: ^0.5.6

代码:

   bool _isKeyboardOpen = false;
    @protected
    void initState() {
      super.initState();

      KeyboardVisibilityNotification().addNewListener(
        onChange: (bool visible) {
        setState(() {
          _isKeyboardOpen = visible;
          });

        },
      );
    }

在构建小部件中使用代码喜欢:

选项 1:

_isKeyboardOpen ? Container() : Image.asset('assets/urs.png',
                height: 100,
                width: 100,)

选项2:

  if(!_isKeyboardOpen)
      Image.asset('assets/urs.png', height: 100, width: 100,)