-
Notifications
You must be signed in to change notification settings - Fork 307
feat: Fixes issue #382: Add Multi-Day View Support #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import '../enumerations.dart'; | ||
| import '../extension.dart'; | ||
| import '../widgets/responsive_widget.dart'; | ||
| import '../widgets/multi_day_view_widget.dart'; | ||
| import 'create_event_page.dart'; | ||
| import 'web/web_home_page.dart'; | ||
|
|
||
| class MultiDayViewDemo extends StatefulWidget { | ||
| const MultiDayViewDemo({super.key}); | ||
|
|
||
| @override | ||
| _MultiDayViewDemoState createState() => _MultiDayViewDemoState(); | ||
| } | ||
|
|
||
| class _MultiDayViewDemoState extends State<MultiDayViewDemo> { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return ResponsiveWidget( | ||
| webWidget: WebHomePage( | ||
| selectedView: CalendarView.week, | ||
| ), | ||
| mobileWidget: Scaffold( | ||
| floatingActionButton: FloatingActionButton( | ||
| child: Icon(Icons.add), | ||
| elevation: 8, | ||
| onPressed: () => context.pushRoute(CreateEventPage()), | ||
| ), | ||
| body: MultiDayViewWidget(), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import 'package:calendar_view/calendar_view.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import '../pages/event_details_page.dart'; | ||
|
|
||
| class MultiDayViewWidget extends StatelessWidget { | ||
| final GlobalKey<MultiDayViewState>? state; | ||
| final double? width; | ||
|
|
||
| const MultiDayViewWidget({super.key, this.state, this.width}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MultiDayView( | ||
| key: state, | ||
| daysInView: 3, | ||
| width: width, | ||
| showLiveTimeLineInAllDays: true, | ||
| eventArranger: SideEventArranger(maxWidth: 30), | ||
| timeLineWidth: 65, | ||
| scrollPhysics: const BouncingScrollPhysics(), | ||
| liveTimeIndicatorSettings: LiveTimeIndicatorSettings( | ||
| color: Colors.redAccent, | ||
| onlyShowToday: true, | ||
| ), | ||
| onTimestampTap: (date) { | ||
| SnackBar snackBar = SnackBar( | ||
| content: Text("On tap: ${date.hour} Hr : ${date.minute} Min"), | ||
| ); | ||
| ScaffoldMessenger.of(context).showSnackBar(snackBar); | ||
| }, | ||
| onEventTap: (events, date) { | ||
| Navigator.of(context).push( | ||
| MaterialPageRoute( | ||
| builder: (_) => DetailsPage( | ||
| event: events.first, | ||
| date: date, | ||
| ), | ||
| ), | ||
| ); | ||
| }, | ||
| onEventLongTap: (events, date) { | ||
| SnackBar snackBar = SnackBar(content: Text("on LongTap")); | ||
| ScaffoldMessenger.of(context).showSnackBar(snackBar); | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,17 +41,21 @@ class LiveTimeIndicator extends StatefulWidget { | |
| /// This field will be used to set end hour for day and week view | ||
| final int endHour; | ||
|
|
||
| /// Flag to show only today's events. | ||
| final bool onlyShowToday; | ||
|
|
||
| /// Widget to display tile line according to current time. | ||
| const LiveTimeIndicator({ | ||
| Key? key, | ||
| required this.width, | ||
| required this.height, | ||
| required this.timeLineWidth, | ||
| required this.liveTimeIndicatorSettings, | ||
| required this.heightPerMinute, | ||
| required this.startHour, | ||
| this.endHour = Constants.hoursADay, | ||
| }) : super(key: key); | ||
| const LiveTimeIndicator( | ||
| {Key? key, | ||
| required this.width, | ||
| required this.height, | ||
| required this.timeLineWidth, | ||
| required this.liveTimeIndicatorSettings, | ||
| required this.heightPerMinute, | ||
| required this.startHour, | ||
| this.endHour = Constants.hoursADay, | ||
| this.onlyShowToday = false}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor this code |
||
| : super(key: key); | ||
|
|
||
| @override | ||
| _LiveTimeIndicatorState createState() => _LiveTimeIndicatorState(); | ||
|
|
@@ -113,7 +117,9 @@ class _LiveTimeIndicatorState extends State<LiveTimeIndicator> { | |
| color: widget.liveTimeIndicatorSettings.color, | ||
| height: widget.liveTimeIndicatorSettings.height, | ||
| offset: Offset( | ||
| widget.timeLineWidth + widget.liveTimeIndicatorSettings.offset, | ||
| widget.onlyShowToday | ||
| ? 0 | ||
| : widget.timeLineWidth + widget.liveTimeIndicatorSettings.offset, | ||
| (_currentTime.getTotalMinutes - startMinutes) * | ||
| widget.heightPerMinute, | ||
| ), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,24 @@ extension DateTimeExtensions on DateTime { | |
| 7) | ||
| .ceil(); | ||
|
|
||
| /// Gets difference of multi-day between [date] and calling object. | ||
| int getMultiDayDifference( | ||
| {required DateTime startDate, | ||
| required DateTime endDate, | ||
| daysInView = 3}) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define type here |
||
| final daysDifference = | ||
| startDate.withoutTime.difference(endDate.withoutTime).inDays.abs() + 1; | ||
|
|
||
| return (daysDifference / daysInView).ceil(); | ||
| } | ||
|
|
||
| /// Returns the list of [DateTime] for given [index] and [daysInView]. | ||
| List<DateTime> getMultiDateRangeList(DateTime startDate, int index, | ||
| {int daysInView = 3}) { | ||
| DateTime baseDate = startDate.add(Duration(days: index * daysInView)); | ||
| return List.generate(daysInView, (i) => baseDate.add(Duration(days: i))); | ||
| } | ||
|
|
||
| /// Returns The List of date of Current Week, all of the dates will be without | ||
| /// time. | ||
| /// Day will start from Monday to Sunday. | ||
|
|
@@ -89,6 +107,36 @@ extension DateTimeExtensions on DateTime { | |
| DateTime lastDayOfWeek({WeekDays start = WeekDays.monday}) => | ||
| DateTime(year, month, day + (6 - (weekday - start.index - 1) % 7)); | ||
|
|
||
| DateTime firstDayOfMultiDay({ | ||
| required DateTime startDate, | ||
| int daysInView = 3, | ||
| }) { | ||
| final diffDays = startDate.withoutTime | ||
| .difference(DateTime.now().withoutTime) | ||
| .inDays | ||
| .abs(); | ||
| final offset = diffDays % daysInView; | ||
| return offset == 0 | ||
| ? startDate.withoutTime | ||
| : startDate.subtract(Duration(days: daysInView - offset)).withoutTime; | ||
| } | ||
|
|
||
| /// Returns the last date of week containing the current date | ||
| DateTime lastDayOfMultiDay({ | ||
| required DateTime endDate, | ||
| int daysInView = 3, | ||
| }) { | ||
| final diffDays = endDate.withoutTime | ||
| .difference(DateTime.now().withoutTime) | ||
| .inDays | ||
| .abs() + | ||
| 1; | ||
| final offset = diffDays % daysInView; | ||
| return offset == 0 | ||
| ? endDate.withoutTime | ||
| : endDate.add(Duration(days: daysInView - offset)).withoutTime; | ||
| } | ||
|
|
||
| /// Returns list of all dates of [month]. | ||
| /// All the dates are week based that means it will return array of size 42 | ||
| /// which will contain 6 weeks that is the maximum number of weeks a month | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove max width from this.