当前位置:网站首页>The scroll up and down switch of the flutter text is used to prompt the announcement message
The scroll up and down switch of the flutter text is used to prompt the announcement message
2022-07-18 21:59:00 【Young people who get up early】
Results the preview

1 Basic use code
void main() {
/// Start the root directory
runApp(MaterialApp(
home: TestTipsPage(),
));
}
class TestTipsPage extends StatefulWidget {
@override
_TestTipsPageState createState() => _TestTipsPageState();
}
class _TestTipsPageState extends State<TestTipsPage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Container(
alignment: Alignment.center,
width: double.infinity,
height: 24,
child: buildMarqueeWidget(),
),
),
);
}
}
2 Core use code
MarqueeWidget buildMarqueeWidget(List<String> loopList) {
/// Rotate up and down Safety tips
return MarqueeWidget(
// Son Item Builder
itemBuilder: (BuildContext context, int index) {
String itemStr = loopList[index];
// It can usually be a Text Text
return Text(itemStr);
},
// Number of circular prompt messages
count: loopList.length,
);
}
3 Core implementation code
import 'dart:async';
import 'package:flutter/cupertino.dart';
// News rotation rolling up and down
class MarqueeWidget extends StatefulWidget {
/// Number of subviews
final int count;
/// Subview builder
final IndexedWidgetBuilder itemBuilder;
/// Time interval of rotation
final int loopSeconds;
const MarqueeWidget({
Key? key,
required this.count,
required this.itemBuilder,
this.loopSeconds = 5,
}) : super(key: key);
@override
_MarqueeWidgetState createState() => _MarqueeWidgetState();
}
class _MarqueeWidgetState extends State<MarqueeWidget> {
late PageController _controller;
late Timer _timer;
@override
void initState() {
super.initState();
_controller = PageController();
_timer = Timer.periodic(Duration(seconds: widget.loopSeconds), (timer) {
if (_controller.page != null) {
// If you are currently on the last page , Then jump directly to the first page , The two contents are the same , There is no visual perception when jumping
if (_controller.page!.round() >= widget.count) {
_controller.jumpToPage(0);
}
_controller.nextPage(
duration: const Duration(seconds: 1), curve: Curves.linear);
}
});
}
@override
Widget build(BuildContext context) {
return PageView.builder(
scrollDirection: Axis.vertical,
controller: _controller,
itemBuilder: (buildContext, index) {
if (index < widget.count) {
return widget.itemBuilder(buildContext, index);
} else {
return widget.itemBuilder(buildContext, 0);
}
},
itemCount: widget.count + 1,
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
_timer.cancel();
}
}
边栏推荐
- conda安装requirement.txt指定的依赖包
- LETV has become the king of anti involution: employees have lived a fairy life without 996!
- Installing MySQL database on Linux server (detailed tutorial)
- [PHP code audit] Introduction analysis of vulnerabilities in Pikachu shooting range
- Downlink power distribution technology of synaesthesia integrated system
- MySQL notes: the latest tutorial of song Hongkang at site B (under continuous update)
- AcWing 396. 矿场搭建 题解(tarjan割点)
- Everything you need to know about cognitive analysis
- 低代码平台搭建学生事务一门式管理系统解决方案
- 低代码如何助力非标零售业务新增长案例分析
猜你喜欢

网络基础VlAN配置 Trunk技术(eNSP、Cisco)

数字员工未来可期?盘点RPA在八大行业领域的应用案例

机器学习实战运用:速刷牛客5道机器学习题目

AcWing 396. 矿场搭建 题解(tarjan割点)

AcWing 396. Solution to the problem of mine construction (tarjan cut point)
[original] migration of rm500u-cn module driver

Istio灰度发布:部署Bookinfo微服务项目

SQL notes

ES6-新增的数组方法之最常用的几种 map(),filter(),reduce(),forEach(),

FreeSwitch的限流配置
随机推荐
How to use mitmproxy to get data return in automated testing?
通感一体化融合架构及关键技术
Backup MySQL database on Linux server (detailed tutorial)
Key technologies and challenges of communication perception integration
Linux服务器上备份mysql数据库(详细教程)
Flutter 文字上下滚动切换 用于公告消息提示
PyQt5-字体对话框(QFontDialog)
The upgraded ranking activity is hot again. Looking around, it's full of bonuses
升级版打榜活动再次火热袭来,放眼望去全是奖金
Istio灰度發布:部署Bookinfo微服務項目
Istio gray Publishing: deploy bookinfo microservice project
信息收集
[PHP code audit] Introduction analysis of vulnerabilities in Pikachu shooting range
通信感知一体化关键技术与挑战
Localstorage, sessionstorage string or number considerations
华为和荣耀手机升级鸿蒙系统之后与matebook无法多屏协同的问题
Leetcode 1309. 解码字母到整数映射(可以,一次过)
Publication en niveaux de gris istio: déploiement du projet de microservice bookinfo
AcWing 1183. Power problem solution (double connected components and cut points of undirected graph)
openGauss数据库