当前位置:网站首页>flutter 每天一背,需要掌握
flutter 每天一背,需要掌握
2022-08-10 02:37:00 【氤氲息】
1.基本类怎么写的,init和dispose里面的内容都写在super.前面
2.json解析类怎么写的,基本类型,范类,列表
3.EventBus怎么用的,发送消息,监听,注销
4.弹窗怎么写的,两种方式,中间弹出来的showDialog,还有从屏幕下面弹起来的showModalBottomSheet
5. 列表怎么写,嵌套在滑动列表里面的列表,缺省图,滑动控制器,下拉刷新
6. switch case怎么写,switch(){},:;;
7. 创建一个空列表,可增加长度类型的List? currentMessageList = List.empty(growable: true);,根据创建时间来排序currentMessageList?.sort((a, b) => a.createTime!.compareTo(b.createTime!));
8. provider,填数据,刷新数据,获取数据,对象和列表两种方式
如果是对象:
//填数据
DriftBottleSetting? driftBottleSetting;//这个是服务器返回的数据
Provider.of<providers>(Global.appContext,listen:false).getDriftBottleSetting(driftBottleSetting!);
//刷新数据
class providers extends ChangeNotifier{
DriftBottleSetting? driftBottleSetting;
get _driftBottleSetting =>driftBottleSetting;
getDriftBottleSetting(DriftBottleSetting driftBottleSetting){
driftBottleSetting=driftBottleSetting;
notifyListeners();
return driftBottleSetting;
}
clear() {
_driftBottleSetting=null;//一般在登录的时候会调用一次清楚数据,通过:Provider.of<SlideMatchModel>(context, listen: false).clear();
notifyListeners();
}
}
//获取数据
DriftBottleSetting? driftBottleSetting;
driftBottleSetting=Provider.of<providers>(context,listen: false).driftBottleSetting;//在build里面写
}
如果是列表也是同样的操作
//刷新数据类
import 'package:flutter/foundation.dart';
import '../pages/driftBottleGame/data/reply_list.dart';
class BottleProvider with ChangeNotifier, DiagnosticableTreeMixin{
List<DownList>? currentMessageList = List.empty(growable: true);
addDownList(List<DownList>? downLists){
if(downLists!.isNotEmpty) {
currentMessageList?.addAll(downLists);
}
currentMessageList?.sort((a, b) => a.createTime!.compareTo(b.createTime!));
notifyListeners();
}
clear(){
currentMessageList?.clear();
// notifyListeners();
}
}
//在initState先清空数据
Provider.of<BottleProvider>(context,listen: false).clear();
//在网络请求处获取到数据后填充数据
Provider.of<BottleProvider>(context,listen: false).addDownList(currentMessageList);//currentMessageList就是获得的数据
//在build处使用数据
List<DownList>? currentMessageList = Provider.of<BottleProvider>(context,listen: true).currentMessageList;
9.时间戳转日期
String getMessageTime() {
String time = '';
int timestamp = downList.createTime! * 1000;
DateTime timeDate = DateTime.fromMillisecondsSinceEpoch(timestamp);
DateTime now = DateTime.now();
if (now.day == timeDate.day) {
time =
"${timeDate.hour.toString().padLeft(2, '0')}:${timeDate.minute.toString().padLeft(2, '0')}:${timeDate.second.toString().padLeft(2, '0')}";
} else {
time =
"${timeDate.month.toString().padLeft(2, '0')}-${timeDate.day.toString().padLeft(2, '0')} ${timeDate.hour.toString().padLeft(2, '0')}:${timeDate.minute.toString().padLeft(2, '0')}:${timeDate.second.toString().padLeft(2, '0')}";
}
return time;
}
10.列表的另外一个写法
Column(
key: _containerKey,
children:
(currentMessageList == null || currentMessageList.length == 0)
? [Container()]: replyList == null
? [Container()]
: currentMessageList.map((e) => MsgContainer(replyList: replyList!,downList: e,)).toList(),
)//意思就是将列表里面的数据进行排成列表,根据list里面的长度进行排成列表,数据就是e,MsgContainer是单个item的样式
边栏推荐
- 第三章 搜索与图论(二)
- 2022.8.8考试清洁工老马(sweeper)题解
- 数据挖掘和数据仓库之间的区别
- MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
- MMDetection框架的anchor_generators.py解析
- 剑指offer专项突击版第25天
- 【二叉树-简单】112. 路径总和
- 当我操作dms客户端的时候,我要操控好几个阿里云账号下的数据库,但是这边每次切换都会把我的登录记录删
- [Red Team] ATT&CK - Auto Start - Registry Run Key, Startup Folder
- exchange2010 邮件数据库无法装入
猜你喜欢

IDEA自动生成serialVersionUID

excel高级绘图技巧100讲(二十三)-Excel中实现倒计时计数

实测办公场景下,国产远程控制软件的表现力如何?(技术解析)

In automated testing, test data is separated from scripts and parameterized methods

Difference Between Data Mining and Data Warehousing

【二叉树-中等】687. 最长同值路径

MMDetection框架的anchor_generators.py解析

【二叉树-简单】112. 路径总和

实例048:数字比大小

NFG电商系统在元宇宙趋势下做什么?
随机推荐
网路编程_调试accept
官宣出自己的博客啦
flink 12 源码编译及使用idea运行、debug
是什么让训练综合分类网络艰苦?
vite基础,vite中 `@`符号是不被支持,不用@符号,直接用层级(./,../等)
数据挖掘和数据仓库之间的区别
跨站请求伪造(CSRF)攻击是什么?如何防御?
6 common plugin recommendations in Pycharm
2022.8.8 Exam questions for photographer Lao Ma (photographer)
2022.8.9考试平衡的余数--1000题解
Data Governance (5): Metadata Management
单体架构应用和分布式架构应用的区别
【二叉树-中等】2265. 统计值等于子树平均值的节点数
Chip Accelerator
Error state based Kalman filter ESKF
2022.8.8 Exam area link (district) questions
【二叉树-中等】508. 出现次数最多的子树元素和
实例044:矩阵相加
2022.8.8考试从记忆中写入(memory)题解
2022.8.9考试独特的投标拍卖--800题解