d2calendar 0.0.5
d2calendar: ^0.0.5 copied to clipboard
Flutter d2 Calendar Package to build your own monthly Calendar or yearly Calendar.
How to Use the CalendarWidget #
To use the CalendarWidget in your Flutter application, follow the steps below:
[Image] [Image] [Image]-
Add the necessary dependencies to your
pubspec.yamlfile:dependencies: flutter: sdk: flutter d2calendar: ^0.0.3 -
Import package
import 'package:d2calendar/Calendar/CalendarWrapper.dart'; -
Initialize class
CalendarWrapper wrapper = CalendarWrapper(2023); -
Add Calendar to your UI
wrapper.Calendar( red: red, yellow: yellow, month: 'October', callback: (selectedList, obj) { // Handle the selected list and object here print(selectedList); // Boolean list of Days Selected print(obj); //Return Selected Date's }, singleDay: false, theme: 'light', notSelectDates: not_select_dates, ),Wrap this inside a Container or pass it in ListView children (field).
-
Initialize list to show red and Yellow dots.
List<int> red = [1, 2]; // This will Add a red Dot below 1st and 2nd of Selected Month List<int> yellow = [2, 3, 31, 32, 33, 34, 35, 36]; // similar(#red) List<int> not_select_dates = [22, 23];
- About class Wrapper class
CalendarWrapper Class #
The CalendarWrapper class is responsible for generating a calendar for a specific year and providing access to individual months.
Constructor: #
CalendarWrapper(int year)
- Constructs a new
CalendarWrapperinstance with the specifiedyear.
Methods: #
void init_(year)
- Initializes the calendar by generating the months for the specified
year.
void printData()
- Prints the data for each month in the calendar.
List<String> getJanuary()
- Returns the list of days for the month of January.
List<String> getFebruary()
- Returns the list of days for the month of February.
List<String> getMarch()
- Returns the list of days for the month of March.
List<String> getApril()
- Returns the list of days for the month of April.
List<String> getMay()
- Returns the list of days for the month of May.
List<String> getJune()
- Returns the list of days for the month of June.
List<String> getJuly()
- Returns the list of days for the month of July.
List<String> getAugust()
- Returns the list of days for the month of August.
List<String> getSeptember()
- Returns the list of days for the month of September.
List<String> getOctober()
- Returns the list of days for the month of October.
List<String> getNovember()
- Returns the list of days for the month of November.
List<String> getDecember()
- Returns the list of days for the month of December.
void setMonth(int month)
- Sets the current month to the specified
monthvalue.
void setYear(int year)
-
Sets the current year to the specified
yearvalue.Widget Calendar({ required red, required yellow, required month, required callback, required single_day, required theme, required not_select_dates, }) -
Generates a calendar widget for the specified
monthusing the provided parameters. Theredparameter is a list of integers representing days marked as red. Theyellowparameter is a list of integers representing days marked as yellow. Thecallbackis a function that is called when a day is selected. Thesingle_dayparameter indicates if only one day can be selected. Thethemeparameter defines the theme of the calendar. Thenot_select_datesparameter is a list of integers representing days that cannot be selected.
JSON Structure from CalendarUtil class (Not Wrapper Class) #
JSON Month
{
"name": "January",
"year": 2023,
"days": [
{"1": "Sunday"},
{"2": "Monday"},
{"3": "Tuesday"},
...
{"31": "Tuesday"}
],
"data": [
"2023-1-01",
"2023-1-02",
...
"2023-1-31"
]
}
name: (String): The name of the month.year: (int): The year of the month.days: (List<Map<int, String>>): The list of days in themonth, where each day is represented as a map containing the day number (key) and the corresponding weekday name (value).data: (List
Json Year
{
"year": 2023,
"months": [
{
"name": "January",
"year": 2023,
"days": [
{"1": "Sunday"},
{"2": "Monday"},
...
{"31": "Tuesday"}
],
"data": [
"2023-1-01",
...
"2023-1-30",
"2023-1-31"
]
},
// Include JSON representations of other months here
]
}
year: (int): The year.months(List