diff --git a/lib/models/converter/group_converter.dart b/lib/models/converter/group_converter.dart index 96b227f..bcbeba8 100644 --- a/lib/models/converter/group_converter.dart +++ b/lib/models/converter/group_converter.dart @@ -5,7 +5,13 @@ class GroupConverter implements JsonConverter> { const GroupConverter(); @override - Group fromJson(Map json) => Group.fromJson(json); + Group fromJson(Map json) { + if (json != null) { + return Group.fromJson(json); + } else { + return null; + } + } @override Map toJson(Group group) => group.toJson(); diff --git a/lib/models/converter/notification_converter.dart b/lib/models/converter/notification_converter.dart index 110a1ef..5d04d7e 100644 --- a/lib/models/converter/notification_converter.dart +++ b/lib/models/converter/notification_converter.dart @@ -5,8 +5,14 @@ class NotificationConverter implements JsonConverter json) => Notification.fromJson(json); + Notification fromJson(Map json) { + if (json != null) { + return Notification.fromJson(json); + } else { + return null; + } + } @override - Map toJson(Notification notification) => notification.toJson(); + Map toJson(Notification notification) => notification?.toJson(); } diff --git a/lib/models/converter/participant_converter.dart b/lib/models/converter/participant_converter.dart index 8e49120..48bde2f 100644 --- a/lib/models/converter/participant_converter.dart +++ b/lib/models/converter/participant_converter.dart @@ -5,8 +5,14 @@ class ParticipantConverter implements JsonConverter json) => Participant.fromJson(json); + Participant fromJson(Map json) { + if (json != null) { + return Participant.fromJson(json); + } else { + return null; + } + } @override - Map toJson(Participant participant) => participant.toJson(); + Map toJson(Participant participant) => participant?.toJson(); } diff --git a/lib/models/converter/questionnaire_converter.dart b/lib/models/converter/questionnaire_converter.dart index 726b14c..4bf1869 100644 --- a/lib/models/converter/questionnaire_converter.dart +++ b/lib/models/converter/questionnaire_converter.dart @@ -5,8 +5,14 @@ class QuestionnaireConverter implements JsonConverter json) => Questionnaire.fromJson(json); + Questionnaire fromJson(Map json) { + if (json != null) { + return Questionnaire.fromJson(json); + } else { + return null; + } + } @override - Map toJson(Questionnaire questionnaire) => questionnaire.toJson(); + Map toJson(Questionnaire questionnaire) => questionnaire?.toJson(); } diff --git a/lib/pages/home/home_controller.dart b/lib/pages/home/home_controller.dart index 04fdb58..f51e6b4 100644 --- a/lib/pages/home/home_controller.dart +++ b/lib/pages/home/home_controller.dart @@ -1,19 +1,27 @@ +import 'package:flutter/cupertino.dart'; import 'package:morning_weakers/core/dummy_data.dart'; import 'package:morning_weakers/models/models.dart'; import 'package:morning_weakers/pages/home/home_state.dart'; +import 'package:morning_weakers/repositories/hackathon_repository.dart'; import 'package:state_notifier/state_notifier.dart'; class HomeController extends StateNotifier with LocatorMixin { HomeController() : super(const HomeState()); + HackathonRepository get hackathonRepository => read(); + @override void initState() { + debugPrint('debugger: initstatee'); getData(); } //TODO:API生えたら非同期処理実装する! - Future getData() { - final Hackathon hackathon = dummyHackathon(); + Future getData() async{ + debugPrint('debugger: hackathonId ${hackathonRepository.currentHackathonId}'); + final Hackathon hackathon = await hackathonRepository.getHackathon(hackathonRepository.currentHackathonId); + debugPrint('debugger: hackathonId ${hackathon}'); + //final Hackathon hackathon = dummyHackathon(); state = state.copyWith(hackathon: hackathon); } } diff --git a/lib/pages/home/widget/notification_widget.dart b/lib/pages/home/widget/notification_widget.dart index 908ecdc..b8a1024 100644 --- a/lib/pages/home/widget/notification_widget.dart +++ b/lib/pages/home/widget/notification_widget.dart @@ -7,9 +7,9 @@ import 'package:provider/provider.dart'; class NotificationWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final List notification = context.select>( - (state) => state.hackathon.notifications, - ); + // TODO: hackathonがnullだからそこfix + final List notification = + context.select>((state) => state.hackathon.notifications); // ignore: cascade_invocations notification.sort((a, b) => a.createdAt.compareTo(b.createdAt)); diff --git a/lib/repositories/hackathon_repository.dart b/lib/repositories/hackathon_repository.dart index 8db271e..0d3c467 100644 --- a/lib/repositories/hackathon_repository.dart +++ b/lib/repositories/hackathon_repository.dart @@ -14,7 +14,6 @@ class HackathonRepository { final Map hackMap = hackathon.copyWith(id: hackRef.documentID).toJson() ..remove('participants') ..remove('groups') - ..remove('questionnaire') ..remove('notifications'); debugPrint(hackMap.toString()); await hackRef.setData(hackMap).whenComplete(() { @@ -57,7 +56,7 @@ class HackathonRepository { ..putIfAbsent('id', () => hackRef.documentID) ..putIfAbsent('participants', () => participants) ..putIfAbsent('groups', () => groups) - ..putIfAbsent('notification', () => notifications))); + ..putIfAbsent('notifications', () => notifications))); } /// Drawerに表示するハッカソンアイコン一覧とidの取得, 所属なしならnullが返る