Open bcycgcg opened 4 years ago
same issue
You can specify a start offset in the scroll view container to the current time.
In the Init state create a ScrollController
class _DayViewExampleState extends State<DayViewExample> {
DateTime _day0;
DateTime _day1;
// To specify start offset to the current time
ScrollController _scrollController;
@override
void initState() {
super.initState();
_day0 = new DateTime.now();
_day1 = _day0.toUtc().add(new Duration(days: 1)).toLocal();
// The number of minutes to the current time.
double nowInMinutes = ((_day0.hour * 60) + _day0.minute).toDouble();
// Scroll controller offsets a certain number of pixels
// Each minute has a height of 1 pixel
// So, to offset to the current time, we offset the number of minutes
_scrollController = new ScrollController(
initialScrollOffset: nowInMinutes,
keepScrollOffset: true,
);
}
In the SingleChildScrollView, add the ScrollController to apply the initial offset.
new Expanded(
child: new SingleChildScrollView(
controller: _scrollController,
child: new DayViewSchedule(
heightPerMinute: 1.0,
components: <ScheduleComponent>[
new TimeIndicationComponent.intervalGenerated(
generatedTimeIndicatorBuilder:
_generatedTimeIndicatorBuilder,
),
new SupportLineComponent.intervalGenerated(
generatedSupportLineBuilder: _generatedSupportLineBuilder,
),
new DaySeparationComponent(
generatedDaySeparatorBuilder:
_generatedDaySeparatorBuilder,
),
new EventViewComponent(
getEventsOfDay: _getEventsOfDay,
),
],
),
),
I made a pull request with the addition to the example project here: #27
i am trying to have the day view in the UI show starting 8am. the calendar by default goes to midnight since that's the beginning of the day view.