我正在try 创建一个如下所示的Ffltter用户界面:

enter image description here

使用Expanded个小部件和它的flex属性,我已经创建了背景布局.但我不知道如何在上面创建圆角布局.

My Code:

@override
Widget build(BuildContext context) {
return Column(
    children: <Widget>[
      Expanded(
        flex: 1,
          child: Container(
            color: const Color(0xff32394a),
            child: Image.asset('assets/ic_logo_xx.png'),
          )
      ),
      Expanded(
        flex: 2,
          child: Container(
            color: Colors.white,
          )
      ),
    ]
);
}

我试图使用ClipRRect显示圆角布局,但它没有显示在现有布局的顶部.

Updated code with 100

@override
  Widget build(BuildContext context) {
    return Column(
        children: <Widget>[
          Expanded(
            flex: 1,
              child: Container(
                color: const Color(0xff32394a),
                child: Image.asset('assets/ic_logo_xx.png'),
              )
          ),
          Expanded(
            flex: 1,
            child: ClipRRect( //<---here
              borderRadius :BorderRadius.circular(10),
              child: Container(
                height: MediaQuery.of(context).size.height,
                width: 600,
                decoration: BoxDecoration(
                  color: Color(0xffF6F6F6),
                ),
              ),
            ),
          ),
          Expanded(
            flex: 2,
              child: Container(
                color: Colors.white,
              )
          ),
        ]
    );
  }

结果:

enter image description here

推荐答案

我们不一定需要ClipRRect,对于与您共享的图像类似的应用程序,我们可以使用Stack以及Animated PositionedContainer's BoxDecoration borderRadius属性.
Stack帮助我们一个接一个地布局小部件,最后一个小部件位于前一个小部件的顶部.然后我们可以使用动画定位小工具进行定位.
以下是我的main.dart文件的代码,它足以获得您想要的结果.
您还可以查看代码和结果here

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          SizedBox(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Stack(children: <Widget>[
              Positioned(
                  child: Container(
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.height * 0.4,
                color: const Color(0xff32394a),
                child: Center(
                    child: MaterialButton(
                        onPressed: () {},
                        child: const Text(
                          'Applogo',
                          style: TextStyle(fontSize: 32),
                        ))),
              )),
              Positioned(
                  top: MediaQuery.of(context).size.height * 0.4 - 64,
                  left: 32,
                  right: 32,
                  child: Column(
                    children: [
                      Container(
                        width: MediaQuery.of(context).size.width - 64,
                        decoration: BoxDecoration(
                          color: const Color(0xffF6F6F6),
                          borderRadius: BorderRadius.circular(16),
                        ),
                        padding: const EdgeInsets.all(32),
                        child: Column(
                          children: [
                            Container(
                              margin: const EdgeInsets.only(bottom: 32),
                              child: const Text(
                                'Sign In',
                                style: TextStyle(fontSize: 32),
                              ),
                            ),
                            Container(
                              margin: const EdgeInsets.only(bottom: 16),
                              child: TextField(
                                decoration: InputDecoration(
                                    border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(16)),
                                    hintText: 'Email / User name',
                                    contentPadding: const EdgeInsets.only(
                                        left: 16,
                                        right: 16,
                                        top: 8,
                                        bottom: 8)),
                              ),
                            ),
                            Container(
                              margin: const EdgeInsets.only(bottom: 16),
                              child: TextField(
                                decoration: InputDecoration(
                                    border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(16)),
                                    hintText: 'Password',
                                    contentPadding: const EdgeInsets.only(
                                        left: 16,
                                        right: 16,
                                        top: 8,
                                        bottom: 8)),
                              ),
                            ),
                            Row(
                              children: [
                                Checkbox(value: false, onChanged: (_) {}),
                                const Text("Remember Me")
                              ],
                            ),
                            Row(
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                Expanded(
                                  child: ElevatedButton(
                                    onPressed: () {},
                                    style: ElevatedButton.styleFrom(
                                      backgroundColor: const Color(0x9932394a),
                                    ),
                                    child: const Text("Sign In",
                                        style: TextStyle(
                                          color: Colors.white,
                                        )),
                                  ),
                                ),
                              ],
                            ),
                            const SizedBox(
                              height: 16,
                            ),
                            const Row(
                              mainAxisSize: MainAxisSize.max,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text("Forgot Username?"),
                                Text("Forgot Password?"),
                              ],
                            )
                          ],
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.only(top: 32),
                        child: const Text(
                          "Don't have an account? Sign Up",
                          style: TextStyle(color: Colors.black),
                        ),
                      )
                    ],
                  )),
            ]),
          ),
        ],
      ),
    );
  }
}

Here is the screenshot

enter image description here

Flutter相关问答推荐

如何在容器中移动图标按钮?

如何使用Firebase Firestore来获取外部集合中的文档子集合中的文档

flutter -当使用SingleChildScrollView包装我的列小部件时,它不会填充整个高度

'Flutter的无效常数值错误

我想在Flutter中画一个箭头,但我似乎无法填满空间

Flutter守护进程无法启动

Flutter 构建 Web 分段故障 - 无法启动事件处理程序线程

Flutter 包错误:此应用程序使用的是已弃用的 Android 嵌入版本

输入处于活动状态时如何设置文本字段标签的样式?

如何停止折线图的抖动

转换函数上传文件上传Uint8List

如何显示从 MariaDB 获取的数据到列表视图

Flutter 动画页面计数器文本

如何在图像上点或(图像的一部分)在 flutter 中点击?

如何限制用户每 24 小时执行的操作数?

在 Android 12+ 中,REST API 调用在 flutter 中非常慢,在 WiFi 中需要 10 秒,而在移动数据中不到一秒

如何让多个图标转到不同的网址

Flutter 中的无效日期格式 2022 年 11 月 14 日

既然我们已经有了 Flutter 的内置 setState,为什么还要在 Flutter 中使用 BloC 或 Provider?

带图像封面的 ElevatedButton