FadyFayezYounan / easy_date_timeline

The "easy_date_timeline" package is a customizable Flutter widget that displays a timeline of dates in a horizontal timeline.
MIT License
96 stars 46 forks source link

Header Month Information Not Updating While Scrolling #25

Open yagizdo opened 8 months ago

yagizdo commented 8 months ago

I've encountered an issue where the month information in the header remains unchanged while scrolling. Within the header builder, I'm only displaying the month name, such as "February", for instance. However, when I scroll to March, for example, the displayed month doesn't update accordingly. It seems that the date value within the header builder remains static, causing the displayed month to stay fixed.

Is there a solution to this problem?

Calendar View :

import 'package:easy_date_timeline/easy_date_timeline.dart';
import 'package:flutter/material.dart';

import '../../../../../widgets/main_widgets/main_appbar.dart';
import '../../../../../widgets/main_widgets/main_layout.dart';
import '../widget/date_card.dart';
import '../widget/date_header.dart';
import '../widget/day_schedule_comp.dart';

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

  @override
  Widget build(BuildContext context) {
    return MainLayout(
      content: context.isLittlePhone
          ? smallPhoneLayout(context)
          : context.isMiddlePhone
              ? middlePhoneLayout(context)
              : bigPhoneLayout(context),
    );
  }

  Widget bigPhoneLayout(BuildContext context) {
    return _buildBody(context);
  }

  Widget middlePhoneLayout(BuildContext context) {
    return _buildBody(context);
  }

  Widget smallPhoneLayout(BuildContext context) {
    return _buildBody(context);
  }

  Widget _buildBody(BuildContext context) {
    return Column(children: [
      const MainAppBar(
        title: "Takvim",
        isDetail: true,
      ),
      Expanded(child: _buildContent(context)),
    ]);
  }

  Widget _buildContent(BuildContext context) {
    final EasyInfiniteDateTimelineController controller =
        EasyInfiniteDateTimelineController();
    return Padding(
      padding: EdgeInsets.only(
        top: context.screenWidth * 0.02,
        left: context.screenWidth * 0.04,
        right: context.screenWidth * 0.04,
      ),
      child: Column(
        children: [
          EasyInfiniteDateTimeLine(
            controller: controller,
            firstDate: DateTime(2024),
            focusDate: DateTime.now(),
            lastDate: DateTime(2099, 12, 31),
            showTimelineHeader: true,
            autoCenter: true,
            dayProps: EasyDayProps(
              height: context.screenWidth * 0.24,
            ),
            headerBuilder: (context, date) {
              return DateHeader(
                date: date,
              );
            },
            itemBuilder: (
              context,
              String dayNumber,
              String dayName,
              String monthName,
              DateTime fullDate,
              bool isSelected,
            ) {
              return DateCard(
                dayNumber: dayNumber,
                dayName: dayName,
                monthName: monthName,
                fullDate: fullDate,
                isSelected: isSelected,
              );
            },
            onDateChange: (selectedDate) {},
          ),
          const Expanded(child: DayScheduleComp()),
        ],
      ),
    );
  }
}

Date Header :

import 'package:flutter/material.dart';

import '../../../../../utils/app_constants.dart';
import '../../../../../utils/app_textstyles.dart';

class DateHeader extends StatelessWidget {
  const DateHeader({super.key, required this.date});

  final DateTime date;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(
        bottom: context.screenWidth * 0.02,
      ),
      child: Text(
        monthNameMap[date.month] ?? "",
        style: AppTextStyle.dateHeader(context),
      ),
    );
  }
}
yagizdo commented 8 months ago

@FadyFayezYounan Do you have any suggestions?

FadyFayezYounan commented 8 months ago

@yagizdo I will update the package now and take a look at this issue,

yagizdo commented 8 months ago

Thank you, I'm looking forward to it. If I can solve it, I will open a PR.