Skip to content

Commit

Permalink
Extended example with the ability to add additional events to the lis…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
rwbr committed Aug 17, 2021
1 parent acacf7d commit c2264fc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
54 changes: 45 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -22,16 +24,16 @@ class CalendarScreen extends StatefulWidget {
}

class _CalendarScreenState extends State<CalendarScreen> {
List<NeatCleanCalendarEvent> _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<DateTime, List<NeatCleanCalendarEvent>> _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',
Expand Down Expand Up @@ -97,13 +99,17 @@ class _CalendarScreenState extends State<CalendarScreen> {
@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));
}

@override
Widget build(BuildContext context) {
print(_events.length);
return Scaffold(
body: SafeArea(
child: Calendar(
Expand All @@ -123,6 +129,36 @@ class _CalendarScreenState extends State<CalendarScreen> {
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,
),
);
}

Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_neat_and_clean_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class _CalendarState extends State<Calendar> {
: Container(),
);
} else {
// eventLiostBuilder is not null
// eventListBuilder is not null
return widget.eventListBuilder!(context, _selectedEvents!);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c2264fc

Please sign in to comment.