Skip to content
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

Focused date behaviour inconsistent if firstDay changes #866

Open
hrafnthor opened this issue Apr 15, 2024 · 1 comment
Open

Focused date behaviour inconsistent if firstDay changes #866

hrafnthor opened this issue Apr 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@hrafnthor
Copy link

hrafnthor commented Apr 15, 2024

Describe the bug
In cases where the firstDay can change from initial value (for example when fetching the calendar range over the network, and initial range is given as [today, today]), the focusedDay will be overlooked and the focused moved to the period where the new firstDay is.

The following code snippet will showcase the behaviour:

class Data {
  Data({
    required this.focusedDay,
    required this.firstDay,
    required this.lastDay,
  });

  final DateTime focusedDay;

  final DateTime firstDay;

  final DateTime lastDay;
}

class WidgetTest extends StatelessWidget {
  const WidgetTest({super.key});

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<Data>(
        initialData: Data(
          focusedDay: DateTime.now(),
          firstDay: DateTime.now(),
          lastDay: DateTime.now()
        ),
        future: Future.delayed(
          const Duration(seconds: 5),
          () => Data(
            focusedDay: DateTime.now(),
            firstDay: DateTime(2024, 1, 1),
            lastDay: DateTime(2024, 12, 31),
          ),
        ),
        builder: (c, s) {
          if (s.hasData) {
            final data = s.requireData;
            return TableCalendar(
              headerVisible: true,
              firstDay: data.firstDay,
              lastDay: data.lastDay,
              focusedDay: data.focusedDay,
              selectedDayPredicate: (day) => day.sameDate(data.focusedDay),
              calendarFormat: CalendarFormat.week,
            );
          }
          return SizedBox();
        });
  }
}

extension DateTimeExtension on DateTime {
  bool sameDate(DateTime other) =>
      year == other.year && month == other.month && day == other.day;
}

This will display a TableCalendar with today's date focused, until after 5 seconds when the future delivers values with different start and end dates (but the same focused date). At that point the calendar jumps to the starting date rather than using the focused date.

Expected behavior
The set focusedDay should always be the controlling factor for where the focus is at, no matter what values are given by firstDay or lastDay.

System

Flutter: 3.19.5 (stable)
table_calendar: 3.1.1

@hrafnthor hrafnthor added the bug Something isn't working label Apr 15, 2024
@hrafnthor hrafnthor changed the title On Focused date behaviour inconsistent if startDate changes Apr 15, 2024
@hrafnthor hrafnthor changed the title Focused date behaviour inconsistent if startDate changes Focused date behaviour inconsistent if firstDay changes Apr 15, 2024
@niemsie
Copy link

niemsie commented May 10, 2024

This is the same issue as we are having here: #842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants