0

我的登录屏幕有一个背景图片。当用户点击文本字段时,容器必须向上,以便文本字段/按钮不会隐藏在键盘下。

下面是我的代码,它工作正常。但是当启用文本字段时,背景图像只会向上移动。

    class _SignInState extends State<SignIn> {
      TextEditingController usernameController = TextEditingController();
      TextEditingController passwordController = TextEditingController();

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          //resizeToAvoidBottomInset: false,
          body: Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,

            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/bg.png'),
                fit: BoxFit.cover,
            )),

            child: SingleChildScrollView(
              padding: EdgeInsets.all(20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch, 
                children: <Widget>[

                  --- added username & password textfield ---
                  --- added submit and forgot password buttons ----

为了避免这种情况,我补充说:

    resizeToAvoidBottomInset: false,

作为“脚手架”的财产。现在滚动停止工作。

我哪里错了?

4

1 回答 1

2

用容器包裹脚手架,添加Boxdecoration(可以在其中添加背景图片)并使脚手架的背景颜色透明。

    class _SignInState extends State<SignIn> {
     TextEditingController usernameController = TextEditingController();
     TextEditingController passwordController = TextEditingController();

     @override
     Widget build(BuildContext context) {
      return Container(
       width: MediaQuery.of(context).size.width,
       height: MediaQuery.of(context).size.height,

       decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/bg.png'),
            fit: BoxFit.cover,
       )),

       child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Container(
         width: MediaQuery.of(context).size.width,
         height: MediaQuery.of(context).size.height,
         child: SingleChildScrollView(
             --- rest of the code ---
于 2020-06-16T10:11:39.460 回答