From c2264fcab46c7107dc908940500e00d2323e0eb6 Mon Sep 17 00:00:00 2001 From: Ralf Weinbrecher Date: Tue, 17 Aug 2021 21:18:08 +0200 Subject: [PATCH] Extended example with the ability to add additional events to the list of today This is to illustrate, how you can add events to today's list and update the view. This change was inspired by issue #13. --- CHANGELOG.md | 4 ++ example/lib/main.dart | 54 ++++++++++++++++++++---- example/pubspec.lock | 8 ++-- lib/flutter_neat_and_clean_calendar.dart | 2 +- pubspec.lock | 6 +-- pubspec.yaml | 2 +- 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7210d..c465786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.2.3+11] - 2021-08-17 +* Extended example to illustrate how to add events to the list and update the view +* This is a reaction on issue #13 + ## [0.2.2+10] - 2021-05-06 * Issue #12 was fixed in this release * Now it's possible to use the parameter `isExpanded`to decide, if the widget should be shown in expanded mode diff --git a/example/lib/main.dart b/example/lib/main.dart index 7aba9b1..966f106 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:flutter_neat_and_clean_calendar/flutter_neat_and_clean_calendar.dart'; @@ -22,16 +24,16 @@ class CalendarScreen extends StatefulWidget { } class _CalendarScreenState extends State { + List _todaysEvents = [ + NeatCleanCalendarEvent('Event A', + startTime: DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day, 10, 0), + endTime: DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day, 12, 0), + description: 'A special event', + color: Colors.blue[700]), + ]; final Map> _events = { - DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day): [ - NeatCleanCalendarEvent('Event A', - startTime: DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day, 10, 0), - endTime: DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day, 12, 0), - description: 'A special event', - color: Colors.blue[700]), - ], DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 2): [ NeatCleanCalendarEvent('Event B', @@ -97,6 +99,9 @@ class _CalendarScreenState extends State { @override void initState() { super.initState(); + _events.putIfAbsent( + DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day), + () => _todaysEvents); // Force selection of today on first load, so that the list of today's events gets shown. _handleNewDate(DateTime( DateTime.now().year, DateTime.now().month, DateTime.now().day)); @@ -104,6 +109,7 @@ class _CalendarScreenState extends State { @override Widget build(BuildContext context) { + print(_events.length); return Scaffold( body: SafeArea( child: Calendar( @@ -123,6 +129,36 @@ class _CalendarScreenState extends State { color: Colors.black, fontWeight: FontWeight.w800, fontSize: 11), ), ), + floatingActionButton: FloatingActionButton( + onPressed: () { + // Add your onPressed code here! + Random random = Random(); + // Pick a random number in the range [0.0, 1.0) + double randomDouble = random.nextDouble(); + _todaysEvents.add(NeatCleanCalendarEvent('New Event', + startTime: DateTime( + DateTime.now().year, + DateTime.now().month, + DateTime.now().day, + DateTime.now().hour, + DateTime.now().minute), + endTime: DateTime( + DateTime.now().year, + DateTime.now().month, + DateTime.now().day, + DateTime.now().hour, + DateTime.now().minute + 15), + description: 'New event', + color: + Color((randomDouble * 0xFFFFFF).toInt()).withOpacity(1.0))); + setState(() { + _events[DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day)] = _todaysEvents; + }); + }, + child: const Icon(Icons.add), + backgroundColor: Colors.green, + ), ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 50fd9c7..e0ffa92 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.2.2+10" + version: "0.2.3+11" flutter_test: dependency: "direct dev" description: flutter @@ -113,7 +113,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -148,7 +148,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/lib/flutter_neat_and_clean_calendar.dart b/lib/flutter_neat_and_clean_calendar.dart index b4a6ac9..4a3b23e 100644 --- a/lib/flutter_neat_and_clean_calendar.dart +++ b/lib/flutter_neat_and_clean_calendar.dart @@ -453,7 +453,7 @@ class _CalendarState extends State { : Container(), ); } else { - // eventLiostBuilder is not null + // eventListBuilder is not null return widget.eventListBuilder!(context, _selectedEvents!); } } diff --git a/pubspec.lock b/pubspec.lock index a38f32a..cda6e0d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -99,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -134,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3b5917e..e78995a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_neat_and_clean_calendar description: Simple and clean flutter calendar with ability to slide up/down to show weekly/monthly calendar. Fork of [flutter_clean_calender](https://pub.dev/packages/flutter_clean_calendar) -version: 0.2.2+10 +version: 0.2.3+11 homepage: https://github.com/rwbr/flutter_neat_and_clean_calendar environment: