Skyost / FlutterWeekView

Displays a highly customizable week view (or day view) which is able to display events, to be scrolled, to be zoomed-in & out and a lot more !
https://pub.dev/packages/flutter_week_view
MIT License
208 stars 89 forks source link

Initialtime in weekview not working after state change in stateful widget #63

Closed nanosekun-de closed 3 years ago

nanosekun-de commented 3 years ago

Within a stateful widget, Initialtime has no function when the Weekview is updated after a state change.

Run the following code and then wipe from today to the previous day. Then click on the DayBar.

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DateTime day = DateTime.now();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: WeekView(
          initialTime: day,
          onDayBarTappedDown: (_) => setState(() {
            day = day.add(Duration(days: 7));
          }),
          dates: [
            day.subtract(
              Duration(days: 1),
            ),
            day,
            day.add(
              Duration(days: 1),
            ),
          ],
        ),
      ),
    );
  }
}

The Weekview first shows today's day, which is stored in a state variable. Clicking on the DayBar moves the day forward by one week. I would have expected the day displayed to be today plus one week, however the day that corresponds to the previously selected index is displayed. That means if I was on the previous day, the new Weekview is on the previous day plus one week instead of today's day plus one week.

Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.19041.685] flutter_week_view: 1.0.0+1

Skyost commented 3 years ago

@nanosekun-de It may have been fixed in 55c0db582fd20e3d3189f6bf3f34d61b7a368c36 which is not (yet) released on pub.dev. Would it be possible for you to test it to see if the bug you're describring has been fixed ?

In your pubspec.yaml :

dependencies:
  flutter_week_view:
    git:
      url: https://github.com/Skyost/FlutterWeekView
      ref: master
nanosekun-de commented 3 years ago

Tested the new version. No change, the problem still exists.

Skyost commented 3 years ago

It should be okay now. Can you please confirm me that this bug has been fixed @nanosekun-de ? (you should run a pub upgrade with the git package specified in your pubspec.yaml)

nanosekun-de commented 3 years ago

Bug is fixed. Thank you.

Skyost commented 3 years ago

Cool, I'm gonna make a release on pub.dev asap :wink: