Skip to content

Commit

Permalink
🔥 0.1.1+12 release
Browse files Browse the repository at this point in the history
  • Loading branch information
softmarshmallow committed Sep 3, 2020
1 parent ddf176b commit 772a0cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 75 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Timeline(
altOffset: Offset(0, -24),
// ...
);
```
```
## [0.1.1+12] - supports anchor & offset for timeline & indicator
5 changes: 3 additions & 2 deletions example/lib/screen/plain_timeline_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _PlainTimelineDemoScreenState extends State<PlainTimelineDemoScreen> {

TimelineEventDisplay get plainEventDisplay {
return TimelineEventDisplay(
indicatorPosition: IndicatorPosition.top,
anchor: IndicatorPosition.top,
indicatorOffset: Offset(0, 24),
child: TimelineEventCard(
title: Text("multi\nline\ntitle\nawesome!"),
Expand All @@ -96,8 +96,9 @@ class _PlainTimelineDemoScreenState extends State<PlainTimelineDemoScreen> {
data: TimelineThemeData(
lineColor: Colors.blueAccent, itemGap: 100, lineGap: 0),
child: Timeline(
indicatorPosition: IndicatorPosition.center,
anchor: IndicatorPosition.center,
indicatorSize: 56,
altOffset: Offset(10, 40),
events: events,
));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/event_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TimelineEventDisplay {
this.indicator,
this.indicatorSize,
this.forceLineDrawing = false,
this.indicatorPosition,
this.anchor,
this.indicatorOffset = const Offset(0, 0),
});

Expand All @@ -21,8 +21,8 @@ class TimelineEventDisplay {
/// enables indicator line drawing even no indicator is passed.
final bool forceLineDrawing;

/// [indicatorPosition] overrides the default IndicatorPosition
final IndicatorPosition indicatorPosition;
/// [anchor] overrides the default IndicatorPosition
final IndicatorPosition anchor;
final Offset indicatorOffset;

bool get hasIndicator {
Expand Down
112 changes: 44 additions & 68 deletions lib/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Timeline extends StatelessWidget {
// item gap will be ignored when custom separatorBuilder is provided
this.separatorBuilder,
this.altOffset = const Offset(0, 0),
this.indicatorPosition = IndicatorPosition.center})
this.anchor = IndicatorPosition.center})
: itemCount = events.length;

final Offset altOffset;
Expand All @@ -35,8 +35,8 @@ class Timeline extends StatelessWidget {
final bool primary;
final bool reverse;

/// [indicatorPosition] describes where the indicator drawing should start. use it with alt offset
final IndicatorPosition indicatorPosition;
/// [anchor] describes where the indicator drawing should start. use it with alt offset
final IndicatorPosition anchor;

final IndexedWidgetBuilder separatorBuilder;

Expand Down Expand Up @@ -65,7 +65,6 @@ class Timeline extends StatelessWidget {
if (index != events.length - 1) {
nextEvent = events[index + 1];
}
print(index);
final isFirst = index == 0;
final isLast = index == itemCount - 1;
final timelineTile = <Widget>[
Expand Down Expand Up @@ -119,9 +118,8 @@ class Timeline extends StatelessWidget {
TimelineThemeData theme}) {
final overrideIndicatorSize =
event.indicatorSize != null ? event.indicatorSize : indicatorSize;
final overrideIndicatorPosition = event.indicatorPosition != null
? event.indicatorPosition
: indicatorPosition;
final overrideIndicatorPosition =
event.anchor != null ? event.anchor : anchor;
final indicatorOffset = event.indicatorOffset;

var line = CustomPaint(
Expand Down Expand Up @@ -217,19 +215,9 @@ class _LineIndicatorPainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
// indicator's radius
final radius = indicatorSize / 2;
final indicatorMargin = radius + lineGap;
final safeItemGap = radius + itemGap;
final height = size.height;
final halfHeight = height / 2;
final safeHalfHeight = halfHeight - radius;
final double halfItemGap = itemGap / 2;
double topStartY = 0.0;

var testLinePaint = Paint()
..color = Colors.red
..strokeCap = strokeCap
..strokeWidth = strokeWidth
..style = style;

// initial start point
// works well
Expand All @@ -246,17 +234,14 @@ class _LineIndicatorPainter extends CustomPainter {
break;
}

print("indicatorCenterStartPoint : $indicatorCenterStartPoint");

// alt start point
Offset indicatorCenter = indicatorCenterStartPoint.translate(altX, altY);
print("indicatorCenter : $indicatorCenter");

// region upper line
if (!isFirst) {
double additionalGap = 0;
if (!prevHasIndicator) additionalGap = halfItemGap;
final additionalTop = getAdditionalY(height);
final additionalTop = getAdditionalY(height, mode: "upper");

// works well
Offset topStart = indicatorCenter.translate(
Expand All @@ -271,7 +256,7 @@ class _LineIndicatorPainter extends CustomPainter {
));

// works well
Offset topEnd = indicatorCenter.translate(0, -radius);
Offset topEnd = indicatorCenter.translate(0, -radius - lineGap);

// draw upper line
if (!isFirst) canvas.drawLine(topStart, topEnd, linePaint);
Expand All @@ -283,49 +268,58 @@ class _LineIndicatorPainter extends CustomPainter {
double additionalGap = 0;
if (!nextHasIndicator) additionalGap = halfItemGap;

final additionalBottom = getAdditionalY(height);
final additionalBottom = getAdditionalY(height, mode: "downer");

// works well
Offset bottomEnd = indicatorCenter.translate(
0,
// the altY + radius is the default start point.
// adding half item gap is also by default.
// the below two items does not get affected by the indicator position
(((-altY + radius) + halfItemGap) //
(radius + halfItemGap - altY) +
(additionalGap) //
+
(additionalGap) +
(additionalBottom) //
));
);

// works well
Offset bottomStart = indicatorCenter.translate(0, -radius);
// if (!isLast) canvas.drawLine(bottomStart, bottomEnd, testLinePaint);

//
// Offset bottomStart = indicatorCenter.translate(
// 0, (safeHalfHeight + halfItemGap + indicatorMargin - lineGap));
// // works well
// Offset bottomEnd = indicatorCenter.translate(0, radius);

Offset bottomStart = indicatorCenter.translate(0, radius + lineGap);
if (!isLast) canvas.drawLine(bottomStart, bottomEnd, linePaint);
}
// endregion downer line
}

double getAdditionalY(double height, {int direction = 1}) {
double getAdditionalY(double height, {@required String mode}) {
double add = 0;
// the additional size should be
switch (indicatorPosition) {
case IndicatorPosition.top:
add = 0;
break;
case IndicatorPosition.center:
add = (height - indicatorSize) / 2;
break;
case IndicatorPosition.bottom:
add = height - indicatorSize;
break;
if (mode == "upper") {
switch (indicatorPosition) {
case IndicatorPosition.top:
add = 0;
break;
case IndicatorPosition.center:
add = (height - indicatorSize) / 2;
break;
case IndicatorPosition.bottom:
add = height - indicatorSize;
break;
}
return add;
}

if (mode == "downer") {
switch (indicatorPosition) {
case IndicatorPosition.top:
add = height - indicatorSize;
break;
case IndicatorPosition.center:
add = (height - indicatorSize) / 2;
break;
case IndicatorPosition.bottom:
add = 0;
break;
}
return add;
}
return add * direction;

throw FlutterError("$mode is not a supported mode");
}

@override
Expand All @@ -334,24 +328,6 @@ class _LineIndicatorPainter extends CustomPainter {
}
}

// switch (indicatorPosition) {
// case IndicatorPosition.top:
// topStart = indicatorCenter.translate(
// 0,
// -(safeHalfHeight + halfItemGap + indicatorMargin - lineGap) +
// additionalTopY);
// break;
// case IndicatorPosition.center:
// topStart = indicatorCenter - Offset(0, lineGap);
// break;
// case IndicatorPosition.bottom:
// topStart = indicatorCenter.translate(
// 0,
// -(safeHalfHeight + halfItemGap + indicatorMargin - lineGap) +
// additionalTopY);
// break;
// }

// painter v1
/*
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+11
version: 0.1.1+12
homepage: https://github.com/softmarshmallow/flutter-timeline
repository: https://github.com/softmarshmallow/flutter-timeline

Expand Down

0 comments on commit 772a0cb

Please sign in to comment.