Skip to content

Commit

Permalink
✨ Set event tile width
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Oct 25, 2024
1 parent 982747f commit aa967d4
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 44 deletions.
18 changes: 18 additions & 0 deletions example/lib/widgets/week_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ class WeekViewWidget extends StatelessWidget {
return WeekView(
key: state,
width: width,
hasFixedWidthTile: true,
showLiveTimeLineInAllDays: true,
eventTileBuilder: (
date,
events,
boundary,
startDuration,
endDuration,
tileWidth,
) {
return DefaultEventTile(
date: date,
events: events,
boundary: boundary,
startDuration: startDuration,
endDuration: endDuration,
tileWidth: 10,
);
},
timeLineWidth: 65,
liveTimeIndicatorSettings: LiveTimeIndicatorSettings(
color: Colors.redAccent,
Expand Down
6 changes: 5 additions & 1 deletion lib/src/components/_internal_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
/// This field will be used to set end hour for day and week view
final int endHour;

final bool hasFixedWidthTile;

/// A widget that display event tiles in day/week view.
const EventGenerator({
Key? key,
Expand All @@ -371,6 +373,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
required this.scrollNotifier,
required this.onTileDoubleTap,
this.endHour = Constants.hoursADay,
this.hasFixedWidthTile = false,
}) : super(key: key);

/// Arrange events and returns list of [Widget] that displays event
Expand All @@ -389,7 +392,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
top: events[index].top,
bottom: events[index].bottom,
left: events[index].left,
right: events[index].right,
right: hasFixedWidthTile ? null : events[index].right,
child: GestureDetector(
onLongPress: () => onTileLongTap?.call(events[index].events, date),
onTap: () => onTileTap?.call(events[index].events, date),
Expand All @@ -411,6 +414,7 @@ class EventGenerator<T extends Object?> extends StatelessWidget {
height - events[index].bottom - events[index].top),
events[index].startDuration,
events[index].endDuration,
null,
);
}),
),
Expand Down
5 changes: 4 additions & 1 deletion lib/src/components/common_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DefaultPressDetector extends StatelessWidget {
Positioned(
top: heightPerSlot * i,
left: 0,
right: 0,
// right: 0,
bottom: height - (heightPerSlot * (i + 1)),
child: GestureDetector(
behavior: HitTestBehavior.translucent,
Expand Down Expand Up @@ -86,13 +86,15 @@ class DefaultEventTile<T> extends StatelessWidget {
required this.boundary,
required this.startDuration,
required this.endDuration,
this.tileWidth,
});

final DateTime date;
final List<CalendarEventData<T>> events;
final Rect boundary;
final DateTime startDuration;
final DateTime endDuration;
final double? tileWidth;

@override
Widget build(BuildContext context) {
Expand All @@ -101,6 +103,7 @@ class DefaultEventTile<T> extends StatelessWidget {
return RoundedEventTile(
borderRadius: BorderRadius.circular(10.0),
title: event.title,
tileWidth: tileWidth,
totalEvents: events.length - 1,
description: event.description,
padding: EdgeInsets.all(10.0),
Expand Down
91 changes: 49 additions & 42 deletions lib/src/components/day_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class RoundedEventTile extends StatelessWidget {
/// Style for description
final TextStyle? descriptionStyle;

// Sets width of tile. Default tile is expanded.
final double? tileWidth;

/// This is default tile to display in day view.
const RoundedEventTile({
Key? key,
Expand All @@ -51,60 +54,64 @@ class RoundedEventTile extends StatelessWidget {
this.backgroundColor = Colors.blue,
this.titleStyle,
this.descriptionStyle,
this.tileWidth,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
padding: padding,
margin: margin,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: borderRadius,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
if (title.isNotEmpty)
Expanded(
child: Text(
title,
style: titleStyle ??
TextStyle(
fontSize: 20,
color: backgroundColor.accent,
),
softWrap: true,
overflow: TextOverflow.fade,
),
),
if (description?.isNotEmpty ?? false)
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
return SizedBox(
width: tileWidth ?? null,
child: Container(
padding: padding,
margin: margin,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: borderRadius,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
if (title.isNotEmpty)
Expanded(
child: Text(
description!,
style: descriptionStyle ??
title,
style: titleStyle ??
TextStyle(
fontSize: 17,
color: backgroundColor.accent.withAlpha(200),
fontSize: 20,
color: backgroundColor.accent,
),
softWrap: true,
overflow: TextOverflow.fade,
),
),
),
if (totalEvents > 1)
Expanded(
child: Text(
"+${totalEvents - 1} more",
style: (descriptionStyle ??
if (description?.isNotEmpty ?? false)
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Text(
description!,
style: descriptionStyle ??
TextStyle(
fontSize: 17,
color: backgroundColor.accent.withAlpha(200),
))
.copyWith(fontSize: 17),
),
),
),
),
),
],
if (totalEvents > 1)
Expanded(
child: Text(
"+${totalEvents - 1} more",
style: (descriptionStyle ??
TextStyle(
color: backgroundColor.accent.withAlpha(200),
))
.copyWith(fontSize: 17),
),
),
],
),
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/day_view/_internal_day_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;

final bool hasFixedWidthTile;

/// Defines a single day page.
const InternalDayViewPage({
Key? key,
Expand Down Expand Up @@ -173,6 +175,7 @@ class InternalDayViewPage<T extends Object?> extends StatefulWidget {
required this.emulateVerticalOffsetBy,
required this.onTileDoubleTap,
this.keepScrollOffset = false,
this.hasFixedWidthTile = false,
}) : super(key: key);

@override
Expand Down Expand Up @@ -292,6 +295,7 @@ class _InternalDayViewPageState<T extends Object?>
alignment: Alignment.centerRight,
child: EventGenerator<T>(
height: widget.height,
hasFixedWidthTile: widget.hasFixedWidthTile,
date: widget.date,
onTileLongTap: widget.onTileLongTap,
onTileDoubleTap: widget.onTileDoubleTap,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,15 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
Rect boundary,
DateTime startDuration,
DateTime endDuration,
double? tileWidth,
) =>
DefaultEventTile(
date: date,
events: events,
boundary: boundary,
startDuration: startDuration,
endDuration: endDuration,
tileWidth: tileWidth,
);

/// Default view header builder. This builder will be used if
Expand Down
1 change: 1 addition & 0 deletions lib/src/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef EventTileBuilder<T extends Object?> = Widget Function(
Rect boundary,
DateTime startDuration,
DateTime endDuration,
double? tileWidth,
);

typedef DetectorBuilder<T extends Object?> = Widget Function({
Expand Down
5 changes: 5 additions & 0 deletions lib/src/week_view/_internal_week_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class InternalWeekViewPage<T extends Object?> extends StatefulWidget {
/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;

final bool hasFixedWidthTile;

/// A single page for week view.
const InternalWeekViewPage({
Key? key,
Expand Down Expand Up @@ -208,6 +210,7 @@ class InternalWeekViewPage<T extends Object?> extends StatefulWidget {
required this.weekViewScrollController,
this.lastScrollOffset = 0.0,
this.keepScrollOffset = false,
this.hasFixedWidthTile = false,
}) : super(key: key);

@override
Expand Down Expand Up @@ -438,6 +441,8 @@ class _InternalWeekViewPageState<T extends Object?>
onTileLongTap: widget.onTileLongTap,
onTileDoubleTap: widget.onTileDoubleTap,
width: widget.weekTitleWidth,
hasFixedWidthTile:
widget.hasFixedWidthTile,
eventArranger: widget.eventArranger,
eventTileBuilder: widget.eventTileBuilder,
scrollNotifier:
Expand Down
7 changes: 7 additions & 0 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class WeekView<T extends Object?> extends StatefulWidget {

/// Flag to keep scrollOffset of pages on page change
final bool keepScrollOffset;
final bool hasFixedWidthTile;

/// Main widget for week view.
const WeekView({
Expand Down Expand Up @@ -302,6 +303,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
this.fullDayHeaderTitle = '',
this.fullDayHeaderTextConfig,
this.keepScrollOffset = false,
this.hasFixedWidthTile = false,
}) : assert(!(onHeaderTitleTap != null && weekPageHeaderBuilder != null),
"can't use [onHeaderTitleTap] & [weekPageHeaderBuilder] simultaneously"),
assert((timeLineOffset) >= 0,
Expand Down Expand Up @@ -334,6 +336,7 @@ class WeekView<T extends Object?> extends StatefulWidget {
class WeekViewState<T extends Object?> extends State<WeekView<T>> {
late double _width;
late double _height;
late bool _hasFixedWidthTile;
late double _timeLineWidth;
late double _hourHeight;
late double _lastScrollOffset;
Expand Down Expand Up @@ -387,6 +390,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
@override
void initState() {
super.initState();
_hasFixedWidthTile = widget.hasFixedWidthTile;
_lastScrollOffset = widget.scrollOffset;

_scrollController =
Expand Down Expand Up @@ -515,6 +519,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
_hourHeight.toString() + dates[0].toString()),
height: _height,
width: _width,
hasFixedWidthTile: _hasFixedWidthTile,
weekTitleWidth: _weekTitleWidth,
weekTitleHeight: widget.weekTitleHeight,
weekDayBuilder: _weekDayBuilder,
Expand Down Expand Up @@ -797,13 +802,15 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
Rect boundary,
DateTime startDuration,
DateTime endDuration,
double? tileWidth,
) =>
DefaultEventTile(
date: date,
events: events,
boundary: boundary,
startDuration: startDuration,
endDuration: endDuration,
tileWidth: tileWidth,
);

/// Default view header builder. This builder will be used if
Expand Down

0 comments on commit aa967d4

Please sign in to comment.