我正在try 使用Flutter和Firebase制作一个任务应用程序. 我不是最擅长设计的人,所以我从Dribbble那里获取了一个设计,试图将其复制到我的应用程序中.

这是设计的链接. Dribbble link

这是我试图复制的页面: Page screenshot

这是我当时做的代码:(实际上不起作用)

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final String userID = FirebaseAuth.instance.currentUser!.uid;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.only(top: 25.0),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(left: 25),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: StreamBuilder(
                    stream: FirebaseFirestore.instance
                        .collection("Users")
                        .doc(userID)
                        .snapshots(),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.waiting) {
                        return const Center(child: CircularProgressIndicator());
                      }
                      if (snapshot.hasError) {
                        return const Text("Erreur");
                      }
                      return Text.rich(
                        TextSpan(
                          text: "Bonjour,\n",
                          style: GoogleFonts.exo2(
                            fontSize: 40,
                            height: 1.25,
                          ),
                          children: [
                            TextSpan(
                              text: snapshot.data!.data()!["name"],
                              style: const TextStyle(
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ],
                        ),
                      );
                    },
                  ),
                ),
              ),
              Row(
                children: [
                  // Column de gauche
                  SizedBox(
                    width: MediaQuery.of(context).size.width / 2,
                    child: ListView(
                      children: const [],
                    ),
                  ),

                  // Column de droite
                  SizedBox(
                    width: MediaQuery.of(context).size.width / 2,
                    child: Column(
                      children: [
                        Container(),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

我真的不知道如何进行相同的布局,因为我必须将屏幕分成2部分,并且ListView.builder(在我的代码中只有ListView)需要固定大小.

每个对我的代码中的任何内容有任何建议来帮助我改进它并提高我的技能的人,我都在这里倾听!

如果有人知道我如何复制同一页面或者只是帮助我这样做,那就太好了!

推荐答案

正如我在 comments 中提到的那样,使用flutter_staggered_grid_view和堆栈可以产生相同的设计.判断下面的代码,它会产生您想要的内容.但您需要在代码中相应地设置大小.

Stack(
        children: [
          MasonryGridView.count(
            padding: const EdgeInsets.all(15.0),
            crossAxisCount: 2,
            mainAxisSpacing: 16,
            crossAxisSpacing: 16,
            itemBuilder: (context, index) {
              if (index == 1) {
                return const SizedBox(
                  height: 150,
                );
              }
              return Container(
                height: 300,
                decoration: BoxDecoration(
                  color: Colors.red,
                  borderRadius:  BorderRadius.circular(20.0),
                ),
              );
            },
          ),
          Positioned(
            right: 0,
            top: 15,
            child: Container(
              height: 150,
              width: MediaQuery.sizeOf(context).width * 0.5 - 8, // half of screen size - half of cross axis padding in MasonryGridView will give its width
              decoration: BoxDecoration(
                color: Colors.white,
                border: Border.all(color: Colors.grey),
                borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(20),
                    bottomLeft: Radius.circular(20)),
              ),
              alignment: Alignment.center,
              child: const Icon(Icons.add),
            ),
          )
        ],
      )

结果

enter image description here

enter image description here

Flutter相关问答推荐

如何在不使用NULL-check(!)的情况下缩小`FutureBuilder.Builder()`内部的`Snaphot`范围

有没有一种正确的方法可以通过上下滑动在两个小部件(在我的情况下是应用程序栏)之间切换?

修复后期变量的抖动皮棉

Flutter API请求BadState响应

Android Studio扩展控件上未加载Google map

Flutter 数独网格

如何翻转这种剪刀设计

如何将带有参数的函数传递给FIFTH中的自定义小部件

从图标启动器打开时,VSCode未检测到Web设备

在 flutter 的列中使用 Expanded 时出现渲染 Flex 错误

Flutter Dismissible 不会在 startToEnd 滑动时被关闭

如何动态获取任何小部件的像素?

Flutter中pubspec.yaml文件中的name参数是什么?

添加appBar时绘制的线条发生偏移 Flu

不使用 GlobalKey 仍然收到 GlobalKey 被多次使用的错误

我的第一个 flutter 项目出错,启动时为空值?

如何扫描来自给定链接或按钮的重定向中的所有 URL?

Flutter 本地通知在最新版本中不起作用

Flutter 用户过滤器

如何将变量翻译成其他语言