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

Wrong order of calendar formats and its implication inheritance #869

Open
xxwag opened this issue Apr 24, 2024 · 8 comments
Open

Wrong order of calendar formats and its implication inheritance #869

xxwag opened this issue Apr 24, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@xxwag
Copy link

xxwag commented Apr 24, 2024

Describe the bug
I initialize the calendar format as explained in the examples, yet the reading of the format change button is incorrect (2 weeks for month layout etc..) Simply renaming the calendar formats name using availablecalendarformats wont work as there is are hidden properties behind it (for example if i try to get the render box constraints of the calendar table it results incorrectly). Altrought the rest of the behaviour is smooth and im not getting any overflows or anything...

To reproduce

        inside the buildcalendar:
         onFormatChanged: (format) {
                  WidgetsBinding.instance
                      .addPostFrameCallback(_afterLayout);
                  if (_calendarFormat != format) {
                    setState(() {
                      _calendarFormat = format;
                    });
                  } else {
                    print('Format unchanged, no state update needed.');
                  }
                },

inside the widget build:
SliverToBoxAdapter(
child: LayoutBuilder(
builder: (context, constraints) {
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: constraints.maxHeight, // Use parent max height
minHeight:
200,
),
child: buildCalendar(),
);
},
),
),

Steps to reproduce the behavior:
I feel like it missbehaved since the beggining ..

Expected behavior
The calendar format to match the actual layout

Screenshots
image

Output of flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.22621.1413], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.88.1)
[√] Connected device (3 available)
[√] Network resources

Additional context
Add any other context about the problem here.

@xxwag xxwag added the bug Something isn't working label Apr 24, 2024
@xxwag
Copy link
Author

xxwag commented Apr 25, 2024

Sorry i found this and it solves that
#199

, but id still like to ask whether the Calendar Table shouldnt be ready to emit onhandleupdate behaviour for multiple daycell selection or am i wrong? I have to hard code something like this to retrieve the daycell positions and its annoying. Also the usage of the range selection is pretty unclear from my POV.

DateTime _calculateDateFromGesture(Offset localPosition) {
final RenderBox? box =
_calendarKey.currentContext?.findRenderObject() as RenderBox?;
if (box != null) {
double cellWidth = box.size.width / 7;
double rowHeight = _getRowHeight();

  int column = (localPosition.dx / cellWidth).floor();
  int row = (localPosition.dy / rowHeight).floor();

  DateTime firstVisibleDay =
      _focusedDay.subtract(Duration(days: _focusedDay.weekday - 1));
  DateTime calculatedDate =
      firstVisibleDay.add(Duration(days: row * 7 + column));

  print("First Visible Day: $firstVisibleDay");
  print("Calculated Date: $calculatedDate");

  return calculatedDate;
}
return _focusedDay; // Fallback if box is not found

}

@Somtobro
Copy link

Bro, totally random but, any idea on how to implement day to day swiping?

@xxwag
Copy link
Author

xxwag commented Apr 30, 2024

Yes, so you need to create an handlepan function or similar and call it from the table calendar gesture detector to interact with the whole table. Not sure if thats what you looking for.

@Somtobro
Copy link

Yeah, that's what I'm looking for .
But there's no built bin function to call next day.
For example:
If I'm on the last day of the month eg 30th of April.
Swiping again would go to 31 and then 32.
Do you understand what I'm tryna say?

@xxwag
Copy link
Author

xxwag commented Apr 30, 2024

Try the simpleSwipeConfig = const SimpleSwipeConfig(
verticalThreshold: 25.0,
swipeDetectionBehavior: SwipeDetectionBehavior.continuousDistinct,
),

By now you should already have something like an focused day datetime and you initialize it using date.now right? 

Swipe config would iterate based on the direction, increment the focused day and change its state to represent the change. 

@Somtobro
Copy link

Somtobro commented May 1, 2024

Yeah I've figured it out.
The only problem now Is I can't select too far forward or behind.
For example
Currently I can't scroll past August 1st
Today is May 1st

@xxwag
Copy link
Author

xxwag commented May 1, 2024

Im doing this to calculate the surrounding days and fill the exit voids, maybe you can use this substract in combination with focused month +-1 to fill the available dates to get swiped on.

  DateTime firstDayOfMonth = DateTime(_focusedDay.year, _focusedDay.month, 1);
    int daysToSubtract = (firstDayOfMonth.weekday - 1) % 7;
    DateTime firstVisibleDay =
        firstDayOfMonth.subtract(Duration(days: daysToSubtract));

    DateTime calculatedDate =
        firstVisibleDay.add(Duration(days: row * 7 + column));

@Somtobro
Copy link

Somtobro commented May 6, 2024

Thanks guys I've fixed it. I came up with a very brilliant solution.
I wrapped the body around a Swipe widget and I used the flutters add and subtract to go back and forth to the next or previous (changing selected and focused days) day that handles it perfectly as it checks if the the next day exists and if it's the last day of the year it goes to the new year as well.
Thanks once more

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