Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [1.2.2] - 2026-04-28

@rickypid
Co-authored-by: RichiB20 <RichiB20@users.noreply.github.com>

- Fix `setState` called during build in `initState` by deferring `controller.fetch()` via `addPostFrameCallback`.
- Fix `setState` called on unmounted widget in `_getAsync` by adding `mounted` guards before each `setState` call.
- Skip `controller.fetch()` on pan end when the visible date range has not changed (e.g. simple tap or sub-day drag).

## [1.2.1] - 2026-03-31

@rickypid
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.1"
version: "1.2.2"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
36 changes: 26 additions & 10 deletions lib/src/widgets/gantt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class _GanttState extends State<Gantt> {
late GanttTheme theme;
late GanttController controller;
Offset? _lastPosition;
DateTime? _panStartDate;
late LinkedScrollControllerGroup _linkedControllers;
late ScrollController _listController;
late ScrollController _gridColumnsController;
Expand All @@ -161,7 +162,9 @@ class _GanttState extends State<Gantt> {
if (widget.activities != null) {
controller.setActivities(widget.activities!, notify: false);
} else {
controller.fetch();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) controller.fetch();
});
}
if (widget.highlightedDates != null) {
controller.setHighlightedDates(widget.highlightedDates!, notify: false);
Expand All @@ -185,8 +188,10 @@ class _GanttState extends State<Gantt> {
super.dispose();
}

void _handlePanStart(DragStartDetails details) =>
_lastPosition = details.localPosition;
void _handlePanStart(DragStartDetails details) {
_lastPosition = details.localPosition;
_panStartDate = controller.startDate;
}

void _handlePanUpdate(
DragUpdateDetails details,
Expand Down Expand Up @@ -234,23 +239,31 @@ class _GanttState extends State<Gantt> {
void _handlePanCancel() => _reset();

void _reset() {
final dateChanged =
_panStartDate != null &&
!controller.startDate.isAtSameMomentAs(_panStartDate!);
_lastPosition = null;
controller.fetch();
_panStartDate = null;
if (dateChanged) controller.fetch();
}

Future<void> _getAsync() async {
if (!mounted) return;
if (widget.activitiesAsync != null || widget.holidaysAsync != null) {
var activities = <GanttActivity>[];
var holidays = <GantDateHoliday>[];
setState(() {
_loading = true;
});
if (mounted) {
setState(() {
_loading = true;
});
}
if (widget.activitiesAsync != null) {
activities = await widget.activitiesAsync!(
controller.startDate,
controller.endDate,
controller.activities,
);
if (!mounted) return;
controller.setActivities(activities, notify: false);
}
if (widget.holidaysAsync != null) {
Expand All @@ -259,11 +272,14 @@ class _GanttState extends State<Gantt> {
controller.endDate,
controller.holidays,
);
if (!mounted) return;
controller.setHolidays(holidays, notify: false);
}
setState(() {
_loading = false;
});
if (mounted) {
setState(() {
_loading = false;
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_gantt
description: "Flutter package for rendering an interactive and customizable Gantt chart widget."
version: 1.2.1
version: 1.2.2
homepage: https://github.com/insideapp-srl/flutter_gantt
repository: https://github.com/insideapp-srl/flutter_gantt

Expand Down
Loading