Skip to content

Commit

Permalink
#5 Correctly initialize the events data.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjtappe committed Dec 3, 2024
1 parent c613286 commit 6317286
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 48 deletions.
31 changes: 13 additions & 18 deletions lib/data/testData/test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,16 @@ class TestData {
// Schedule a series of events
// Around now(), add a series of short events
DateTime now = DateTime.now();
DateTime scheduleStart = now.subtract(Duration(
hours: now.hour,
minutes: now.minute,
seconds: now.second,
milliseconds: now.millisecond,
));
DateTime scheduleStart = DateTime(now.year, now.month, now.day);
List<DateTime> scheduleDays = [
scheduleStart.subtract(Duration(days: 1)),
scheduleStart,
scheduleStart.add(Duration(days: 1)),
];
int eventCount = 0;
TrackData track = tracks[0];
SpeakerData? speaker = speakers[0];
RoomData room = rooms[0];
TrackData track;
SpeakerData? speaker;
RoomData room;
for (DateTime day in scheduleDays) {
DateTime startTime = day.add(Duration(hours: 8));
while (startTime.hour < 22) {
Expand All @@ -105,13 +100,20 @@ class TestData {
if (startTime.isAfter(now.subtract(Duration(hours: 1, minutes: 1))) &&
startTime.isBefore(now.add(Duration(hours: 1, minutes: 1)))) {
duration = Duration(hours: 0, minutes: 30);
parallel = 3;
parallel = 2;
} else {
duration = Duration(hours: 1, minutes: 0);
parallel = 0;
}
DateTime endTime = startTime.add(duration);
for (int i = 0; i <= parallel; i++) {
track = tracks[eventCount % tracks.length];
room = rooms[eventCount % rooms.length];
if (eventCount % 2 == 0) {
speaker = speakers[eventCount % speakers.length];
} else {
speaker = null;
}
items.add(EventData(
start: startTime,
end: endTime,
Expand All @@ -121,16 +123,9 @@ class TestData {
speaker: speaker?.name,
room: room.name,
));
startTime = endTime;
track = tracks[eventCount % tracks.length];
room = rooms[eventCount % rooms.length];
if (eventCount % 2 == 0) {
speaker = speakers[eventCount % speakers.length];
} else {
speaker = null;
}
eventCount ++;
}
startTime = endTime;
}
}
return items;
Expand Down
36 changes: 21 additions & 15 deletions lib/pages/event_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,41 @@ class EventDetailsPage extends StatelessWidget {
listen: false,
);
List<TrackData> trackItems = [];
TrackData? trackItem = tracksProvider.getDataByName(
item.track!,
);
if (trackItem != null) {
trackItems.add(trackItem);
if (item.track != null) {
TrackData? trackItem = tracksProvider.getDataByName(
item.track!,
);
if (trackItem != null) {
trackItems.add(trackItem);
}
}

SpeakersProvider speakersProvider = Provider.of<SpeakersProvider>(
context,
listen: false,
);
List<SpeakerData> speakerItems = [];
SpeakerData? speakerItem = speakersProvider.getDataByName(
item.speaker!,
);
if (speakerItem != null) {
speakerItems.add(speakerItem);
if (item.speaker != null) {
SpeakerData? speakerItem = speakersProvider.getDataByName(
item.speaker!,
);
if (speakerItem != null) {
speakerItems.add(speakerItem);
}
}

RoomsProvider roomsProvider = Provider.of<RoomsProvider>(
context,
listen: false,
);
List<RoomData> roomItems = [];
RoomData? roomItem = roomsProvider.getDataByName(
item.room!,
);
if (roomItem != null) {
roomItems.add(roomItem);
if (item.room != null) {
RoomData? roomItem = roomsProvider.getDataByName(
item.room!,
);
if (roomItem != null) {
roomItems.add(roomItem);
}
}

FavoritesProvider favProvider =
Expand Down
25 changes: 10 additions & 15 deletions lib/pages/events_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_week_view/flutter_week_view.dart';
import 'package:iccm_eu_app/components/event_list_tile.dart';
import 'package:iccm_eu_app/components/page_title.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/rooms_provider.dart';
Expand Down Expand Up @@ -125,11 +124,7 @@ class DayViewCalendarState extends State<DayViewCalendar> {
builder: (context, itemList, child) {
DateTime current = itemList.earliestEvent().start;
// Normalize to start of day
current.subtract(Duration(
hours: current.hour,
minutes: current.minute,
seconds: current.second,
));
current = DateTime(current.year, current.month, current.day);
List<EventData> cutoffList = itemList.cutoffAfterDays(days: 16);
DateTime last = itemList.latestEvent(
items: cutoffList,
Expand All @@ -154,6 +149,7 @@ class DayViewCalendarState extends State<DayViewCalendar> {
maximumTime: HourMinute(hour: 23, minute: 0),
initialTime: initialTime,
dates: dates,
userZoomable: false,
events: Provider.of<EventsProvider>(context).items().map((
item) {
Color? backgroundColor = Colors.red;
Expand Down Expand Up @@ -206,7 +202,6 @@ class DayViewCalendarState extends State<DayViewCalendar> {
},
);
}).toList(),
userZoomable: true,
);
}
);
Expand Down Expand Up @@ -246,14 +241,14 @@ class EventListState extends State<EventList> {
Widget build(BuildContext context) {
return Column(
children: [
ListView(
shrinkWrap: true, // Important to prevent unbounded height issues
physics: const NeverScrollableScrollPhysics(), // Disable scrolling for static list
padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: const <Widget>[
PageTitle(title: 'Events'),
]
),
// ListView(
// shrinkWrap: true, // Important to prevent unbounded height issues
// physics: const NeverScrollableScrollPhysics(), // Disable scrolling for static list
// padding: const EdgeInsets.symmetric(horizontal: 16.0),
// children: const <Widget>[
// PageTitle(title: 'Events'),
// ]
// ),
Expanded( // Use Expanded to allow ListView.builder to take available space
child: Consumer<EventsProvider>( // Wrap ListView.builder with Consumer
builder: (context, itemList, child) {
Expand Down

0 comments on commit 6317286

Please sign in to comment.