Compare commits

..
11 changed files with 224 additions and 277 deletions
@@ -10,7 +10,7 @@ part 'events_event.dart';
part 'events_state.dart'; part 'events_state.dart';
class CalendarEventsBloc extends Bloc<CalendarEventsEvent, CalendarEventState> { class CalendarEventsBloc extends Bloc<CalendarEventsEvent, CalendarEventState> {
EventController eventController = EventController(); final EventController eventController = EventController();
final CalendarSystemService calendarService; final CalendarSystemService calendarService;
CalendarEventsBloc({ CalendarEventsBloc({
@@ -20,9 +20,7 @@ class CalendarEventsBloc extends Bloc<CalendarEventsEvent, CalendarEventState> {
on<AddEvent>(_onAddEvent); on<AddEvent>(_onAddEvent);
on<DisposeResources>(_onDisposeResources); on<DisposeResources>(_onDisposeResources);
on<GoToWeek>(_onGoToWeek); on<GoToWeek>(_onGoToWeek);
on<ResetEvents>(_onResetEvents);
} }
Future<void> _onLoadEvents( Future<void> _onLoadEvents(
LoadEvents event, LoadEvents event,
Emitter<CalendarEventState> emit, Emitter<CalendarEventState> emit,
@@ -128,18 +126,4 @@ class CalendarEventsBloc extends Bloc<CalendarEventsEvent, CalendarEventState> {
eventController.dispose(); eventController.dispose();
return super.close(); return super.close();
} }
void _onResetEvents(
ResetEvents event,
Emitter<CalendarEventState> emit,
) {
if (calendarService is MemoryCalendarServiceWithRemoteFallback) {
(calendarService as MemoryCalendarServiceWithRemoteFallback)
.memoryService
.clear();
}
eventController.dispose();
eventController = EventController();
emit(EventsInitial());
}
} }
@@ -29,10 +29,3 @@ class CheckWeekHasEvents extends CalendarEventsEvent {
final DateTime weekStart; final DateTime weekStart;
const CheckWeekHasEvents(this.weekStart); const CheckWeekHasEvents(this.weekStart);
} }
class ResetEvents extends CalendarEventsEvent {
const ResetEvents();
@override
List<Object?> get props => [];
}
@@ -1,4 +1,3 @@
// booking_page.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:calendar_view/calendar_view.dart'; import 'package:calendar_view/calendar_view.dart';
@@ -27,33 +26,7 @@ class BookingPage extends StatefulWidget {
} }
class _BookingPageState extends State<BookingPage> { class _BookingPageState extends State<BookingPage> {
@override late final EventController _eventController;
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(create: (_) => SelectedBookableSpaceBloc()),
BlocProvider(create: (_) => DateSelectionBloc()),
BlocProvider(
create: (_) => CalendarEventsBloc(
calendarService: MemoryCalendarServiceWithRemoteFallback(
remoteService: RemoteCalendarService(HTTPService()),
memoryService: MemoryCalendarService(),
),
),
),
],
child: _BookingPageContent(),
);
}
}
class _BookingPageContent extends StatefulWidget {
@override
State<_BookingPageContent> createState() => _BookingPageContentState();
}
class _BookingPageContentState extends State<_BookingPageContent> {
late EventController _eventController;
@override @override
void initState() { void initState() {
@@ -67,7 +40,7 @@ class _BookingPageContentState extends State<_BookingPageContent> {
super.dispose(); super.dispose();
} }
void _loadEvents(BuildContext context) { void _dispatchLoadEvents(BuildContext context) {
final selectedRoom = final selectedRoom =
context.read<SelectedBookableSpaceBloc>().state.selectedBookableSpace; context.read<SelectedBookableSpaceBloc>().state.selectedBookableSpace;
final dateState = context.read<DateSelectionBloc>().state; final dateState = context.read<DateSelectionBloc>().state;
@@ -87,170 +60,186 @@ class _BookingPageContentState extends State<_BookingPageContent> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<SelectedBookableSpaceBloc, SelectedBookableSpaceState>( return MultiBlocProvider(
listener: (context, state) { providers: [
if (state.selectedBookableSpace != null) { BlocProvider(create: (_) => SelectedBookableSpaceBloc()),
// Reset events and clear cache when room changes BlocProvider(create: (_) => DateSelectionBloc()),
context.read<CalendarEventsBloc>().add(ResetEvents()); BlocProvider(
_loadEvents(context); create: (_) => CalendarEventsBloc(
} calendarService: MemoryCalendarServiceWithRemoteFallback(
}, remoteService: RemoteCalendarService(
child: BlocListener<DateSelectionBloc, DateSelectionState>( HTTPService(),
listener: (context, state) { ),
_loadEvents(context); memoryService: MemoryCalendarService(),
}, ),
child: BlocListener<CalendarEventsBloc, CalendarEventState>( )),
],
child: Builder(
builder: (context) =>
BlocListener<CalendarEventsBloc, CalendarEventState>(
listenWhen: (prev, curr) => curr is EventsLoaded,
listener: (context, state) { listener: (context, state) {
if (state is EventsLoaded) { if (state is EventsLoaded) {
_eventController.removeWhere((_) => true); _eventController.removeWhere((_) => true);
_eventController.addAll(state.events); _eventController.addAll(state.events);
} }
}, },
child: Row( child: BlocListener<SelectedBookableSpaceBloc,
crossAxisAlignment: CrossAxisAlignment.start, SelectedBookableSpaceState>(
children: [ listener: (context, state) => _dispatchLoadEvents(context),
Expanded( child: BlocListener<DateSelectionBloc, DateSelectionState>(
child: Container( listener: (context, state) => _dispatchLoadEvents(context),
decoration: BoxDecoration( child: Row(
color: ColorsManager.whiteColors, crossAxisAlignment: CrossAxisAlignment.start,
boxShadow: [ children: [
BoxShadow( Expanded(
color: ColorsManager.blackColor.withOpacity(0.1), child: Container(
offset: const Offset(3, 0), decoration: BoxDecoration(
blurRadius: 6, color: ColorsManager.whiteColors,
spreadRadius: 0, boxShadow: [
), BoxShadow(
], color: ColorsManager.blackColor.withOpacity(0.1),
), offset: const Offset(3, 0),
child: Column( blurRadius: 6,
children: [ spreadRadius: 0,
Expanded(
flex: 2,
child: BlocBuilder<SelectedBookableSpaceBloc,
SelectedBookableSpaceState>(
builder: (context, state) {
return BookingSidebar(
onRoomSelected: (selectedRoom) {
context
.read<SelectedBookableSpaceBloc>()
.add(SelectBookableSpace(selectedRoom));
},
);
},
),
),
Expanded(
child:
BlocBuilder<DateSelectionBloc, DateSelectionState>(
builder: (context, dateState) {
return CustomCalendarPage(
selectedDate: dateState.selectedDate,
onDateChanged: (day, month, year) {
final newDate = DateTime(year, month, day);
context
.read<DateSelectionBloc>()
.add(SelectDate(newDate));
context.read<DateSelectionBloc>().add(
SelectDateFromSidebarCalendar(newDate));
},
);
},
),
),
],
),
),
),
Expanded(
flex: 5,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SvgTextButton(
svgAsset: Assets.homeIcon,
label: 'Manage Bookable Spaces',
onPressed: () {},
),
const SizedBox(width: 20),
SvgTextButton(
svgAsset: Assets.groupIcon,
label: 'Manage Users',
onPressed: () {},
),
],
),
BlocBuilder<DateSelectionBloc, DateSelectionState>(
builder: (context, state) {
final weekStart = state.weekStart;
final weekEnd =
weekStart.add(const Duration(days: 6));
return WeekNavigation(
weekStart: weekStart,
weekEnd: weekEnd,
onPreviousWeek: () {
context
.read<DateSelectionBloc>()
.add(PreviousWeek());
},
onNextWeek: () {
context
.read<DateSelectionBloc>()
.add(NextWeek());
},
);
},
), ),
], ],
), ),
const SizedBox(height: 20), child: Column(
Expanded( children: [
flex: 5, Expanded(
child: BlocBuilder<SelectedBookableSpaceBloc, flex: 2,
SelectedBookableSpaceState>( child: BlocBuilder<SelectedBookableSpaceBloc,
builder: (context, roomState) { SelectedBookableSpaceState>(
final selectedRoom = builder: (context, state) {
roomState.selectedBookableSpace; return BookingSidebar(
return BlocBuilder<DateSelectionBloc, onRoomSelected: (selectedRoom) {
context
.read<SelectedBookableSpaceBloc>()
.add(SelectBookableSpace(selectedRoom));
},
);
},
),
),
Expanded(
child: BlocBuilder<DateSelectionBloc,
DateSelectionState>( DateSelectionState>(
builder: (context, dateState) { builder: (context, dateState) {
return BlocBuilder<CalendarEventsBloc, return CustomCalendarPage(
CalendarEventState>( selectedDate: dateState.selectedDate,
builder: (context, eventState) { onDateChanged: (day, month, year) {
return WeeklyCalendarPage( final newDate = DateTime(year, month, day);
key: ValueKey( context
selectedRoom?.uuid ?? 'no-room'), .read<DateSelectionBloc>()
startTime: selectedRoom .add(SelectDate(newDate));
?.bookableConfig.startTime, context.read<DateSelectionBloc>().add(
endTime: SelectDateFromSidebarCalendar(newDate));
selectedRoom?.bookableConfig.endTime, },
weekStart: dateState.weekStart, );
selectedDate: dateState.selectedDate, },
eventController: _eventController, ),
selectedDateFromSideBarCalender: context ),
.watch<DateSelectionBloc>() ],
.state ),
.selectedDateFromSideBarCalender, ),
// isLoading: eventState is EventsLoading, ),
Expanded(
flex: 5,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SvgTextButton(
svgAsset: Assets.homeIcon,
label: 'Manage Bookable Spaces',
onPressed: () {},
),
const SizedBox(width: 20),
SvgTextButton(
svgAsset: Assets.groupIcon,
label: 'Manage Users',
onPressed: () {},
),
],
),
BlocBuilder<DateSelectionBloc,
DateSelectionState>(
builder: (context, state) {
final weekStart = state.weekStart;
final weekEnd =
weekStart.add(const Duration(days: 6));
return WeekNavigation(
weekStart: weekStart,
weekEnd: weekEnd,
onPreviousWeek: () {
context
.read<DateSelectionBloc>()
.add(PreviousWeek());
},
onNextWeek: () {
context
.read<DateSelectionBloc>()
.add(NextWeek());
},
);
},
),
],
),
Expanded(
flex: 5,
child: BlocBuilder<SelectedBookableSpaceBloc,
SelectedBookableSpaceState>(
builder: (context, roomState) {
final selectedRoom =
roomState.selectedBookableSpace;
return BlocBuilder<DateSelectionBloc,
DateSelectionState>(
builder: (context, dateState) {
return BlocListener<CalendarEventsBloc,
CalendarEventState>(
listenWhen: (prev, curr) =>
curr is EventsLoaded,
listener: (context, state) {
if (state is EventsLoaded) {
_eventController
.removeWhere((_) => true);
_eventController.addAll(state.events);
}
},
child: WeeklyCalendarPage(
startTime: selectedRoom
?.bookableConfig.startTime,
endTime: selectedRoom
?.bookableConfig.endTime,
weekStart: dateState.weekStart,
selectedDate: dateState.selectedDate,
eventController: _eventController,
selectedDateFromSideBarCalender: context
.watch<DateSelectionBloc>()
.state
.selectedDateFromSideBarCalender,
),
); );
}, },
); );
}, },
); ),
}, ),
), ],
), ),
], ),
), ),
), ],
), ),
], ),
), ),
), ),
), ),
@@ -76,29 +76,21 @@ class __SidebarContentState extends State<_SidebarContent> {
builder: (context, state) { builder: (context, state) {
return Column( return Column(
children: [ children: [
Padding( const _SidebarHeader(title: 'Spaces'),
padding: const EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Container(
decoration: BoxDecoration(
color: ColorsManager.whiteColors,
boxShadow: [
BoxShadow(
color: ColorsManager.blackColor.withOpacity(0.1),
offset: const Offset(0, 4),
blurRadius: 4,
spreadRadius: 0,
),
],
),
child: _SidebarHeader(title: 'Spaces')),
),
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: ColorsManager.whiteColors, color: ColorsManager.whiteColors,
borderRadius: BorderRadius.circular(8.0),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: ColorsManager.blackColor.withOpacity(0.1), color: ColorsManager.blackColor.withOpacity(0.1),
offset: const Offset(0, 4), offset: const Offset(0, -2),
blurRadius: 4,
spreadRadius: 0,
),
BoxShadow(
color: ColorsManager.blackColor.withOpacity(0.1),
offset: const Offset(0, 2),
blurRadius: 4, blurRadius: 4,
spreadRadius: 0, spreadRadius: 0,
), ),
@@ -228,7 +220,7 @@ class _SidebarHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(16.0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -66,28 +66,18 @@ class _CustomCalendarPageState extends State<CustomCalendarPage> {
weekdayLabels: const ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'], weekdayLabels: const ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
); );
return Container( return CalendarDatePicker2(
decoration: const BoxDecoration( config: config,
border: Border( value: [_selectedDate],
top: BorderSide( onValueChanged: (dates) {
color: ColorsManager.textGray, final picked = dates.first;
width: 1.0, if (picked != null) {
), setState(() {
), _selectedDate = picked;
), });
child: CalendarDatePicker2( widget.onDateChanged(picked.day, picked.month, picked.year);
config: config, }
value: [_selectedDate], },
onValueChanged: (dates) {
final picked = dates.first;
if (picked != null) {
setState(() {
_selectedDate = picked;
});
widget.onDateChanged(picked.day, picked.month, picked.year);
}
},
),
); );
} }
} }
@@ -32,17 +32,15 @@ class EventTileWidget extends StatelessWidget {
return Expanded( return Expanded(
child: Container( child: Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.all(5), padding: EdgeInsets.all(5),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isEventEnded color: isEventEnded
? ColorsManager.grayColor.withOpacity(0.1) ? ColorsManager.grayColor.withOpacity(0.1)
: ColorsManager.blue1.withOpacity(0.1), : ColorsManager.blue1.withOpacity(0.1),
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
border: Border( border: const Border(
left: BorderSide( left: BorderSide(
color: isEventEnded color: ColorsManager.grayColor,
? ColorsManager.grayColor
: ColorsManager.secondaryColor,
width: 4, width: 4,
), ),
), ),
@@ -21,7 +21,7 @@ class RoomListItem extends StatelessWidget {
groupValue: isSelected ? room.uuid : null, groupValue: isSelected ? room.uuid : null,
visualDensity: const VisualDensity(vertical: -4), visualDensity: const VisualDensity(vertical: -4),
onChanged: (value) => onTap(), onChanged: (value) => onTap(),
activeColor: ColorsManager.secondaryColor, activeColor: ColorsManager.primaryColor,
title: Text( title: Text(
room.spaceName, room.spaceName,
maxLines: 2, maxLines: 2,
@@ -14,33 +14,26 @@ class WeekDayHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ColoredBox( return Column(
color: isSelectedDay children: [
? ColorsManager.secondaryColor.withOpacity(0.1) Text(
: Colors.transparent, DateFormat('EEE').format(date).toUpperCase(),
child: Column( style: TextStyle(
children: [ fontWeight: FontWeight.w400,
const SizedBox( fontSize: 14,
height: 10, color: isSelectedDay ? Colors.blue : Colors.black,
), ),
Text( ),
DateFormat('EEE').format(date).toUpperCase(), Text(
style: const TextStyle( DateFormat('d').format(date),
fontWeight: FontWeight.w400, style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w700,
color: ColorsManager.blackColor, fontSize: 20,
), color:
isSelectedDay ? ColorsManager.blue1 : ColorsManager.blackColor,
), ),
Text( ),
DateFormat('d').format(date), ],
style: const TextStyle(
fontWeight: FontWeight.w700,
fontSize: 30,
color: ColorsManager.blackColor,
),
),
],
),
); );
} }
} }
@@ -24,7 +24,7 @@ class WeeklyCalendarPage extends StatelessWidget {
}); });
static const double timeLineWidth = 65; static const double timeLineWidth = 65;
static const int totalDays = 7; static const int totalDays = 7;
static const double dayColumnWidth = 220; static const double dayColumnWidth = 220;
final double calendarContentWidth = final double calendarContentWidth =
timeLineWidth + (totalDays * dayColumnWidth); timeLineWidth + (totalDays * dayColumnWidth);
@@ -57,10 +57,13 @@ class WeeklyCalendarPage extends StatelessWidget {
); );
} }
const double timeLineWidth = 90;
const double timeLineWidth = 65;
return LayoutBuilder( return LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
bool isInRange(DateTime date, DateTime start, DateTime end) { bool isInRange(DateTime date, DateTime start, DateTime end) {
!date.isBefore(start) && !date.isAfter(end); !date.isBefore(start) && !date.isAfter(end);
// remove this line and Check if the date is within the range // remove this line and Check if the date is within the range
@@ -97,6 +100,7 @@ class WeeklyCalendarPage extends StatelessWidget {
width: width, width: width,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.orange.withOpacity(0.13), color: Colors.orange.withOpacity(0.13),
borderRadius: BorderRadius.circular(8),
), ),
); );
} else if (isSelected) { } else if (isSelected) {
@@ -106,6 +110,7 @@ class WeeklyCalendarPage extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
color: color:
ColorsManager.spaceColor.withOpacity(0.07), ColorsManager.spaceColor.withOpacity(0.07),
borderRadius: BorderRadius.circular(8),
), ),
); );
} }
@@ -138,7 +143,7 @@ class WeeklyCalendarPage extends StatelessWidget {
heightPerMinute: 1.7, heightPerMinute: 1.7,
showLiveTimeLineInAllDays: false, showLiveTimeLineInAllDays: false,
showVerticalLines: true, showVerticalLines: true,
emulateVerticalOffsetBy: -95, emulateVerticalOffsetBy: -80,
startDay: WeekDays.monday, startDay: WeekDays.monday,
liveTimeIndicatorSettings: liveTimeIndicatorSettings:
const LiveTimeIndicatorSettings( const LiveTimeIndicatorSettings(
@@ -156,7 +161,7 @@ class WeeklyCalendarPage extends StatelessWidget {
}, },
timeLineWidth: timeLineWidth, timeLineWidth: timeLineWidth,
weekPageHeaderBuilder: (start, end) => Container(), weekPageHeaderBuilder: (start, end) => Container(),
weekTitleHeight: 90, weekTitleHeight: 60,
weekNumberBuilder: (firstDayOfWeek) => Padding( weekNumberBuilder: (firstDayOfWeek) => Padding(
padding: const EdgeInsets.only(right: 15, bottom: 10), padding: const EdgeInsets.only(right: 15, bottom: 10),
child: Column( child: Column(
@@ -203,6 +208,8 @@ class WeeklyCalendarPage extends StatelessWidget {
}, },
); );
} }
} }
bool isSameDay(DateTime d1, DateTime d2) { bool isSameDay(DateTime d1, DateTime d2) {
@@ -475,8 +475,8 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
horizontal: context.screenWidth * 0.3, horizontal: context.screenWidth * 0.3,
vertical: context.screenHeight * 0.3, vertical: context.screenHeight * 0.3,
), ),
minScale: 0.5, minScale: 0.1,
maxScale: 3.0, maxScale: 4.0,
constrained: false, constrained: false,
child: SizedBox( child: SizedBox(
width: context.screenWidth * 5, width: context.screenWidth * 5,
+2 -1
View File
@@ -140,5 +140,6 @@ abstract class ApiEndpoints {
static const String saveSchedule = '/schedule/{deviceUuid}'; static const String saveSchedule = '/schedule/{deviceUuid}';
static const String getBookableSpaces = '/bookable-spaces'; static const String getBookableSpaces = '/bookable-spaces';
static const String getBookings = '/bookings?month={mm}-{yyyy}&space={space}'; static const String getBookings =
'/bookings?month={mm}%2F{yyyy}&space={space}';
} }