Flutter时间线展示插件flutter_timeline_v2的使用
Flutter时间线展示插件flutter_timeline_v2的使用
framework: flutter
platform: Android, iOS, Web, macOS, Linux, Windows
tags: flutter, timeline, flutter timeline v2, timeline tile
title: flutter timeline v2
flutter_timeline
[logo]
该插件基于gridaco的flutter_timeline
包创建。我只是为了Flutter社区保持其更新。
a fully customizable & general timeline widget, based on real-world application references
Installation
在pubspec.yaml
文件中添加以下依赖:
dependencies:
flutter_timeline_v2: latest
usage
简单示例
// 定义一个简单的事件显示方式
TimelineEventDisplay get plainEventDisplay {
return TimelineEventDisplay(
child: TimelineEventCard(
title: Text("just now"),
content: Text("someone commented on your timeline ${DateTime.now()}"),
),
indicator: TimelineDots.of(context).circleIcon);
}
List<TimelineEventDisplay> events;
Widget _buildTimeline() {
return TimelineTheme(
data: TimelineThemeData(lineColor: Colors.blueAccent), // 设置时间轴线条颜色
child: Timeline(
indicatorSize: 56, // 设置指示器大小
events: events, // 设置事件列表
));
}
void _addEvent() {
setState(() {
events.add(plainEventDisplay); // 添加新事件
});
}
使用偏移量
Widget _buildTimeline() {
return Timeline(
indicatorSize: 56,
events: events,
altOffset: Offset(0, -24) // 设置偏移量
);
}
使用锚点和偏移量
TimelineEventDisplay get plainEventDisplay {
return TimelineEventDisplay(
anchor: IndicatorPosition.top, // 设置锚点位置
indicatorOffset: Offset(0, 24), // 设置偏移量
child: TimelineEventCard(
title: Text("multi\nline\ntitle\nawesome!"), // 设置多行标题
content: Text("someone commented on your timeline ${DateTime.now()}"), // 设置内容
),
indicator: randomIndicator); // 设置指示器
}
更多关于Flutter时间线展示插件flutter_timeline_v2的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复