Skip to content

Commit

Permalink
✅ added alt offset feature (1/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
softmarshmallow committed Aug 31, 2020
1 parent f84fde3 commit 218ec68
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.4+4"
version: "0.0.4+6"
matcher:
dependency: transitive
description:
Expand Down
35 changes: 24 additions & 11 deletions lib/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class Timeline extends StatelessWidget {
this.indicatorSize = 12.0,
// item gap will be ignored when custom separatorBuilder is provided
this.separatorBuilder,
this.altOffset = const Offset(0, 0),
}) : itemCount = events.length;

final Offset altOffset;
final List<TimelineEventDisplay> events;
final double indicatorSize;
final bool isLeftAligned;
Expand Down Expand Up @@ -73,9 +75,10 @@ class Timeline extends StatelessWidget {
}

Widget buildWrappedIndicator(Widget child, {double width, double height}) {
return SizedBox(
return Container(
width: width,
height: height,
transform: Matrix4.translationValues(altOffset.dx, altOffset.dy, 0.0),
child: child,
);
}
Expand All @@ -100,14 +103,13 @@ class Timeline extends StatelessWidget {
strokeWidth: theme.strokeWidth,
style: theme.style,
itemGap: theme.itemGap,
altOffset: altOffset,
),
// size: const Size(double.infinity, double.infinity),
child: SizedBox(height: double.infinity, width: indicatorSize),
);
return Stack(
children: [
line,
// align the indicator to the center
Positioned.fill(
child: Align(
alignment: Alignment.center,
Expand All @@ -126,6 +128,7 @@ class _LineIndicatorPainter extends CustomPainter {
_LineIndicatorPainter({
@required this.hideDefaultIndicator,
@required this.indicatorSize,
@required this.altOffset,
@required this.maxIndicatorSize,
@required this.lineGap,
@required this.strokeCap,
Expand All @@ -141,6 +144,7 @@ class _LineIndicatorPainter extends CustomPainter {
..strokeWidth = strokeWidth
..style = style;

final Offset altOffset;
final bool hideDefaultIndicator;
final double indicatorSize;
final double maxIndicatorSize;
Expand All @@ -160,20 +164,29 @@ class _LineIndicatorPainter extends CustomPainter {
final maxIndicatorRadius = maxIndicatorSize / 2;
final indicatorMargin = indicatorRadius + lineGap;
final safeItemGap = (indicatorSize / 2) + lineGap;
final altY = altOffset.dy;

final top = size.topLeft(Offset(maxIndicatorRadius, 0.0 - safeItemGap));
final centerTop = size.centerLeft(
Offset(maxIndicatorRadius, -indicatorMargin),
// todo
// calculate starting point
// calculate alt point
// use alt point as default point

final top =
size.topLeft(Offset(maxIndicatorRadius, 0.0 - safeItemGap + altY));
final topOfCenter = size.centerLeft(
Offset(maxIndicatorRadius, -indicatorMargin + altY),
);

final bottom =
size.bottomLeft(Offset(maxIndicatorRadius, 0.0 + safeItemGap));
final centerBottom = size.centerLeft(
Offset(maxIndicatorRadius, indicatorMargin),
size.bottomLeft(Offset(maxIndicatorRadius, 0.0 + safeItemGap + altY));
final bottomOfCenter = size.centerLeft(
Offset(maxIndicatorRadius, indicatorMargin + altY),
);

if (!isFirst) canvas.drawLine(top, centerTop, linePaint);
if (!isLast) canvas.drawLine(centerBottom, bottom, linePaint);
// if not first, draw top-to-center upper line
if (!isFirst) canvas.drawLine(top, topOfCenter, linePaint);
// if not last, draw center-to-bottom bottom line
if (!isLast) canvas.drawLine(bottomOfCenter, bottom, linePaint);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_timeline
description: a fully customizable & general timeline widget, based on real-world application references
version: 0.0.4+5
version: 0.0.4+6
homepage: https://github.com/softmarshmallow/flutter-timeline
repository: https://github.com/softmarshmallow/flutter-timeline

Expand Down

0 comments on commit 218ec68

Please sign in to comment.