Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
softmarshmallow authored Aug 10, 2021
2 parents db721c5 + 9cae924 commit 24c0388
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 90 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ Widget _buildTimeline() {



## references
https://www.pinterest.com/official_softmarshmallow/flutter-timeline/


## complex example

Expand All @@ -119,6 +116,14 @@ https://www.pinterest.com/official_softmarshmallow/flutter-timeline/
more documentation available at [github](https://github.com/softmarshmallow/flutter-timeline)


## Sponsors
- [Bridged](https://bridged.xyz) ([github](https:github.com/bridgedxyz))


## Also check out...
[flutter_layouts](https://github.com/softmarshmallow/flutter-layouts)


## references
https://www.pinterest.com/official_softmarshmallow/flutter-timeline/

12 changes: 6 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ List<DemoScreen> demos = [
];

class DemoHomePage extends StatefulWidget {
DemoHomePage({Key key, this.title}) : super(key: key);
DemoHomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
Expand Down Expand Up @@ -93,13 +93,13 @@ class _DemoHomePageState extends State<DemoHomePage> {

class DemoScreen {
DemoScreen(
{@required this.name,
@required this.description,
@required this.cover,
@required this.route});
{required this.name,
required this.description,
this.cover,
required this.route});

final String name;
final String description;
final String cover;
final String? cover;
final String route;
}
2 changes: 1 addition & 1 deletion example/lib/screen/cms_comments_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _DeskTimelineDemoScreenState extends State<DeskTimelineDemoScreen> {
return Text(
"Today",
style:
Theme.of(context).textTheme.headline5.copyWith(color: Colors.amber),
Theme.of(context).textTheme.headline5?.copyWith(color: Colors.amber),
);
}

Expand Down
2 changes: 1 addition & 1 deletion example/lib/screen/dessert_stories_demo.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class DessertStoriesDemoScreen extends StatefulWidget {
DessertStoriesDemoScreen({Key key}) : super(key: key);
DessertStoriesDemoScreen({Key? key}) : super(key: key);

@override
_DessertStoriesDemoScreenState createState() => _DessertStoriesDemoScreenState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/screen/plain_timeline_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class _PlainTimelineDemoScreenState extends State<PlainTimelineDemoScreen> {
indicator: randomIndicator);
}

List<TimelineEventDisplay> events;
late List<TimelineEventDisplay> events;

Widget _buildTimeline() {
return TimelineTheme(
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ packages:
source: hosted
version: "2.1.0-nullsafety.2"
sdks:
dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.12.0 <2.0.0"
dart: ">=2.12.0 <2.10.0"
flutter: ">=2.0.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion lib/defaults.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class TimelineDots {
TimelineDots({this.context});
TimelineDots({required this.context});

BuildContext context;

Expand Down
24 changes: 14 additions & 10 deletions lib/event_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'indicator_position.dart';

class TimelineEventDisplay {
TimelineEventDisplay({
@required @required this.child,
required this.child,
this.indicator,
this.indicatorSize,
this.forceLineDrawing = false,
Expand All @@ -15,14 +15,14 @@ class TimelineEventDisplay {
final Widget child;

/// if not provided, use the default indicator size
final double indicatorSize;
final Widget indicator;
final double? indicatorSize;
final Widget? indicator;

/// enables indicator line drawing even no indicator is passed.
final bool forceLineDrawing;

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

bool get hasIndicator {
Expand All @@ -41,8 +41,8 @@ class TimelineEventCard extends StatelessWidget {
final EdgeInsetsGeometry padding;

TimelineEventCard({
@required this.title,
@required this.content,
required this.title,
required this.content,
this.padding = const EdgeInsets.only(left: 16, top: 12, right: 16, bottom: 20),
});

Expand Down Expand Up @@ -72,12 +72,16 @@ class TimelineEventCard extends StatelessWidget {

Widget _title(BuildContext context) {
return DefaultTextStyle(
style: Theme.of(context).textTheme.subtitle1, child: title);
style: Theme.of(context).textTheme.subtitle1 ?? TextStyle(),
child: title,
);
}

Widget _description(BuildContext context) {
return DefaultTextStyle(
style: Theme.of(context).textTheme.overline, child: content);
style: Theme.of(context).textTheme.overline ?? TextStyle(),
child: content,
);
}
}

Expand All @@ -90,7 +94,7 @@ class TimelineSectionDivider extends StatelessWidget {
);
}

const TimelineSectionDivider({Key key, @required this.content})
const TimelineSectionDivider({Key? key, required this.content})
: super(key: key);

@override
Expand All @@ -101,7 +105,7 @@ class TimelineSectionDivider extends StatelessWidget {
Widget _content(BuildContext context) {
return AnimatedDefaultTextStyle(
child: content,
style: Theme.of(context).textTheme.headline5,
style: Theme.of(context).textTheme.headline5 ?? TextStyle(),
duration: kThemeChangeDuration);
}
}
4 changes: 0 additions & 4 deletions lib/indicator_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ extension Mapper on IndicatorPosition {
switch (this) {
case IndicatorPosition.top:
return Alignment.topCenter;
break;
case IndicatorPosition.center:
return Alignment.center;
break;
case IndicatorPosition.bottom:
return Alignment.bottomCenter;
break;
}
return Alignment.center;
}
}
73 changes: 36 additions & 37 deletions lib/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'indicator_position.dart';

class Timeline extends StatelessWidget {
const Timeline(
{@required this.events,
{required this.events,
this.isLeftAligned = true,
this.padding = const EdgeInsets.all(8),
this.controller,
Expand All @@ -28,17 +28,17 @@ class Timeline extends StatelessWidget {
final double indicatorSize;
final bool isLeftAligned;
final EdgeInsets padding;
final ScrollController controller;
final ScrollController? controller;
final int itemCount;
final ScrollPhysics physics;
final ScrollPhysics? physics;
final bool shrinkWrap;
final bool primary;
final bool reverse;

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

final IndexedWidgetBuilder separatorBuilder;
final IndexedWidgetBuilder? separatorBuilder;

@override
Widget build(BuildContext context) {
Expand All @@ -63,8 +63,8 @@ class Timeline extends StatelessWidget {
itemBuilder: (context, index) {
final event = _events[index];
// safely get prev, next events
TimelineEventDisplay prevEvent;
TimelineEventDisplay nextEvent;
TimelineEventDisplay? prevEvent;
TimelineEventDisplay? nextEvent;
if (index != 0) {
prevEvent = _events[index - 1];
}
Expand Down Expand Up @@ -97,15 +97,15 @@ class Timeline extends StatelessWidget {
);
}

bool _eventHasIndicator(TimelineEventDisplay event) {
bool _eventHasIndicator(TimelineEventDisplay? event) {
if (event == null) {
return false;
}
return event.hasIndicator;
}

Widget buildWrappedIndicator(Widget child,
{double width, double height, Offset indicatorOffset}) {
Widget buildWrappedIndicator(Widget? child,
{double? width, double? height, required Offset indicatorOffset}) {
final offset = altOffset + indicatorOffset;
return Container(
width: width,
Expand All @@ -116,21 +116,21 @@ class Timeline extends StatelessWidget {
}

Widget _buildIndicatorSection(
{bool isFirst,
bool isLast,
bool prevHasIndicator,
bool nextHasIndicator,
TimelineEventDisplay event,
TimelineThemeData theme}) {
{required bool isFirst,
required bool isLast,
required bool prevHasIndicator,
required bool nextHasIndicator,
required TimelineEventDisplay event,
required TimelineThemeData theme}) {
final overrideIndicatorSize =
event.indicatorSize != null ? event.indicatorSize : indicatorSize;
event.indicatorSize != null ? event.indicatorSize! : indicatorSize;
final overrideIndicatorPosition =
event.anchor != null ? event.anchor : anchor;
event.anchor != null ? event.anchor! : anchor;
final indicatorOffset = event.indicatorOffset;

var line = CustomPaint(
painter: _LineIndicatorPainter(
hideDefaultIndicator: event.child != null,
hideDefaultIndicator: true,
lineColor: theme.lineColor,
reverse: reverse,
indicatorSize: overrideIndicatorSize,
Expand Down Expand Up @@ -170,23 +170,23 @@ class Timeline extends StatelessWidget {

class _LineIndicatorPainter extends CustomPainter {
_LineIndicatorPainter(
{@required this.hideDefaultIndicator,
@required this.reverse,
@required this.indicatorSize,
@required this.altOffset,
@required this.maxIndicatorSize,
@required this.lineGap,
@required this.strokeCap,
@required this.strokeWidth,
@required this.style,
@required this.lineColor,
@required this.isFirst,
@required this.isLast,
@required this.nextHasIndicator,
@required this.prevHasIndicator,
@required this.itemGap,
@required this.indicatorOffset,
@required this.indicatorPosition})
{required this.hideDefaultIndicator,
required this.reverse,
required this.indicatorSize,
required this.altOffset,
required this.maxIndicatorSize,
required this.lineGap,
required this.strokeCap,
required this.strokeWidth,
required this.style,
required this.lineColor,
required this.isFirst,
required this.isLast,
required this.nextHasIndicator,
required this.prevHasIndicator,
required this.itemGap,
required this.indicatorOffset,
required this.indicatorPosition})
: linePaint = Paint()
..color = lineColor
..strokeCap = strokeCap
Expand Down Expand Up @@ -225,7 +225,6 @@ class _LineIndicatorPainter extends CustomPainter {
// indicator's radius
final radius = indicatorSize / 2;
final height = size.height;
final halfHeight = height / 2;
final double halfItemGap = itemGap / 2;

// initial start point
Expand Down Expand Up @@ -286,7 +285,7 @@ class _LineIndicatorPainter extends CustomPainter {
// endregion downer line
}

double getAdditionalY(double height, {@required String mode}) {
double getAdditionalY(double height, {required String mode}) {
double add = 0;
// the additional size should be
if (mode == "upper") {
Expand Down
21 changes: 5 additions & 16 deletions lib/timeline_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@ class TimelineTheme extends InheritedTheme {

/// Creates an timeline theme that controls the styles of descendant widgets.
/// Both [data] and [child] arguments must not be null.
const TimelineTheme({Key key, @required this.data, @required this.child})
: assert(data != null),
assert(child != null),
super(key: key, child: child);
const TimelineTheme({Key? key, required this.data, required this.child})
: super(key: key, child: child);

static TimelineThemeData of(BuildContext context) {
final TimelineThemeData timelineThemeData =
_getInheritedTimelineThemeData(context).resolve(context);
return timelineThemeData.isConcrete
? timelineThemeData
: timelineThemeData.copyWith(
lineColor: timelineThemeData.lineColor ??
const TimelineThemeData.fallback().lineColor,
strokeWidth: timelineThemeData.strokeWidth ??
const TimelineThemeData.fallback().strokeWidth,
strokeCap: timelineThemeData.strokeCap ??
const TimelineThemeData.fallback().strokeCap,
);
return timelineThemeData;
}

static TimelineThemeData _getInheritedTimelineThemeData(
BuildContext context) {
final TimelineTheme timelineTheme =
final TimelineTheme? timelineTheme =
context.dependOnInheritedWidgetOfExactType<TimelineTheme>();
return timelineTheme?.data ?? const TimelineThemeData.fallback();
}
Expand All @@ -41,7 +30,7 @@ class TimelineTheme extends InheritedTheme {

@override
Widget wrap(BuildContext context, Widget child) {
final TimelineTheme timelineTheme =
final TimelineTheme? timelineTheme =
context.findAncestorWidgetOfExactType<TimelineTheme>();
return identical(this, timelineTheme)
? child
Expand Down
Loading

0 comments on commit 24c0388

Please sign in to comment.