sliver_calendar 0.1.0

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

Calendar

Shows a scrolling calendar list of events. This is still relatively basic, it always assumes that the getEvents returns the entire list of calendar events (mostly ignoring the values passed into the source). It does work however :) Right now it also assumes there is an asset at assets/images/calendarheader.png which it will use to display the header and an asset at assets/images/calendarbanner.jpg which it will use for the month header.

The calendar uses slivers to display the widgets in the view and lets you scroll forward and backward through the events. The header widget will drop down and open up the days of the month, letting you select specific days as well as move back and forth between the months. By default it displays a list of events and not a day view, the day view code is all just a stub right now.

Here is how to use the calendar widget itself:

new CalendarWidget(
              initialDate: new TZDateTime.now(local),
              buildItem: buildItem,
              getEvents: getEvents,
            );

How to setup a source for the calendar widget.

...
  List<Game> _listToShow;
  StreamSubscription<UpdateReason> _listening;

  @override
  Widget buildItem(BuildContext context, CalendarEvent event) {
    return new GameCard(_listToShow[event.index]);
  }

  @override
  List<CalendarEvent> getEvents(DateTime start, DateTime end) {
    if (_listToShow == null) {
      _listToShow = UserDatabaseData.instance.games.values.toList();
    }
    if (_listToShow == null) {
      return [];
    }
    List<CalendarEvent> events = new List<CalendarEvent>();
    int pos = 0;
    _listToShow.forEach((Game g) => events.add(new CalendarEvent(
        instant: g.tzTime, instantEnd: g.tzEndTime, index: pos++)));
    return events;
  }
...

Example of the calendar widget in action: <img src="https://github.com/pinkfish/flutter_calendar/blob/master/screenshots/screenrecording.gif?raw=true">

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

[0.0.1] - May 2018

  • Add in the basics for the sliver calendar.

[0.0.3] - Jun 7rth 2018

  • Add in the date range correctly.
  • Fix up views with the same date,

[0.0.4] = Jun 10th 2018

  • Fix subscription cancel/fix up for the pub spec.
  • Fix the homepage for the calendar code.

[0.1.0] - Sep 26th 2018

  • Change the subscription model to make it more in line with how flutter normally works.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sliver_calendar/sliver_calendar.dart';
import 'package:timezone/timezone.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'dart:math';
import 'dart:typed_data';
import 'dart:async';

void main() async {
  ByteData loadedData;

  await Future.wait([
    rootBundle.load('assets/timezone/2018c.tzf').then((ByteData data) {
      loadedData = data;
      print('loaded data');
    })
  ]);
  initializeDatabase(loadedData.buffer.asUint8List());
  runApp(new MyApp());
}

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

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

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

class _MyHomePageState extends State<MyHomePage> {
  List<CalendarEvent> events = <CalendarEvent>[];
  Location loc;
  Random random = new Random();

  void initState() {
    super.initState();
  }

  Widget buildItem(BuildContext context, CalendarEvent e) {
    return new Card(
      child: new ListTile(
        title: new Text("Event ${e.index}"),
        subtitle: new Text("Yay for events"),
        leading: const Icon(Icons.gamepad),
      ),
    );
  }

  List<CalendarEvent> getEvents(DateTime start, DateTime end) {
    if (loc != null && events.length == 0) {
      TZDateTime nowTime =
      new TZDateTime.now(loc).subtract(new Duration(days: 5));
      for (int i = 0; i < 20; i++) {
        TZDateTime start =
        nowTime.add(new Duration(days: i + random.nextInt(10)));
        events.add(new CalendarEvent(
            index: i,
            instant: start,
            instantEnd: start.add(new Duration(minutes: 30))));
      }
    }
    return events;
  }


  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Column(
        children: <Widget>[
          new FutureBuilder<String>(
            future: FlutterNativeTimezone.getLocalTimezone(),
            builder: (BuildContext context, AsyncSnapshot<String> tz) {
              if (tz.hasData) {
                 loc = getLocation(tz.data);

                return new Expanded(
                  child: new CalendarWidget(
                    initialDate: new TZDateTime.now(loc),
                    location: loc,
                    buildItem: buildItem,
                    getEvents: getEvents,
                    bannerHeader:
                        new AssetImage("assets/images/calendarheader.jpg"),
                    monthHeader:
                        new AssetImage("assets/images/calendarbanner.jpg"),
                  ),
                );
              } else {
                return new Center(
                  child: new Text("Getting the timezone"),
                );
              }
            },
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  sliver_calendar: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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:sliver_calendar/sliver_calendar.dart';
  
Version Uploaded Documentation Archive
0.1.0 Sep 26, 2018 Go to the documentation of sliver_calendar 0.1.0 Download sliver_calendar 0.1.0 archive
0.0.6 Sep 6, 2018 Go to the documentation of sliver_calendar 0.0.6 Download sliver_calendar 0.0.6 archive
0.0.5 Jun 11, 2018 Go to the documentation of sliver_calendar 0.0.5 Download sliver_calendar 0.0.5 archive
0.0.4 Jun 11, 2018 Go to the documentation of sliver_calendar 0.0.4 Download sliver_calendar 0.0.4 archive
0.0.3 Jun 7, 2018 Go to the documentation of sliver_calendar 0.0.3 Download sliver_calendar 0.0.3 archive
0.0.2 May 30, 2018 Go to the documentation of sliver_calendar 0.0.2 Download sliver_calendar 0.0.2 archive
0.0.1 May 30, 2018 Go to the documentation of sliver_calendar 0.0.1 Download sliver_calendar 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/calendar.dart. (-0.50 points)

Analysis of lib/src/calendar.dart reported 1 hint:

line 142 col 8: This method overrides a method annotated as @mustCallSuper in 'State', but does not invoke the overridden method.

Fix lib/src/calendarevent.dart. (-0.50 points)

Analysis of lib/src/calendarevent.dart reported 1 hint:

line 3 col 8: Unused import: 'sliverscrollviewcalendar.dart'.

Format lib/src/calendarheader.dart.

Run flutter format to format lib/src/calendarheader.dart.

Format lib/src/sliverlistcalendar.dart.

Run flutter format to format lib/src/sliverlistcalendar.dart.

Format lib/src/sliverscrollviewcalendar.dart.

Run flutter format to format lib/src/sliverscrollviewcalendar.dart.

Maintenance issues and suggestions

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: timezone.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
flutter_localizations 0.0.0
flutter_native_timezone ^1.0.0 1.0.1
intl ^0.15.5 0.15.7
timezone 0.5.0-dev-3
Transitive dependencies
collection 1.14.11
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test any