【问题标题】:How do I create this page?如何创建此页面?
【发布时间】:2021-05-13 15:41:57
【问题描述】:

我想创建一个像这张图片一样的页面。Scaffold 没有这个功能。image full screen

【问题讨论】:

  • 我猜你的意思是脚手架本身。这是一个简单的页面,背景图像上有一个按钮。您可以使用带有图像的 BoxDecoration 添加容器:AssetImage(...) 和 BoxFit.cover。 Container.child 会有你的按钮。
  • @ramsin2005,请查看答案!

标签: flutter flutter-layout


【解决方案1】:

您可以使用 Scaffold 和 DecorationImage 来应用背景和堆栈以在图像顶部放置徽标

Scaffold(
        body: Stack(
      children: [
        Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: NetworkImage("https://picsum.photos/200/300"),
              fit: BoxFit.cover,
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            "Logo",
            style: TextStyle(
                color: Colors.white, fontWeight: FontWeight.bold, fontSize: 30),
          ),
        )
      ],
    ))

【讨论】:

    【解决方案2】:

    您需要在这里使用堆栈小部件来制作相同的东西。这是我的代码。

    Widget build(BuildContext context) {
    final wi = MediaQuery.of(context).size.width;
    return Material(
      child: Scaffold(
          body: Stack(
        children: [
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: NetworkImage(
                    "https://i.ibb.co/sgjfh62/af8d63a477078732b79ff9d9fc60873f.jpg"),
                fit: BoxFit.cover,
              ),
            ),
          ),
          Container(
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.network("https://i.ibb.co/ZcvF9VF/5.png"),
                Text(
                  "Logo",
                  style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 30),
                ),
                Text(
                  "Logo",
                  style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 14),
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  decoration: BoxDecoration(
                      color: Colors.blueAccent,
                      borderRadius: BorderRadius.circular(10)),
                  child: Padding(
                    padding: EdgeInsets.all(18.0),
                    child: Text('button'),
                  ),
                )
              ],
            ),
          )
        ],
      )),
    );
    }
    

    【讨论】:

    • 这段代码中没有开始按钮(Button widget)!
    • 这是演示,你需要你想要的确切代码吗?只需用 Inkwell 或 gestureDetector 小部件包装容器!
    • Flutter 错误:使用不包含 MediaQuery 的上下文调用 MediaQuery.of()
    • stackoverflow.com/questions/56446363/…,你需要研究更多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2011-01-09
    • 2017-11-04
    相关资源
    最近更新 更多