Skip to content

Commit

Permalink
Merge pull request #20 from stijn1989/master
Browse files Browse the repository at this point in the history
Gap between timeline children
  • Loading branch information
furkantektas authored Oct 18, 2024
2 parents 27c8354 + 8eed0d4 commit e386986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/src/timeline_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _TimelinePainterCenter extends _TimelinePainter {
configuration.size?.center(Offset(0.0, offset.dy - iconSize / 2 - 2 * TimelineBoxDecoration.LINE_GAP));
final Offset? bottomLineStart =
configuration.size?.center(Offset(0.0, offset.dy + iconSize / 2 + 2 * TimelineBoxDecoration.LINE_GAP));
final Offset? offsetBottom = configuration.size?.bottomCenter(Offset(0.0, offset.dy * 2));
final Offset? offsetBottom = configuration.size?.bottomCenter(Offset(0.0, offset.dy * 2 + properties.gap));
if (!isFirst && offsetTop != null && topLineEnd != null) canvas.drawLine(offsetTop, topLineEnd, linePaint);
if (!isLast && bottomLineStart != null && offsetBottom != null)
canvas.drawLine(bottomLineStart, offsetBottom, linePaint);
Expand Down Expand Up @@ -128,7 +128,7 @@ class _TimelinePainterLeft extends _TimelinePainter {
final Offset? top = configuration.size?.topLeft(Offset(leftOffset.dx, 0.0));
final Offset? centerTop = configuration.size?.centerLeft(Offset(leftOffset.dx, leftOffset.dy - iconMargin));
final Offset? centerBottom = configuration.size?.centerLeft(Offset(leftOffset.dx, leftOffset.dy + iconMargin));
final Offset? end = configuration.size?.bottomLeft(Offset(leftOffset.dx, leftOffset.dy * 2));
final Offset? end = configuration.size?.bottomLeft(Offset(leftOffset.dx, leftOffset.dy * 2 + properties.gap));
if (!isFirst && top != null && centerTop != null) canvas.drawLine(top, centerTop, linePaint);
if (!isLast && centerBottom != null && end != null) canvas.drawLine(centerBottom, end, linePaint);

Expand Down Expand Up @@ -162,7 +162,7 @@ class _TimelinePainterRight extends _TimelinePainter {
final Offset? top = configuration.size?.topRight(Offset(rightOffset.dx, 0.0));
final Offset? centerTop = configuration.size?.centerRight(Offset(rightOffset.dx, rightOffset.dy - iconMargin));
final Offset? centerBottom = configuration.size?.centerRight(Offset(rightOffset.dx, rightOffset.dy + iconMargin));
final Offset? end = configuration.size?.bottomRight(Offset(rightOffset.dx, rightOffset.dy * 2));
final Offset? end = configuration.size?.bottomRight(Offset(rightOffset.dx, rightOffset.dy * 2 + properties.gap));
if (!isFirst && top != null && centerTop != null) canvas.drawLine(top, centerTop, linePaint);
if (!isLast && centerBottom != null && end != null) canvas.drawLine(centerBottom, end, linePaint);

Expand Down
14 changes: 9 additions & 5 deletions lib/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class TimelineProperties {
final Color lineColor;
final double lineWidth;
final double iconSize;
final double gap;

const TimelineProperties({Color? lineColor, double? lineWidth, double? iconSize})
const TimelineProperties({Color? lineColor, double? lineWidth, double? iconSize, double? gap})
: lineColor = lineColor ?? const Color(0xFF333333),
lineWidth = lineWidth ?? 2.5,
iconSize = iconSize ?? TimelineBoxDecoration.DEFAULT_ICON_SIZE;
iconSize = iconSize ?? TimelineBoxDecoration.DEFAULT_ICON_SIZE,
gap = gap ?? 0.0;
}

class Timeline extends StatelessWidget {
Expand All @@ -40,6 +42,7 @@ class Timeline extends StatelessWidget {
Color? lineColor,
double? lineWidth,
double? iconSize,
double? gap,
this.controller,
this.position = TimelinePosition.Center,
this.physics,
Expand All @@ -48,7 +51,7 @@ class Timeline extends StatelessWidget {
this.reverse = false})
: itemCount = children.length,
properties = TimelineProperties(
lineColor: lineColor, lineWidth: lineWidth, iconSize: iconSize),
lineColor: lineColor, lineWidth: lineWidth, iconSize: iconSize, gap: gap),
itemBuilder = ((BuildContext context, int i) => children[i]);

/// Creates a scrollable timeline of widgets that are created on demand.
Expand All @@ -61,13 +64,14 @@ class Timeline extends StatelessWidget {
Color? lineColor,
double? lineWidth,
double? iconSize,
double? gap,
this.position = TimelinePosition.Center,
this.physics,
this.shrinkWrap = false,
this.primary = false,
this.reverse = false})
: properties = TimelineProperties(
lineColor: lineColor, lineWidth: lineWidth, iconSize: iconSize);
lineColor: lineColor, lineWidth: lineWidth, iconSize: iconSize, gap: gap);

@override
Widget build(BuildContext context) {
Expand All @@ -88,7 +92,7 @@ class Timeline extends StatelessWidget {
return Material(
child: InkWell(
onTap: model.onTap as void Function()?,
child: child(properties, model),
child: Container(child: child(properties, model), margin: EdgeInsets.only(bottom: properties.gap)),
),
);
});
Expand Down

0 comments on commit e386986

Please sign in to comment.