flutter_calendar_view
flutter_calendar_view copied to clipboard
Auto scroll to the top of the page when i update widget
Hello, i had a issue, when i scroll to 10-11.am and update data in field rooms (delete old controller and add new controller from rooms), it automatically scroll to the top of the page, i dont know why? So help me pls.
class _TimelineState extends State<_TodayTimeline> {
final _controller = timeline.EventController();
final RefreshController _refreshController = RefreshController();
timeline.CalendarEventData? event;
@override
void dispose() {
_refreshController.dispose();
_controller.dispose();
super.dispose();
}
@override
void didUpdateWidget(_TodayTimeline oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.rooms != oldWidget.rooms) {
_addNewEventsToController();
}
}
void _addNewEventsToController() {
if (event != null) {
_controller.remove(event!);
for (final room in widget.rooms) {
event = timeline.CalendarEventData(
date: room.startDate,
startTime: room.startDate,
endTime: room.endDate,
endDate: room.endDate,
title: room.description,
description: room.owner,
color: room.getStatusColor(context),
);
_controller.add(event!);
}
}
}
@override
void didChangeDependencies() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
for (final room in widget.rooms) {
event = timeline.CalendarEventData(
date: room.startDate,
startTime: room.startDate,
endTime: room.endDate,
endDate: room.endDate,
title: room.description,
description: room.owner,
color: room.getStatusColor(context),
);
if (event != null) {
_controller.add(event!);
}
}
});
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return ListLoader(
controller: RefreshController(),
child: timeline.DayView(
startDuration: const Duration(hours: 8),
controller: _controller,
eventTileBuilder: (
date,
events,
boundary,
startDuration,
endDuration,
) {
return Container(
decoration: BoxDecoration(
color: events.firstOrNull?.color,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
events.firstOrNull?.title ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.wsp,
fontWeight: FontWeight.w700,
),
),
Text(
events.firstOrNull?.description ?? '',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle( fontSize: 12.wsp,
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'',
style: TextStyle(
color: ThemeHelper.textHintSearchColor(context),
fontSize: 12.wsp,
),
),
Text(
'',
style: TextStyle(
color: ThemeHelper.textHintSearchColor(context),
fontSize: 12.wsp,
),
),
],
),
],
),
);
},
timeLineBuilder: (date) {
if (date.minute == 30) return const SizedBox.shrink();
return Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
top: -8,
right: 8,
child: Text(
AppDateUtils.format(
format: AppDateFormat.hhMM,
date: date,
).toString(),
textAlign: TextAlign.right,
),
),
],
);
},
maxDay: selectedDate,
minDay: selectedDate,
pageViewPhysics: const NeverScrollableScrollPhysics(),
dayTitleBuilder: (_) => const Text(''),
headerStyle: const timeline.HeaderStyle(
leftIconVisible: false,
rightIconVisible: false,
decoration: BoxDecoration(),
headerTextStyle: TextStyle(),
),
showHalfHours: true,
showVerticalLine: false,
showLiveTimeLineInAllDays: false,
heightPerMinute: 1.5,
halfHourIndicatorSettings: timeline.HourIndicatorSettings(
lineStyle: timeline.LineStyle.dashed,
color: ThemeHelper.borderDashedLine(context),
),
hourIndicatorSettings: timeline.HourIndicatorSettings(
color: ThemeHelper.borderDashedLine(context),
),
),
);
}
}
Update: before update data, scroll a little bit, it not automatically scroll to the top of the page
Hi @huynguyen96419, Sorry for the delay. Is this issue still reproducible on your end? If so, could you please share a minimal reproducible code sample or the steps to reproduce it? I'm currently unable to understand or reproduce the issue in the example app. Thanks!