当前位置:网站首页>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的样式
边栏推荐
- what is eabi
- Example 045: Summation
- Little rookie Hebei Unicom induction training essay
- 第三章 搜索与图论(二)
- Example 046: Breaking the Cycle
- what is a microcontroller or mcu
- 官宣出自己的博客了
- 流星加速器木马分析与处置方案
- MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
- 论旅行之收获
猜你喜欢
【CC3200AI 实验教程5】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-定时器
flex 的 三个参数:flex-grow、flex-shrink、flex-basis
Meteor accelerator Trojan analysis and disposal plan
推荐几款好用的MySQL开源客户端,建议收藏
Example 044: Matrix Addition
新零售社交电商APP系统平台如何打造公域+私域流量?
【图像分类】2022-CycleMLP ICLR
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
liunx PS1 设置
The Evolutionary History of the "Double Gun" Trojan Horse Virus
随机推荐
vite基础,vite中 `@`符号是不被支持,不用@符号,直接用层级(./,../等)
Introduction and application of quantitative trading strategies
HRnet
数据挖掘和数据仓库之间的区别
web crawler error
【二叉树-中等】1261. 在受污染的二叉树中查找元素
Meteor accelerator Trojan analysis and disposal plan
excel高级绘图技巧100讲(二十三)-Excel中实现倒计时计数
剑指offer专项突击版第25天
是什么让训练综合分类网络艰苦?
【图像分类】2022-ResMLP
实例043:作用域、类的方法与变量
State compression small experience
实例044:矩阵相加
【Kali安全渗透测试实践教程】第6章 密码攻击
推荐几款好用的MySQL开源客户端,建议收藏
How to write a high-quality test case?
PC摄像头设置 默认摄像头设置 win11 默认摄像头设置
HackTheBox——Beep
LeetCode每日两题02:两数之和 II - 输入有序数组 (均1200道)