small_calendar 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 39

small_calendar

small_calendar widget.

Usage

Add Dependency

dependencies:
    small_calendar: "^0.4.0"

Import It

import 'package:small_calendar/small_calendar.dart';

Use It

  1. Create new SmallCalendarData (this widget provides data to SmallCalendar-s down the widget tree)
  2. (Optionally) Create SmallCalendarStyle (to change the looks of SmallCalendar)
  3. Create SmallCalendarPager (to enable swiping between months)
  4. In pageBuilder of SmallCalendarPager create a new SmallCalendar

If you wish to display SmallCalendar for only one Month (without the ability to swipe between months), omit the SmallCalendarPager.

new SmallCalendarData(
  child: new SmallCalendarStyle(
    child: new SmallCalendarPager(
      pageBuilder: (BuildContext context, DateTime month) {
        return new SmallCalendar(
            month: month,
          );
        },
    ),
  ),
);

Styling

  • 1. - weekdayIndicationHeight
  • 2. - WeekdayIndicationStyleData/textStyle
  • 3. - WeekdayIndicationStyleData/backgroundColor
  • 4. - DayStyleData/extendedDayTextStyle
  • 5. - DayStyleData/dayTextStyle
  • 6. - tick
  • 7. - textTickSeparation
  • 8. - selectedColor
  • 9. - todayColor

0.4.0

This update is not backwards compatible!

  • Major changes to API
  • Rearranged functionality into:
    • SmallCalendarData
    • SmallCalendarStyle
    • SmallCalendarPager
    • SmallCalendar

0.3.1

  • onDisplayedMonthChanged now fires only when displayed month is actually changed
  • better documentation

0.3.0

  • performance improvements
  • calendar is now virtually infinite

0.0.1

  • Initial Release

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';

import 'package:small_calendar/small_calendar.dart';

void main() {
  runApp(
    new SmallCalendarExample(),
  );
}

class SmallCalendarExample extends StatefulWidget {
  @override
  _SmallCalendarExampleState createState() => new _SmallCalendarExampleState();
}

class _SmallCalendarExampleState extends State<SmallCalendarExample> {
  String _displayedMonthText;

  bool _showWeekdayIndication = true;

  bool _showTicks = true;

  SmallCalendarPagerController _smallCalendarPagerController;

  SmallCalendarDataController _smallCalendarDataController;

  @override
  void initState() {
    super.initState();

    DateTime initialMonth = new DateTime.now();
    DateTime minimumMonth =
        new DateTime(initialMonth.year - 1, initialMonth.month);
    DateTime maximumMonth =
        new DateTime(initialMonth.year + 1, initialMonth.month);

    _smallCalendarPagerController = new SmallCalendarPagerController(
      initialMonth: initialMonth,
      minimumMonth: minimumMonth,
      maximumMonth: maximumMonth,
    );

    _smallCalendarDataController = new SmallCalendarDataController();

    _updateDisplayedMonthText();
  }

  void _updateDisplayedMonthText() {
    setState(() {
      DateTime displayedMonth = _smallCalendarPagerController.displayedMonth;

      _displayedMonthText =
          "Displayed Month: ${displayedMonth.year}.${displayedMonth.month}";
    });
  }

  Future<bool> _isTodayCallback(DateTime date) async {
    DateTime now = new DateTime.now();

    return now.year == date.year &&
        now.month == date.month &&
        now.day == date.day;
  }

  Future<bool> _isSelectedCallback(DateTime date) async {
    return date.day == 10;
  }

  Future<bool> _hasTick1Callback(DateTime date) async {
    return date.day == 1 || date.day == 4 || date.day == 5;
  }

  Future<bool> _hasTick2Callback(DateTime date) async {
    return date.day == 2 || date.day == 4 || date.day == 5;
  }

  Future<bool> _hasTick3Callback(DateTime date) async {
    await new Future.delayed(new Duration(seconds: 1));

    return date.day == 3 || date.day == 5;
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "Small Calendar example",
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text("Small Calendar example"),
        ),
        // Creates an inner BuildContext so that the onDayPressed method in SmallCalendar
        // can refer to the Scaffold with Scaffold.of().
        body: new Builder(builder: (BuildContext context) {
          return new Column(
            children: <Widget>[
              new Expanded(
                  child: new Container(
                color: Colors.grey[200],
                child: new Center(
                  child: new Container(
                    width: 250.0,
                    height: 250.0,
                    color: Colors.white,

                    /// SmallCalendarData
                    child: new SmallCalendarData(
                      firstWeekday: DateTime.monday,
                      isTodayCallback: _isTodayCallback,
                      isSelectedCallback: _isSelectedCallback,
                      hasTick1Callback: _hasTick1Callback,
                      hasTick2Callback: _hasTick2Callback,
                      hasTick3Callback: _hasTick3Callback,
                      controller: _smallCalendarDataController,

                      /// SmallCalendarStyle
                      child: new SmallCalendarStyle(
                          showWeekdayIndication: _showWeekdayIndication,
                          weekdayIndicationStyle: new WeekdayIndicationStyle(
                            backgroundColor: Theme.of(context).primaryColor,
                          ),
                          dayStyle: new DayStyle(
                            showTicks: _showTicks,
                            tick3Color: Colors.orange,
                          ),

                          /// SmallCalendarPager
                          child: new SmallCalendarPager(
                            controller: _smallCalendarPagerController,
                            onMonthChanged: (DateTime month) {
                              _updateDisplayedMonthText();
                            },
                            pageBuilder:
                                (BuildContext context, DateTime month) {
                              /// SmallCalendar
                              return new SmallCalendar(
                                month: month,
                                onDayTap: (DateTime day) {
                                  print(
                                    "Pressed on: ${day.year}.${day.month}.${day.day}",
                                  );

                                  // shows SnackBar
                                  Scaffold
                                      .of(context)
                                      .showSnackBar(new SnackBar(
                                          content: new Text(
                                        "Pressed on:  ${day.year}.${day.month}.${day.day} ",
                                      )));
                                },
                              );
                            },
                          )),
                    ),
                  ),
                ),
              )),
              new Expanded(
                  child: new Container(
                      margin: new EdgeInsets.symmetric(horizontal: 16.0),
                      child: new SingleChildScrollView(
                        child: new Column(
                          children: <Widget>[
                            new Padding(padding: new EdgeInsets.only(top: 8.0)),
                            new Text(_displayedMonthText),
                            new Padding(
                              padding: new EdgeInsets.symmetric(vertical: 4.0),
                              child: new RaisedButton(
                                  child: new Text("Go To Today"),
                                  onPressed: () {
                                    _smallCalendarPagerController
                                        .jumpToMonth(new DateTime.now());
                                  }),
                            ),
                            new Divider(),
                            new CheckboxListTile(
                              value: _showWeekdayIndication,
                              title: new Text("Show weekday indication"),
                              onChanged: (newValue) {
                                setState(() {
                                  _showWeekdayIndication = newValue;
                                });
                              },
                            ),
                            new Divider(),
                            new CheckboxListTile(
                              value: _showTicks,
                              title: new Text("Show ticks"),
                              onChanged: (newValue) {
                                setState(() {
                                  _showTicks = newValue;
                                });
                              },
                            ),
                            new Divider(),
                            new Text("""For example purpuses:
                    * every first day of month has tick1
                    * every second day of month has tick2
                    * every third day of month has tick3
                    * every fourth day of month has tick1 and tick2
                    * every fifth day of month has tick1, tick2 and tick3
                    * every tenth day of month is selected"""),
                            new Padding(padding: new EdgeInsets.only(top: 8.0)),
                          ],
                        ),
                      ))),
            ],
          );
        }),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  small_calendar: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:small_calendar/small_calendar.dart';
  
Version Uploaded Documentation Archive
0.4.0 May 9, 2018 Go to the documentation of small_calendar 0.4.0 Download small_calendar 0.4.0 archive
0.3.1 Apr 11, 2018 Go to the documentation of small_calendar 0.3.1 Download small_calendar 0.3.1 archive
0.3.0 Mar 5, 2018 Go to the documentation of small_calendar 0.3.0 Download small_calendar 0.3.0 archive
0.0.4 Feb 28, 2018 Go to the documentation of small_calendar 0.0.4 Download small_calendar 0.0.4 archive
0.0.3 Feb 28, 2018 Go to the documentation of small_calendar 0.0.3 Download small_calendar 0.0.3 archive
0.0.2 Feb 28, 2018 Go to the documentation of small_calendar 0.0.2 Download small_calendar 0.0.2 archive
0.0.1 Feb 28, 2018 Go to the documentation of small_calendar 0.0.1 Download small_calendar 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
39
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0