event_calendar 0.0.14

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

Event Calendar #

This package is for calculating calendar events with Reccurring events without the use of device calendar.

Installation #

Just add the latest version of event_calendar to the pubspec.yabl file

Side note #

Due to the nature of this package unit testing can be dificult so if you find any inaccurate dates please share them on the issues page.

Usage #

Start off by creating a calendar. You can add an event with the addEvent(Event event). You can follow the simple example below or look at the ./example/main.dart file.

Calendar calendar = new Calendar(title: "My Calendar", id:"calendarID");

calendar.addEvent(Event(DateTime(2020, 6, 1, 10, 0, 0), id: "1", title: "Single event"));

//Get a single next event
calendar.getNextEvent(startAfter: DateTime(2020, 5, 28, 12, 0, 0));

DateTime start = DateTime(2020, 5, 28, 12, 0, 0);
DateTime end = DateTime(2020, 6, 2, 12, 0, 0);

//get all events within a time frame
List<Events> events = calendar.getEvents(start, end);

Calendar Features #

[x] Parse to and from json
[x] Get next Event
[x] Get events in time frame
[x] Limit event ocurrences
[x] Intervals
[x] Recurring events

  • Hourly
  • Daily
  • Weekly
  • Monthly (both from start of month and from last date)
  • Yearly

TODO
[] Completions
[] Exceptions
[] Exclusions

[0.0.14] #

  • Fixed error in Event.fromJson when parsing a RecurrenceRule

[0.0.13] #

  • Added AttachableObject as an abstract for custom overriding

[0.0.12] #

  • Corrected Interval issue and getNextEvent

[0.0.11] #

  • Calendar nextEvent returning null too early

[0.0.10] #

*Fixed Recurrence getNextDate error

[0.0.9] #

*Corrected Next Event throwing null

[0.0.8] #

*Corrected Next Event returning wrong date

[0.0.7] #

*Fixed datetime error in Calendar JSON

[0.0.6] #

*Fixed datetime error in ReccurenceRule JSON

[0.0.5] #

*Fixed null ReccurenceRule in JSON

[0.0.4] #

  • Fixed Weekly repeating

example/main.dart

import 'package:event_calendar/event_calendar.dart';
import 'package:flutter/material.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: 'Event Calendar Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

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

class HomePageState extends State<HomePage>{
  Calendar calendar = new Calendar(title: "My Calendar", id:"calendarID");

  void initState(){
    super.initState();
    calendar.addEvent(Event(DateTime(2020, 6, 1, 12, 0, 0), id: "1", title: "Take out the garbage", recurrenceRule: RecurrenceRule(Frequency.weekly, byDay: [DayOfTheWeek.Monday, DayOfTheWeek.Friday], count: -1)));
    calendar.addEvent(Event(DateTime(2020, 6, 18, 12, 0, 0), id: "2", title: "Pay garbage bill", recurrenceRule: RecurrenceRule(Frequency.monthly, count: 4)));
    calendar.addEvent(Event(DateTime(2020, 7, 17, 12, 0, 0), id: "3", title: "Cancel garbage service"));
  }

  List<Widget> displayEvents(DateTime start, DateTime end){
    List<Widget> children = List();
    List<Event> events = calendar.getEvents(start, end);
    events.sort((a, b){
      return a.currentDate.difference(b.currentDate).inSeconds;
    });
    events.forEach((e){
      print(e.title);
      children.add(Padding(
        padding: const EdgeInsets.all(8.0),
        child: ClipRRect(child: GestureDetector(onTap: (){

        },child:
        Row(
          children: <Widget>[
            Expanded(child: Container(color: Colors.blue,child: Column(crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(e.title, style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.w500),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text("${e.currentDate.toIso8601String()}", style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w400),),
                ),
              ],
            ))),
          ],
        ),
        )),
      ));
    });

    if(children.length == 0){
      children.add(Center(child:Container(child: Text("All clear! \nNo events planned for this day", textAlign: TextAlign.center,style: TextStyle(fontSize: 18),), height: 100)));
    }

    return children;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
          Container(height: 50,),
          Column(children: displayEvents(DateTime(2020, 6, 18, 12, 0, 0), DateTime(2020, 7, 17, 12, 0, 0))),
        ],),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  event_calendar: ^0.0.14

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:event_calendar/event_calendar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • event_calendar that is a package requiring null.

Health issues and suggestions

Document public APIs. (-0.04 points)

176 out of 182 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/Calendar.dart. (-0.50 points)

Analysis of lib/Calendar.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:math'.

Fix lib/Event.dart. (-0.50 points)

Analysis of lib/Event.dart reported 1 hint:

line 156 col 25: Don't explicitly initialize variables to null.

Format lib/AttachableObject.dart.

Run flutter format to format lib/AttachableObject.dart.

Format lib/Calendar_Enums.dart.

Run flutter format to format lib/Calendar_Enums.dart.

Format lib/RecurrenceRule.dart.

Run flutter format to format lib/RecurrenceRule.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test