'Error in using table_calendar: ^3.0.5 dependency in flutter

I get this error in my code where I used a table_calendar dependency. Here is my code where I implemented the calendar.

import 'package:fitr/reusable_widgets/bottom_navbar.dart';
import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';




class Calendar extends StatefulWidget {
  const Calendar({Key? key}) : super(key: key);

  @override
  State<Calendar> createState() => _CalendarState();
}

class _CalendarState extends State<Calendar> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        titleSpacing: 0.0,
        leading: BackButton(
          color: Colors.black,
        ),
        centerTitle: false,

        //current date here
        title: Text(
          '7 April 2022',
          style: TextStyle(
              color: Colors.black, fontWeight: FontWeight.w500, fontSize: 16.0),
        ),
        actions: <Widget>[
          IconButton(
            padding: EdgeInsets.only(right: 20),
            icon: Icon(
              Icons.calendar_today_outlined,
              color: Colors.black,
            ),
            onPressed: () {
              // do something
            },
          )
        ],
      ),
      backgroundColor: Color(0XFFF0FCFF),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Center(
            child: Column(
              children: [
                TableCalendar(
                  firstDay: DateTime.utc(2010,10,20),
                  lastDay: DateTime.utc(2040,10,20),
                  focusedDay: DateTime.now(),
                ),
              ],
            ),
          ),
        ),
      ),
      bottomNavigationBar: BotNavBar(),
    );
  }
}

And here is the error that it gives when I try to run it.

/D:/flutter/.pub-cache/hosted/pub.dartlang.org/table_calendar-3.0.5/lib/src/table_calendar_base.dart:192:34: Error: Required named parameter 'vsync' must be provided.
              return AnimatedSize(
                                 ^
/D:/flutter/packages/flutter/lib/src/widgets/animated_size.dart:56:9: Context: Found this candidate, but the arguments don't match.
  const AnimatedSize({
        ^^^^^^^^^^^^
3

FAILURE: Build failed with an exception.

* Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

I tried using the older versions of the dependency but it required the latest ones with null safety and it gives me those errors.



Solution 1:[1]

Give it a try and run:

flutter upgrade

To get more information about error:

flutter run --verbose

paste the results in the description

Solution 2:[2]

in pubspec.yaml change table_calendar: 3.0.1. Looks like 3.0.5 will cause this error

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fernando Callata
Solution 2 shrimp