当前位置:网站首页>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(),
));
边栏推荐
猜你喜欢

【斯坦福计网CS144项目】Lab5: NetworkInterface

2022第十一届财经峰会:优炫软件斩获双项大奖

I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing
思源笔记 本地存储无使用第三方同步盘,突然打不开文件。

Jmeter secondary development to realize rsa encryption

Find My技术|智能防丢还得看苹果Find My技术

The latest real software test interview questions are shared. Are you afraid that you will not be able to enter the big factory after collecting them?

Database auditing - an essential part of network security

C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】

令人心动的AI综述(1)
随机推荐
科研用Cholesterol-PEG-NHS,NHS-PEG-CLS,胆固醇-聚乙二醇-活性酯
我们来浅谈代码语言的魅力
非关系型数据库MongoDB简介和部署
程序员如何优雅地解决线上问题?
一文读懂 Web 3.0 应用架构
HCIP(16)
别再到处乱放配置文件了!我司使用 7 年的这套解决方案,稳的一秕
APT级全面免杀拿Shell
Find My技术|智能防丢还得看苹果Find My技术
2022山东国际青少年眼睛健康产业展会,视力健康展,眼视光展
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了
markdown语法
scala 集合通用方法
R语言自学 1 - 向量
Week 7 - Distributional Representations
嵌入式分享合集26
十二、form表单的提交
数字化转型巨浪拍岸,成长型企业如何“渡河”?
Week 7 - Distributional Representations(分布表示)
Merge two excel spreadsheet tools