当前位置: 首页 > news >正文

flutter-GridView使用

先看效果

代码实现

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});@overrideState<PopKkCoinGrants> createState() => _PopKkCoinGrantsState();
}class _PopKkCoinGrantsState extends State<PopKkCoinGrants> {@overrideWidget 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 让容器被内容撑满

相关文章:

flutter-GridView使用

先看效果 代码实现 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_…...

Unity Shader编辑器工具类ShaderUtil 常用函数和用法

Unity Shader编辑器工具类ShaderUtil 常用函数和用法 Unity的Shader编辑器工具类ShaderUtil提供了一系列函数&#xff0c;用于编译、导入和管理着色器。本文将介绍ShaderUtil类中的常用函数和用法。 编译和导入函数 CompileShader 函数签名&#xff1a;public static bool C…...

详解Spring中涉及的技术

注解 介绍&#xff1a; 注解(Annotation)很重要&#xff0c;未来的开发模式都是基于注解的&#xff0c;JPA是基于注解的&#xff0c;Spring2.5以上都是基于注解的&#xff0c;Hibernate3.x以后也是基于注解的&#xff0c;现在的Struts2有一部分也是基于注解的了&#xff0c;注…...

阿里云ssl免费数字证书快过期 如何更换

1.登陆阿里云 找到ssl 查看快过期的证书 数字证书管理服务-ssl证书 2.创建免费的证书&#xff0c;对应过期证书的域名 3.下载新证书 pem key放在本地 此处记录本地的下载路径 /Users/dorsey/Downloads/10791167_lzzabc.cn_nginx/lzzabc.cn.pem /Users/dorsey/Downloads/1…...

利用OpenCV实现图像拼接

一、介绍 图像拼接. 二、分步实现 要实现图像拼接&#xff0c;简单来说有以下几步&#xff1a; 对每幅图进行特征点提取对对特征点进行匹配进行图像配准把图像拷贝到另一幅图像的特定位置对重叠边界进行特殊处理 PS&#xff1a;需要使用低版本的opencv&#xff0c;否则无法使…...

【java安全】无Commons-Collections的Shiro550反序列化利用

文章目录 【java安全】无Commons-Collections的Shiro550反序列化利用Shiro550利用的难点CommonsBeanutils1是否可以Shiro中&#xff1f;什么是serialVersionUID&#xff1f;W 无依赖的Shiro反序列化利用链POC 【java安全】无Commons-Collections的Shiro550反序列化利用 Shiro5…...

CSS 滚动条

一、滚动条样式属性 ::-webkit-scrollbar {width: 6px; /* 竖向滚动条宽度 */height: 6px; /* 横向滚动条高度 */ }::-webkit-scrollbar-thumb {border-radius: 10px; /* 滚动条样式 */-webkit-box-shadow: inset 0 0 3px red; /* 内阴影 */background-color: blue; /* 滚动条…...

Linux: security: openssh: sshd 出现defunct的一种情况

最近遇到了一个问题,就出现了一对遗留进程对,类似于下面这两个 root 77399 19100 77399 0 1 01:46 ? 00:00:00 sshd: \mzhan017 [priv] sshd 77400 77399 77400 0 1 01:46 ? 00:00:00 sshd: [defunct] 人生中的第一次遇到这种情况。一定要记录一下! 关于[priv]这个解释,…...

Self-regulating Prompts: Foundational Model Adaptation without Forgetting

本文也是大模型系列的文章&#xff0c;主要是与Prompt Learning有关。针对《Self-regulating Prompts: Foundational Model Adaptation without Forgetting》的翻译。 自我调节的提示&#xff1a;不遗忘的基础模型适应 摘要1 引言2 相关工作3 提出的方法3.1 前言3.2 提示学习的…...

平时工资不够用?推荐4种适合工作之余做的兼职副业!

你是否也曾经在为每个月的工资发愁&#xff1f;你是否想过做点副业来增加收入&#xff1f;现在很多上班族的工资&#xff0c;已经难以满足他们的生活需求了&#xff0c;很多人开始尝试通过副业来增加收入。那么上班族要如何寻找适合自己的副业呢&#xff1f;下面就给大家分享几…...

21.Netty源码之编码器

highlight: arduino-light Netty如何实现自定义通信协议 在学习完如何设计协议之后&#xff0c;我们又该如何在 Netty 中实现自定义的通信协议呢&#xff1f;其实 Netty 作为一个非常优秀的网络通信框架&#xff0c;已经为我们提供了非常丰富的编解码抽象基类&#xff0c;帮助我…...

Linux 快速创建桌面图标

在安装 tar.gz 这类型压缩文件时&#xff0c;通常启动文件是.sh文件。文章主要记录快速添加到桌面图标。 1、解压 tar -zxvf XXX.tar.gz 2、创建桌面图标文件 touch XXX.desktop 3、文件中配置 [Desktop Entry] NameXXX CommentZZZ Exec/软件可执行文件所在目录/可执行文…...

数据结构—哈夫曼树及其应用

5.6哈夫曼树及其应用 5.6.1哈夫曼树的基本概念 路径&#xff1a;从树中一个结点到另一个结点之间的分支构成这两个结点间的路径。 结点的路径长度&#xff1a;两结点间路径上的分支数。 树的路径长度&#xff1a;从树根到每一个结点的路径长度之和。记作 TL 结点数目相同的…...

NeRF-SLAM: Real-Time Dense Monocular SLAM with Neural Radiance Fields 论文阅读

论文信息 题目&#xff1a;NeRF-SLAM: Real-Time Dense Monocular SLAM with Neural Radiance Fields 作者&#xff1a;Antoni Rosinol, John J. Leonard&#xff0c; Luca Carlone 代码&#xff1a;https://github.com/ToniRV/NeRF-SLAM 来源&#xff1a;arxiv 时间&#xff…...

机器学习之弹性网络(Elastic Net)

弹性网络 代码原文 下面代码参考scikit-learn中文社区&#xff0c;链接在上面。 但是由于scikit-learn中文社区上的代码有些地方跑不通&#xff0c;故对此代码做了修改&#xff0c;输出结果与社区中显示的结果相同。 对弹性网络进行简单的介绍&#xff1a; ElasticNet是一个训…...

嵌入式入门教学——C51

一、前期准备 1、硬件设备 2、软件设备 二、预备知识 1、什么是单片机&#xff1f; 在一片集成电路芯片上集成微处理器、存储器、IO接口电路&#xff0c;从而构成了单芯片微型计算机&#xff0c;及单片机。STC89C52单片机&#xff1a; STC&#xff1a;公司89&#xff1a;所属…...

2023-08-03力扣每日一题

链接&#xff1a; 722. 删除注释 题意&#xff1a; 如题&#xff0c;特殊规则见链接 解&#xff1a; 字符串处理&#xff0c;嗯写就完事了,主要是判断指针位置和特殊规则 实际代码&#xff1a; #include<bits/stdc.h> using namespace std; vector<string> …...

【蓝桥杯备考资料】如何进入国赛?

目录 写在前面注意事项数组、字符串处理BigInteger日期问题DFS 2013年真题Java B组世纪末的星期马虎的算式振兴中华黄金连分数有理数类&#xff08;填空题&#xff09;三部排序&#xff08;填空题&#xff09;错误票据幸运数字带分数连号区间数 2014年真题蓝桥杯Java B组03猜字…...

QtWebApp开发https服务器,完成客户端与服务器基于ssl的双向认证

引言&#xff1a;所谓http协议&#xff0c;本质上也是基于TCP/IP上服务器与客户端请求和应答的标准&#xff0c;web开发中常用的http server有apache和nginx。Qt程序作为http client可以使用QNetworkAccessManager很方便的进行http相关的操作。Qt本身并没有http server相关的库…...

动态IP代理的优势展现与应用场景

在当今数字化时代&#xff0c;网络安全和隐私保护变得愈发重要。作为一家动态IP代理产品供应商&#xff0c;我们深知在保护个人隐私和提高网络安全性方面的重要性。本文将会分享动态IP代理的优势及其在不同应用场景下的实际应用案例&#xff0c;帮助更好地了解和应用动态IP代理…...

STM32F103片内Flash读写避坑指南:CubeMX配置虽简单,但这几个细节错了就HardFault

STM32F103片内Flash读写避坑指南&#xff1a;从硬件机制到实战优化 第一次在项目中尝试使用STM32片内Flash存储设备运行日志时&#xff0c;系统每隔几天就会莫名其妙死机。通过逻辑分析仪抓取异常时刻的波形&#xff0c;发现每次HardFault都发生在Flash写入操作后的20μs内。这…...

HCIA复习——瑕疵版

AR4配置部分system-view sysname AR3 undo info-center enable# 接 AR1 interface GigabitEthernet 0/0/0ip address 202.100.1.2 255.255.255.252quit# 接 AR4 interface GigabitEthernet 0/0/1ip address 10.1.34.1 255.255.255.252quit# 接 AR5 interface GigabitEthernet 0…...

Docker安装教程(CentOS)(包含compose和swarm)

参考资料&#xff1a; 参考视频 Docker官网安装教程&#xff08;CentOS 8&#xff09; CentOS 7安装Docker(本文主要参考教程&#xff0c;还有Ubuntu) CentOS 7安装Docker教程&#xff1a; 1.卸载旧版Docker sudo yum remove docker \docker-client \docker-client-latest…...

终极UDS安全性与最佳实践指南:确保您的数据安全无忧

终极UDS安全性与最佳实践指南&#xff1a;确保您的数据安全无忧 【免费下载链接】uds &#x1f4c0; Unlimited Google Drive Storage by splitting binary files into base64 项目地址: https://gitcode.com/gh_mirrors/ud/uds UDS&#xff08;Unlimited Drive Storage…...

html页面间调用

一、简单情况1、父页面通过iframe套子页面情况子页面通过window.parent调用父页面的函数2、多层嵌套window.top找到最顶层3、父界面通过open打开子界面子界面通过window.opener得到父界面二、复杂情况根据上述关系&#xff0c;进行各种组合&#xff0c;例如window.top.opener举…...

使用 C# 删除 PDF 中的数字签名藤

一、 什么是 AI Skills&#xff1a;从工具级到框架级的演化 AI Skills&#xff08;AI 技能&#xff09; 的概念最早在 Claude Code 等前沿 Agent 实践中被强化。最初&#xff0c;Skills 被视为“工具级”的增强&#xff0c;如简单的文件读写或终端操作&#xff0c;方便用户快速…...

告别数据丢包!用Qt实现高可靠串口数据采集的3个关键策略(附线程安全队列代码)

工业级串口数据采集&#xff1a;Qt高可靠通信架构设计与实战 在工业自动化与物联网设备监控领域&#xff0c;数据采集的可靠性直接关系到系统决策的准确性。我曾参与过一个风电监测项目&#xff0c;现场振动传感器通过RS485串口每秒上传2000个采样点&#xff0c;但初期版本的数…...

Spring Cloud服务熔断与降级

咱们今天不讲童话&#xff0c;咱们讲“系统保命学”。在微服务架构里&#xff0c;服务之间就像是一群互相借钱的酒肉朋友。平时你好我好大家好&#xff0c;一旦有个“朋友”&#xff08;服务A&#xff09;破产了&#xff08;挂了&#xff09;或者赖账&#xff08;超时&#xff…...

终极指南:Hotkey Detective - 3步揪出Windows热键冲突的“幕后黑手“

终极指南&#xff1a;Hotkey Detective - 3步揪出Windows热键冲突的"幕后黑手" 【免费下载链接】hotkey-detective A small program for investigating stolen key combinations under Windows 7 and later. 项目地址: https://gitcode.com/gh_mirrors/ho/hotkey-d…...

深入解析AXI VDMA:视频流高效传输的关键技术

1. AXI VDMA&#xff1a;视频处理的"高速公路收费站" 想象一下早晚高峰的城市环线&#xff0c;成千上万辆汽车需要有序通过收费站。AXI VDMA&#xff08;Video Direct Memory Access&#xff09;在视频处理系统中扮演的角色&#xff0c;就像这个智能收费站系统——它…...