Skip to content

Commit

Permalink
feat: calendar Event 세부정보 표시 UI 구현중 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
KoJaem committed Nov 30, 2023
1 parent c1ecf17 commit ecd79ca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 118 deletions.
42 changes: 4 additions & 38 deletions lib/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,10 @@ class Calendar extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Container(
// color: CustomColor.skyBlue,
// padding: const EdgeInsets.all(8.0),
width: double.infinity,
color: CustomColor.skyBlue,
padding: const EdgeInsets.only(
top: 12.0,
left: 12.0,
right: 12.0,
bottom: 30,
),
child: const CalendarWidget(),
),
Expanded(
child: Container(
// color: CustomColor.skyBlue,
// padding: const EdgeInsets.all(8.0),
color: CustomColor.pastelBlue,
padding: const EdgeInsets.all(12.0),
width: double.infinity,
child: ListView.separated(
separatorBuilder: (context, index) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
);
},
itemCount: 10, // Todo 리스트 받아와서 길이 체크
itemBuilder: (context, index) {
return const ScheduleBox(
bgColor: CustomColor.lightPurple,
);
},
),
),
)
],
child: Container(
width: double.infinity,
color: CustomColor.skyBlue,
child: const CalendarWidget(),
),
));
}
Expand Down
46 changes: 22 additions & 24 deletions lib/widgets/ScheduleBox.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:calendar_app/constants/customColor.dart';
import 'package:flutter/material.dart';
import 'package:googleapis/calendar/v3.dart';

class ScheduleBox extends StatelessWidget {
const ScheduleBox({super.key, required this.bgColor});

const ScheduleBox({super.key, required this.bgColor, required this.event});
final Color bgColor;
final dynamic event;
@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -21,37 +22,34 @@ class ScheduleBox extends StatelessWidget {
)
],
),
margin: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4.0,
),
padding: const EdgeInsets.symmetric(
horizontal: 30,
),
child: const Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Text(
'Sprint meeting',
style: TextStyle(
fontSize: 16,
color: CustomColor.white,
fontWeight: FontWeight.bold,
),
),
Text('14:00 ~ 15:30',
style: TextStyle(
fontSize: 16,
color: CustomColor.white,
fontWeight: FontWeight.bold,
)),
],
),
Text(
'3 Days remaining',
style: TextStyle(
fontSize: 14,
event['summary'],
style: const TextStyle(
fontSize: 16,
color: CustomColor.white,
fontWeight: FontWeight.bold,
),
),
Text(
event['start']['date'] != null
? '하루종일'
: "${event['start']['dateTime'].hours.toString().padLeft(2, '0')} ~ ${event['end']['dateTime']}",
style: const TextStyle(
fontSize: 16,
color: CustomColor.white,
fontWeight: FontWeight.bold,
)),
],
),
);
Expand Down
92 changes: 36 additions & 56 deletions lib/widgets/calendar_widget.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'dart:convert';
import 'dart:developer';

import 'package:calendar_app/constants/customColor.dart';
import 'package:calendar_app/utils/googleAccessToken.dart';
import 'package:calendar_app/widgets/ScheduleBox.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:googleapis/calendar/v3.dart';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
import 'package:table_calendar/table_calendar.dart';
Expand Down Expand Up @@ -43,20 +42,22 @@ class _CalendarWidgetState extends State<CalendarWidget> {
CalendarFormat _calendarFormat = CalendarFormat.month;
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay;
dynamic test;
dynamic monthEvents;
late final ValueNotifier<List<dynamic>> _selectedEvents;

@override
void initState() {
super.initState();
getGoogleCalendarMonthEvents(_focusedDay);
_selectedDay = _focusedDay;
_selectedEvents = ValueNotifier(_getEventsForDay(_selectedDay!));
}

List<dynamic> _getEventsForDay(DateTime day) {
// return dummyEvents[day] ?? [];
// return null;
if (test != null) {
print(test[day]);
return test[day] ?? [];
if (monthEvents != null) {
return monthEvents[day] ?? [];
}
return [];
}
Expand All @@ -66,6 +67,7 @@ class _CalendarWidgetState extends State<CalendarWidget> {
DateTime end = DateTime(focusedDay.year, focusedDay.month + 1, 1);
final FirebaseAuth auth = FirebaseAuth.instance;
User? user = auth.currentUser;
print('이거 실행');
if (user != null) {
try {
final accessToken = await getAccessToken();
Expand Down Expand Up @@ -102,9 +104,8 @@ class _CalendarWidgetState extends State<CalendarWidget> {
}
}
}
log(events.toString());
setState(() {
test = events;
monthEvents = events;
});
return events;

Expand All @@ -121,6 +122,7 @@ class _CalendarWidgetState extends State<CalendarWidget> {
return Column(
children: [
Container(
margin: const EdgeInsets.all(20.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: CustomColor.pastelBlue,
Expand Down Expand Up @@ -183,6 +185,7 @@ class _CalendarWidgetState extends State<CalendarWidget> {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
_selectedEvents.value = _getEventsForDay(selectedDay);
}
},
onFormatChanged: (format) {
Expand All @@ -198,55 +201,32 @@ class _CalendarWidgetState extends State<CalendarWidget> {
},
),
),
Expanded(
child: Container(
color: CustomColor.pastelBlue,
padding: const EdgeInsets.all(12.0),
child: ValueListenableBuilder<List<dynamic>>(
valueListenable: _selectedEvents,
builder: (context, value, _) {
return ListView.separated(
separatorBuilder: (context, index) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
);
},
itemCount: value.length,
itemBuilder: (context, index) {
return ScheduleBox(
bgColor: CustomColor.lightPurple, // Todo 커스텀
event: value[index],
);
},
);
},
),
),
)
],
);
}
}

// Future<Map<DateTime, List<Event>>?> getGoogleCalendarMonthEvents(
// DateTime focusedDay) async {
// DateTime start = DateTime(focusedDay.year, focusedDay.month, 1);
// DateTime end = DateTime(focusedDay.year, focusedDay.month + 1, 1);
// final FirebaseAuth auth = FirebaseAuth.instance;
// User? user = auth.currentUser;
// if (user != null) {
// try {
// final accessToken = await getAccessToken();
// String apiUrl =
// 'https://www.googleapis.com/calendar/v3/calendars/primary/events?timeMin=${start.toUtc().toIso8601String()}&timeMax=${end.toUtc().toIso8601String()}';
// Map<String, String> headers = {'Authorization': 'Bearer $accessToken'};
// var response = await http.get(
// Uri.parse(apiUrl),
// headers: headers,
// );
// final res = jsonDecode(response.body);

// final Map<DateTime, List<dynamic>> events = {};

// if (res.containsKey('items')) {
// if (res['items'] is List) {
// List<dynamic> items = res['items'];
// for (var item in items) {
// final String eventStartKey =
// item['start']['date'] ?? item['start']['dateTime'];
// DateTime parsedDateTime = DateTime.parse(eventStartKey);
// DateTime dateTimeWithYearMonthDay = DateTime(
// parsedDateTime.year, parsedDateTime.month, parsedDateTime.day);
// if (!events.containsKey(dateTimeWithYearMonthDay)) {
// events[dateTimeWithYearMonthDay] = [item];
// } else {
// // 같은 키 값이 있다면 해당 배열에 데이터 추가
// events[dateTimeWithYearMonthDay]!.add(item);
// }
// }
// }
// }
// return events as Map<DateTime, List<Event>>;

// // print(eventList[0].id);
// } catch (error) {
// print('error $error');
// }
// }
// return null;
// }

0 comments on commit ecd79ca

Please sign in to comment.