Skip to content

Commit

Permalink
Fix contents builder in TimelineTileBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
chulwoo-park committed Nov 23, 2020
1 parent 2c9a295 commit ce5c778
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/src/timeline_tile_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class TimelineTileBuilder {
/// * [TimelineTileBuilder.connectedFromStyle], which builds connected tiles from style.
factory TimelineTileBuilder.connected({
@required int itemCount,
ContentsAlign contentsAlign = ContentsAlign.basic,
ConnectionDirection connectionDirection = ConnectionDirection.after,
IndexedWidgetBuilder contentsBuilder,
IndexedWidgetBuilder oppositeContentsBuilder,
Expand All @@ -181,6 +182,7 @@ class TimelineTileBuilder {
assert(connectionDirection != null);
return TimelineTileBuilder(
itemCount: itemCount,
contentsAlign: contentsAlign,
contentsBuilder: contentsBuilder,
oppositeContentsBuilder: oppositeContentsBuilder,
indicatorBuilder: indicatorBuilder,
Expand Down Expand Up @@ -230,6 +232,7 @@ class TimelineTileBuilder {

return TimelineTileBuilder(
itemCount: itemCount,
contentsAlign: contentsAlign,
contentsBuilder: contentsBuilder,
oppositeContentsBuilder: oppositeContentsBuilder,
indicatorBuilder: (context, _) => _createStyledIndicatorBuilder(indicatorStyle)(context),
Expand Down Expand Up @@ -279,16 +282,9 @@ class TimelineTileBuilder {
}) {
return TimelineTileBuilder(
itemCount: itemCount,
contentsBuilder: _createStyledContentsBuilder(
align: contentsAlign,
contentsBuilder: contentsBuilder,
oppositeContentsBuilder: oppositeContentsBuilder,
),
oppositeContentsBuilder: _createStyledContentsBuilder(
align: contentsAlign,
contentsBuilder: oppositeContentsBuilder,
oppositeContentsBuilder: contentsBuilder,
),
contentsAlign: contentsAlign,
contentsBuilder: contentsBuilder,
oppositeContentsBuilder: oppositeContentsBuilder,
indicatorBuilder: (context, index) => _createStyledIndicatorBuilder(indicatorStyle)(context),
startConnectorBuilder: (context, _) => _createStyledConnectorBuilder(connectorStyle)(context),
endConnectorBuilder: (context, _) => _createStyledConnectorBuilder(connectorStyle)(context),
Expand All @@ -308,6 +304,7 @@ class TimelineTileBuilder {
/// TODO: need refactoring, is it has many builders...?
factory TimelineTileBuilder({
@required int itemCount,
ContentsAlign contentsAlign,
IndexedWidgetBuilder contentsBuilder,
IndexedWidgetBuilder oppositeContentsBuilder,
IndexedWidgetBuilder indicatorBuilder,
Expand All @@ -325,6 +322,17 @@ class TimelineTileBuilder {
'Cannot provide both a itemExtent and a itemExtentBuilder.',
);

final effectiveContentsBuilder = _createAlignedContentsBuilder(
align: contentsAlign,
contentsBuilder: contentsBuilder,
oppositeContentsBuilder: oppositeContentsBuilder,
);
final effectiveOppositeContentsBuilder = _createAlignedContentsBuilder(
align: contentsAlign,
contentsBuilder: oppositeContentsBuilder,
oppositeContentsBuilder: contentsBuilder,
);

return TimelineTileBuilder._(
(context, index) {
final tile = TimelineTile(
Expand All @@ -337,8 +345,8 @@ class TimelineTileBuilder {
position: nodePositionBuilder?.call(context, index),
indicatorPosition: indicatorPositionBuilder?.call(context, index),
),
contents: contentsBuilder?.call(context, index),
oppositeContents: oppositeContentsBuilder?.call(context, index),
contents: effectiveContentsBuilder(context, index),
oppositeContents: effectiveOppositeContentsBuilder(context, index),
);

final theme = themeBuilder?.call(context, index);
Expand Down Expand Up @@ -411,7 +419,7 @@ class TimelineTileBuilder {
}
};

static IndexedWidgetBuilder _createStyledContentsBuilder({
static IndexedWidgetBuilder _createAlignedContentsBuilder({
@required ContentsAlign align,
IndexedWidgetBuilder contentsBuilder,
IndexedWidgetBuilder oppositeContentsBuilder,
Expand All @@ -425,7 +433,7 @@ class TimelineTileBuilder {
return oppositeContentsBuilder?.call(context, index);
}

return contentsBuilder(context, index);
return contentsBuilder?.call(context, index);
case ContentsAlign.reverse:
return oppositeContentsBuilder?.call(context, index);
case ContentsAlign.basic:
Expand Down

0 comments on commit ce5c778

Please sign in to comment.