flutter-GridView使用

news2024/9/22 23:34:19

先看效果

代码实现

import 'package:app/common/util/k_log_util.dart';
import 'package:app/gen/assets.gen.dart';
import 'package:app/pages/widget/top_appbar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:timeago/timeago.dart';

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

  @override
  State<PopKkCoinGrants> createState() => _PopKkCoinGrantsState();
}

class _PopKkCoinGrantsState extends State<PopKkCoinGrants> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TopAppBar(context, ""),
      body: Container(
          margin: EdgeInsets.all(15.r),
          child: SingleChildScrollView(
            child: Column(children: [
              _topStaticInfo(),
              _topCountDown(),
              _pastGrantsListTop(),
              _pastGrantsList()
            ]),
          )),
    );
  }

  /// 顶部信息
  Widget _topStaticInfo() {
    return Column(children: [
      Assets.image.kKCoin.image(width: 80.r),
      SizedBox(
        height: 11.r,
      ),
      Text(
        "KKCoin Grants",
        style: TextStyle(
          color: Colors.white,
          fontSize: 16.sp,
          fontWeight: FontWeight.w500,
        ),
        textAlign: TextAlign.center,
      ),
      SizedBox(
        height: 15.r,
      ),
      Padding(
        padding: EdgeInsets.symmetric(horizontal: 5.r),
        child: Text(
          "There are 10 billion KKcoin tokens, and most will be given to unique humans with a verified Konnect ID.",
          style: TextStyle(
            color: const Color(0xff676970),
            fontSize: 13.sp,
            fontWeight: FontWeight.w500,
            height: 1.5,
            leadingDistribution: TextLeadingDistribution.even,
          ),
          textAlign: TextAlign.center,
        ),
      ),
    ]);
  }

  /// 顶部倒计时
  Widget _topCountDown() {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0xff25272B),
        borderRadius: BorderRadius.all(Radius.circular(20.r)),
      ),
      padding: EdgeInsets.all(25.r),
      margin: EdgeInsets.only(top: 25.r, bottom: 25.r),
      child: Row(children: [
        Assets.image.kKCoin.image(width: 56.r),
        SizedBox(
          width: 15.r,
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              "Next grant",
              style: TextStyle(
                color: const Color(0xff676970),
                fontWeight: FontWeight.w500,
                fontSize: 12.sp,
              ),
            ),
            SizedBox(
              height: 5.r,
            ),
            Text(
              "28 Jul",
              style: TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.w500,
                fontSize: 17.sp,
              ),
            ),
          ],
        ),
        Expanded(child: Container()),
        Text(
          "21:52:19",
          style: TextStyle(
            color: Colors.white,
            fontSize: 14.sp,
            fontWeight: FontWeight.w400,
          ),
        )
      ]),
    );
  }

  // 列表部分 头
  Widget _pastGrantsListTop() {
    return Padding(
      padding: EdgeInsets.only(bottom: 19.r),
      child: Row(children: [
        Text("Past grants",
            style: TextStyle(
              color: Colors.white,
              fontSize: 15.sp,
              fontWeight: FontWeight.w600,
            )),
        Expanded(child: Container()),
        Text(
          "07/2023",
          style: TextStyle(
            color: Color(0xff676970),
            fontWeight: FontWeight.w500,
            fontSize: 12.sp,
          ),
        )
      ]),
    );
  }

  // 列表部分
  Widget _pastGrantsList() {
    return GridView.builder(
        physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemCount: 10,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          //横轴元素个数
          crossAxisCount: 2,
          //纵轴间距
          mainAxisSpacing: 15.r,
          //横轴间距
          crossAxisSpacing: 15.r,
          //子组件宽高长度比例
          childAspectRatio: 165 / 105,
        ),
        itemBuilder: (_, position) {
          KLogUtil.d(position);
          return _pastGrantsListItem(position / 2 == 0);
        });
  }

  // 列表一项
  Widget _pastGrantsListItem(bool isPrimary) {
    TextStyle curStyle = isPrimary ? _textStyleWhite() : _textStyleGray();
    DecorationImage curBgImage = isPrimary ? _imagePrimary() : _imageGray();
    return Container(
      width: 165.r,
      height: 105.r,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10.r),
        image: curBgImage,
      ),
      child: Stack(children: [
        Positioned(
          top: 54.r,
          left: 10.r,
          child: Row(
            children: [
              Text(
                "DATE",
                style: curStyle,
              ),
              SizedBox(
                width: 22.r,
              ),
              Text(
                "26 / 07 / 2023",
                style: curStyle,
              )
            ],
          ),
        ),
        Positioned(
          top: 80.r,
          left: 10.r,
          child: Row(
            children: [
              Text(
                "KKCoin",
                style: curStyle,
              ),
              SizedBox(
                width: 12.r,
              ),
              Text(
                "256.23",
                style: curStyle,
              )
            ],
          ),
        ),
      ]),
    );
  }

  // 白色文字样式
  TextStyle _textStyleWhite() {
    return TextStyle(
      color: Colors.white,
      fontSize: 11.sp,
      fontWeight: FontWeight.w400,
    );
  }

  // 灰色的文字样式
  TextStyle _textStyleGray() {
    return TextStyle(
      color: Color(0xff45474D),
      fontWeight: FontWeight.w500,
      fontSize: 11.sp,
    );
  }

  // 灰色背景
  DecorationImage _imageGray() {
    return DecorationImage(
      image: Assets.image.pastGrantsGray.provider(),
      fit: BoxFit.cover,
    );
  }

  // 主色背景
  DecorationImage _imagePrimary() {
    return DecorationImage(
      image: Assets.image.pastGrantsPrimary.provider(),
      fit: BoxFit.cover,
    );
  }
}

关键部分

GridView.builder(
        physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemCount: 10,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          //横轴元素个数
          crossAxisCount: 2,
          //纵轴间距
          mainAxisSpacing: 15.r,
          //横轴间距
          crossAxisSpacing: 15.r,
          //子组件宽高长度比例
          childAspectRatio: 165 / 105,
        ),
        itemBuilder: (_, position) {
          KLogUtil.d(position);
          return _pastGrantsListItem(position / 2 == 0);
        });
  }

其中physics属性  physics: const NeverScrollableScrollPhysics()会禁止页面滚动

shrinkWrap 让容器被内容撑满

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/834473.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

机器学习深度学习——卷积的多输入多输出通道

&#x1f468;‍&#x1f393;作者简介&#xff1a;一位即将上大四&#xff0c;正专攻机器学习的保研er &#x1f30c;上期文章&#xff1a;机器学习&&深度学习——从全连接层到卷积 &#x1f4da;订阅专栏&#xff1a;机器学习&&深度学习 希望文章对你们有所帮…

GPT神器级插件Code Interpreter开放,这里有一份保姆级教程

# 关注并星标腾讯云开发者# 每周4 | 鹅厂一线程序员&#xff0c;为你“试毒”新技术# 第2期 | 腾讯李洛勤&#xff1a;测评 GPT4 Code Interpreter 体验 自 3 月份以来&#xff0c;人们对 GPT-4 API 的兴趣激增&#xff0c;“有数百万开发人员请求访问”。OpenAI 在一篇博客文章…

MySQL日志——慢查询日志

1.慢查询日志 默认情况下&#xff0c;不会记录管理语句&#xff0c;也不会记录不使用索引进行查找的查询。可以 使用log_slow_admin_statements和更改此行为log_queries_not_using_indexes&#xff0c;如下所述。 #慢查询日志 slow_query_log1 #执行时间参数 long_query_time…

Redis面试题-3

Redis面试题-3 14、什么是缓存击穿&#xff1f;该如何解决 缓存击穿是指一个Key非常热点&#xff0c;在不停的扛着大并发&#xff0c;大并发集中对这一个点进行访问&#xff0c;当这个Key在失效的瞬间&#xff0c;持续的大并发就穿破缓存&#xff0c;直接请求数据库&#xff…

SpringBoot整合Nacos实现配置中心

目录 1.Nacos定位 2.Nacos的安装配置 3.整合Nacos 3.1.Nacos安装 3.2.Nacos登录 3.3.配置Nacos 4.Nacos使用 4.1.引入 Maven 依赖 4.2.配置bootstrap.yml 4.3.Nacos配置类 4.4.启用Nacos服务 4.5.测试获取配置 5.加载多个配置文件 datasource-dev.yaml myba…

Antd Table带有分页的全选功能

这种带有分页的全选 如果我们翻页也需要记录跨页的勾选数据 antd自带的onChange事件只能记录选中RowKey值 但是勾选的数据只会是当前页的条数 此时就需要我们结合onSelect和onSelectAll来完成数据的交互 <Tableloading{tableDataloading}rowKey"id"rowSelection{r…

Unity进阶--使用PhotonServer实现服务端和客户端通信--PhotonServer(一)

文章目录 Unity进阶--使用PhotonServer实现服务端和客户端通信服务器的安装和配置添加日志客户端的配置客户端和服务器的通信Dlc 出现vscode引用不好使的时候 Unity进阶–使用PhotonServer实现服务端和客户端通信 服务器的安装和配置 Photon的地址&#xff1a;https://www.ph…

智能物流千人俱乐部---行业必备神器

千人俱乐部前两天正式推出了。 智能物流千人俱乐部详情 很多行业内的甲方和乙方的朋友过来问&#xff0c;这个千人俱乐部到底怎么玩&#xff1f;今天再来解释一下。 1、为什么搞这个千人俱乐部&#xff1f; 一个原因是&#xff1a;研习社天天都有甲方粉丝让推荐设备厂家&#x…

Wavefront .OBJ文件格式解读【3D】

OBJ&#xff08;或 .OBJ&#xff09;是一种几何定义文件格式&#xff0c;最初由 Wavefront Technologies 为其高级可视化器动画包开发。 该文件格式是开放的&#xff0c;已被其他 3D 图形应用程序供应商采用。 OBJ 文件格式是一种简单的数据格式&#xff0c;仅表示 3D 几何体&…

【力扣每日一题】2023.8.4 不同路径3

目录 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 代码&#xff1a; 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 在二维网格之上&#xff0c;让我们模拟从开头走到末尾&#xff0c;并且要经过所有能经过的点&#xff0c;问我们有多少种走法。 看到这道…

【雕爷学编程】MicroPython动手做(31)——物联网之Easy IoT 3

1、物联网的诞生 美国计算机巨头微软(Microsoft)创办人、世界首富比尔盖茨&#xff0c;在1995年出版的《未来之路》一书中&#xff0c;提及“物物互联”。1998年麻省理工学院提出&#xff0c;当时被称作EPC系统的物联网构想。2005年11月&#xff0c;国际电信联盟发布《ITU互联网…

PCIE扩频时钟及参考时钟要求

Spread Spectrum Clocking 1. 概述 Spread Spectrum Clocking(扩频时钟)是采用一种可控的方式使系统时钟抖动以减少峰值能量的过程。主要是为了尽量减少电磁干扰(EMI),主要应用在PCle和USB应用中。与非调制时钟相比,扩频时钟具有相对较高的抖动,应确保下游元件能够承受扩频…

Python:Spider爬虫工程化入门到进阶(1)Scrapy

本文通过简单的小例子&#xff0c;亲自动手创建一个Spider爬虫工程化的Scrapy项目 本文默认读着已经掌握基本的Python编程知识 目录 1、环境准备1.1、创建虚拟环境1.2、安装Scrapy1.3、创建爬虫项目 2、爬虫示例-爬取壁纸2.1、分析目标网站2.2、生成爬虫文件2.3、编写爬虫代码…

用python做一个小项目,python做简单小项目

大家好&#xff0c;本文将围绕用python做一个小项目展开说明&#xff0c;python做简单小项目是一个很多人都想弄明白的事情&#xff0c;想搞清楚python入门小项目需要先了解以下几个事情。 来源丨网络 经常听到有朋友说&#xff0c;学习编程是一件非常枯燥无味的事情。其实&…

实现实时互动:用Spring Boot原生WebSocket打造你的专属聊天室

&#x1f60a; 作者&#xff1a; 一恍过去 &#x1f496; 主页&#xff1a; https://blog.csdn.net/zhuocailing3390 &#x1f38a; 社区&#xff1a; Java技术栈交流 &#x1f389; 主题&#xff1a; 实现实时互动&#xff1a;用Spring Boot原生WebSocket打造你的专属聊天…

详解Nodejs中的Process对象

在Nodejs中&#xff0c;process是一个全局对象&#xff0c;它提供了与当前进程和运行时环境交互的方法和属性。通过process对象&#xff0c;我们可以访问进程的信息、控制流程和进行进程间通信&#xff0c;这些都是服务端语言应该具备的能力。本文将全面介绍process对象的使用场…

【雕爷学编程】 MicroPython动手做(35)——体验小游戏2

知识点&#xff1a;什么是掌控板&#xff1f; 掌控板是一块普及STEAM创客教育、人工智能教育、机器人编程教育的开源智能硬件。它集成ESP-32高性能双核芯片&#xff0c;支持WiFi和蓝牙双模通信&#xff0c;可作为物联网节点&#xff0c;实现物联网应用。同时掌控板上集成了OLED…

从感知到理解-融合语言模型的多模态大模型研究

©PaperWeekly 原创 作者 | 张燚钧 单位 | 中国移动云能力中心 研究方向 | 预训练大模型 引言 近年来&#xff0c;大语言模型&#xff08;Large language model, LLM&#xff09;取得了显著进展。以 ChatGPT 为代表的 LLM 在自然语言任务上展现出惊人的智能涌现能力。尽管…

TPU-NNTC 编译部署LPRNet 车牌识别算法

TPU-NNTC 编译部署LPRNet 车牌识别算法 注意&#xff1a; 由于SOPHGO SE5微服务器的CPU是基于ARM架构&#xff0c;以下步骤将在基于x86架构CPU的开发环境中完成 初始化开发环境(基于x86架构CPU的开发环境中完成)模型转换 (基于x86架构CPU的开发环境中完成) 处理后的LPRNet 项…

sql入门4--函数

字符串函数 # -----字符串函数----- # concat(s1,s2,....)拼接 select concat(Hello ,Mysql); #str转换为小写 select lower(HELLO); # str转换为大写 select upper(mysql); # 向左侧添加 str 位数 要添加的元素 select lpad(1, 3 ,-); # 向右侧添加 str 位数 要添加的元…