sliver_calendar 0.0.5

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

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),
              source: _calendarState,
            );

How to setup a source for the calendar widget.

class GameListCalendarState extends CalendarSource {
  List<Game> _listToShow;
  StreamSubscription<UpdateReason> _listening;

  @override
  Widget buildWidget(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;
  }

  @override
  void initState() {
    _listToShow = UserDatabaseData.instance.games.values.toList();
    _listening = UserDatabaseData.instance.gameStream.listen((UpdateReason r) {
      _listToShow = UserDatabaseData.instance.games.values.toList();
      state.updateEvents();
    });
  }

  @override
  void dispose() {
    _listening.cancel();
  }

  Future<void> loadGames(FilterDetails details) async {
    Iterable<Game> list = await UserDatabaseData.instance.getGames(details);

    _setGames(list);
  }

  void _setGames(Iterable<Game> res) {
    List<Game> games = res.toList();
    games.sort((a, b) => a.time.compareTo(b.time));

    _listToShow = games;
  }
}

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.

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> {
  CalendarSource source;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Column(
        children: <Widget>[
          new FutureBuilder(
            future: FlutterNativeTimezone.getLocalTimezone(),
            builder: (BuildContext context, AsyncSnapshot<String> tz) {
              if (tz.hasData) {
                Location loc = getLocation(tz.data);
                if (source == null) {
                  source = new CalendarEventSource(loc);
                }
                return new Expanded(
                  child: new CalendarWidget(
                    initialDate: new TZDateTime.now(loc),
                    location: loc,
                    source: source,
                    bannerHeader:
                        new AssetImage("assets/images/calendarheader.jpg"),
                    monthHeader:
                        new AssetImage("assets/images/calendarbanner.jpg"),
                  ),
                );
              } else {
                return new Center(
                  child: new Text("Getting the timezone"),
                );
              }
            },
          ),
        ],
      ),
    );
  }
}

class CalendarEventSource extends CalendarSource {
  List<CalendarEvent> events = [];
  final Location loc;
  Random random = new Random();

  CalendarEventSource(this.loc);

  @override
  List<CalendarEvent> getEvents(DateTime start, DateTime end) {
    return events;
  }

  @override
  void dispose() {}

  @override
  void initState() {
    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))));
    }
  }

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

Use this package as a library

1. Depend on it

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


dependencies:
  sliver_calendar: "^0.0.5"

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.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

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95 / 100
Overall score:
Weighted score of the above. [more]
49
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Use constrained dependencies.

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

  • The description is too short.

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

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

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

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <=2.0.0
flutter 0.0.0
flutter_localizations 0.0.0
flutter_native_timezone ^1.0.0 1.0.0
intl ^0.15.5 0.15.6
timezone 0.5.0-dev-2
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
path 1.5.1 1.6.1
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7
Dev dependencies
flutter_test
test any