【问题标题】:How to set image in bottom right corner in container in flutter?如何在颤动的容器的右下角设置图像?
【发布时间】:2021-07-06 03:51:55
【问题描述】:

我的第一个问题是如何在右下角设置图片,答案是

Align(
              alignment: Alignment.bottomRight,
              child: (Image(image: AssetImage("images/bg_decore_up_la.png"),)),
            ),

一切正常, 但是在父 Scaffold 我设置了

resizeToAvoidBottomInset: true,

表示出现键盘时正在滚动。 为了这 , 这个对齐(图像)小部件是我从 SingleChildScrollView 中设置的

现在我的整个代码就像

Scaffold(
        resizeToAvoidBottomInset: true,
        appBar:AppBar(),
        body:SafeArea(
            child:Stack(
                children:[
                  Align(
                    alignment: Alignment.bottomRight,
                    child: (Image(image: AssetImage("images/bg_decore_up_la.png"),)),
                  ),//want to fixed widget when keyboard will appear
                  ScrollConfiguration(
                      behavior: MyBehavior(),
                      child: SingleChildScrollView(
                         //scrolling widget list
                      )
                  )
                ]
            )
        )
    );

如果我设置

Align(
          alignment: Alignment.topRight,
          child: Container(
            margin: EdgeInsets.only(top: 60),
            child: (
                Image(
                  image: AssetImage("images/bg_decore_bottom_la.png"),)),
          ),

这段代码解决了这个问题, 但为此我需要适当的上边距

topMargin=totalScreenHeight-ImageWidth;

【问题讨论】:

    标签: flutter


    【解决方案1】:

    像这样使用 Stack 和 Positionned 小部件

    Stack(
                    children: const <Widget>[
                      Positioned(
                        bottom: 0,
                        right:0,
                        child: (Image(
                          image: AssetImage("images/bg_decore_up_la.png"),
                        )),
                      )
                    ],
                  ),
    

    【讨论】:

    • 当键盘出现时,不工作的图像仍然滚动
    猜你喜欢
    • 2020-05-26
    • 2021-08-06
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    相关资源
    最近更新 更多