当前位置:网站首页>flutter 每个要注意的点
flutter 每个要注意的点
2022-08-02 23:19:00 【氤氲息】
列表
1.数据为空时的提示语
return MaterialApp(
color: Colors.transparent,
home: widget.upList.isEmpty?Column(//如果是空的就返回文字:暂无数据
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
alignment: Alignment.center,
child: Container(
margin: const EdgeInsets.only(bottom: 120),
child: Column(children: [
ContentText(S.current.bottle_no_data, 14.0,
CommonColors.getTextWeakColor()),
TopPadding(30),
])),
)
],
):Scaffold()//如果有数据就返回这个里面的内容
2.要判断列表数据是否为空
child: MediaQuery.removePadding(
removeTop: true,
context: context,
child: widget.upList.isEmpty//如果数据为空就显示Container(),如果有内容就显示列表数据
? Container()
: ListView.builder(
shrinkWrap: true,
itemCount: widget.upList.length,
itemBuilder: (BuildContext context, int index) {
BottleModel upList = widget.upList[index];
return GestureDetector(
onTap: () {
if (widget.onItemClicked != null) {
widget.onItemClicked!(index);
//延时
Future.delayed(const Duration(milliseconds: 500), () {
EventBusUtil.fire(
OnCloseBottleRefresh(CloudCustomDataBean.TYPE_DRIFT_BOTTLE));
});
}
},
child: Stack(
alignment: Alignment.topRight,
children: [
if (index % 3 == 2)
Container(
width: width,
margin: const EdgeInsets.only(
top: 16, left: 16, right: 16),
padding: const EdgeInsets.only(
left: 16, top: 16, bottom: 8, right: 16),
decoration: BoxDecoration(
color: const Color(0xFFFBFFF2),
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(
color: Color(0xFFDBEBB6),
blurRadius: 1,
),
],
),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
upList.text!,
style: const TextStyle(
color: Color(0xFF333333),
fontSize: 18),
),
Container(
margin: const EdgeInsets.only(top: 8),
child: Text(
DateUtil.formatDateMs(
upList.downTime! * 1000,
format: 'yyyy.MM.dd'),
style: const TextStyle(
color: Color(0xFF999999),
fontSize: 12),
),
)
],
),
),
Positioned(
top: 7,
right: 15,
child: showMessageNumView(upList.noReadNum),
)
],
),
);
})),
3.下拉分页加载
final ScrollController _scrollController = ScrollController();
bool _hasMore = true;
bool _isLoad = false;
int pageSize =20;
@override
void initState() {
super.initState();
// 监听滚动事件
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
//达到最大滚动位置
_isLoad = true;
if (_hasMore && _isLoad) {
DownList? downList = currentMessageList?.last;
_getReplyList(
driftBottleId: downList?.driftBottleId,
pageTime: downList?.createTime,
status: 1,);
}
}
});
WidgetsBinding.instance!.addPostFrameCallback(_afterLayout);
}
SingleChildScrollView(
controller: _scrollController,
reverse: currentMessageList!.length >= 6
? true
: cloumHeight >= Global.screenHeight - 100, //注意设置为反向
padding: const EdgeInsets.fromLTRB(12, 0, 12, 0),
child: Column(
key: _containerKey,
children:
(currentMessageList == null || currentMessageList.length == 0)
? [Container()]: replyList == null
? [Container()]
: currentMessageList.map((e) => MsgContainer(replyList: replyList!,downList: e,)).toList(),
));
边栏推荐
- CAS:1445723-73-8,DSPE-PEG-NHS,磷脂-聚乙二醇-活性酯两亲性脂质PEG共轭物
- 谷歌 Chrome 浏览器 104 正式版发布:加快网页加载,蓝牙 API 改进
- No code development platform data ID introductory tutorial
- 脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
- What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
- 基于两级分解和长短时记忆网络的短期风速多步组合预测模型
- ORA-55610: Invalid DDL statement on history-tracked table
- 测试人生 | 阿里实习 90 天:从实习生的视角谈谈个人成长
- js基础知识整理之 —— Date和定时器
- 程序员英语自我介绍
猜你喜欢
随机推荐
MySQL的多表查询(1)
CIO修炼手册:成功晋升CIO的七个秘诀
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了
CKAN教程之在 AWS 上部署 CKAN 应用程序
WAF WebShell Trojan free to kill
程序员英语自我介绍
谷歌 Chrome 浏览器 104 正式版发布:加快网页加载,蓝牙 API 改进
Week 7 CNN Architectures - LeNet-5、AlexNet、VGGNet、GoogLeNet、ResNet
No-code development platform form styling steps introductory course
KubeSphere监控失效为NAN的问题
msys2下载地址
What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
基于奇异谱分析法和长短时记忆网络组合模型的滑坡位移预测
LVM与磁盘配额原理及配置
停止使用 Storyboards 和 Interface Builder
# DWD层及DIM层构建## ,220801 ,
js基础知识整理之 —— 全局作用域
Mock工具之Moco使用教程
典型相关分析CCA计算过程
令人心动的AI综述(1)








