当前位置:网站首页>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的样式
边栏推荐
- 元宇宙+NFT是“宝”还是“炒”
- 【二叉树-中等】2265. 统计值等于子树平均值的节点数
- What makes training multi-modal classification networks hard?
- 想要避免After Effects渲染失败的问题,5个小技巧必看
- 【Image Classification】2022-ResMLP
- LeetCode每日两题02:两数之和 II - 输入有序数组 (均1200道)
- HRnet
- 兴业数金一面
- 【Kali安全渗透测试实践教程】第9章 无线网络渗透
- 2022.8.8 Exam questions for photographer Lao Ma (photographer)
猜你喜欢
【Kali安全渗透测试实践教程】第8章 Web渗透
vite基础,vite中 `@`符号是不被支持,不用@符号,直接用层级(./,../等)
Difference Between Data Mining and Data Warehousing
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
论文理解:“PIAT: Physics Informed Adversarial Training for Solving Partial Differential Equations“
高精度加法
新零售社交电商APP系统平台如何打造公域+私域流量?
如何编写一份优质的测试用例?
How to write a high-quality test case?
NFG电商系统在元宇宙趋势下做什么?
随机推荐
跨站请求伪造(CSRF)攻击是什么?如何防御?
【语义分割】2022-HRViT CVPR
单体架构应用和分布式架构应用的区别
实例044:矩阵相加
[Kali Security Penetration Testing Practice Course] Chapter 7 Privilege Escalation
Robust Real-time LiDAR-inertial Initialization(实时鲁棒的LiDAR惯性初始化)论文学习
实例047:函数交换变量
PC摄像头设置 默认摄像头设置 win11 默认摄像头设置
what is eabi
The 25th day of the special assault version of the sword offer
2022.8.9考试排列变换--1200题解
[8.8] Code Source - [Non-falling subarray game] [Longest rising subsequence count (Bonus)] [Substring (data enhanced version)]
量化交易策略介绍及应用市值中性化选股
Research on IC enterprises
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
2022.8.9考试游记总结
How to write a high-quality test case?
[Kali Security Penetration Testing Practice Tutorial] Chapter 6 Password Attack
【CC3200AI 实验教程5】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-定时器
2022.8.8考试从记忆中写入(memory)题解