Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/models/converter/group_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ class GroupConverter implements JsonConverter<Group, Map<String, dynamic>> {
const GroupConverter();

@override
Group fromJson(Map<String, dynamic> json) => Group.fromJson(json);
Group fromJson(Map<String, dynamic> json) {
if (json != null) {
return Group.fromJson(json);
} else {
return null;
}
}

@override
Map<String, dynamic> toJson(Group group) => group.toJson();
Expand Down
10 changes: 8 additions & 2 deletions lib/models/converter/notification_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ class NotificationConverter implements JsonConverter<Notification, Map<String, d
const NotificationConverter();

@override
Notification fromJson(Map<String, dynamic> json) => Notification.fromJson(json);
Notification fromJson(Map<String, dynamic> json) {
if (json != null) {
return Notification.fromJson(json);
} else {
return null;
}
}

@override
Map<String, dynamic> toJson(Notification notification) => notification.toJson();
Map<String, dynamic> toJson(Notification notification) => notification?.toJson();
}
10 changes: 8 additions & 2 deletions lib/models/converter/participant_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ class ParticipantConverter implements JsonConverter<Participant, Map<String, dyn
const ParticipantConverter();

@override
Participant fromJson(Map<String, dynamic> json) => Participant.fromJson(json);
Participant fromJson(Map<String, dynamic> json) {
if (json != null) {
return Participant.fromJson(json);
} else {
return null;
}
}

@override
Map<String, dynamic> toJson(Participant participant) => participant.toJson();
Map<String, dynamic> toJson(Participant participant) => participant?.toJson();
}
10 changes: 8 additions & 2 deletions lib/models/converter/questionnaire_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ class QuestionnaireConverter implements JsonConverter<Questionnaire, Map<String,
const QuestionnaireConverter();

@override
Questionnaire fromJson(Map<String, dynamic> json) => Questionnaire.fromJson(json);
Questionnaire fromJson(Map<String, dynamic> json) {
if (json != null) {
return Questionnaire.fromJson(json);
} else {
return null;
}
}

@override
Map<String, dynamic> toJson(Questionnaire questionnaire) => questionnaire.toJson();
Map<String, dynamic> toJson(Questionnaire questionnaire) => questionnaire?.toJson();
}
12 changes: 10 additions & 2 deletions lib/pages/home/home_controller.dart
Original file line number Diff line number Diff line change
@@ -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<HomeState> with LocatorMixin {
HomeController() : super(const HomeState());

HackathonRepository get hackathonRepository => read<HackathonRepository>();

@override
void initState() {
debugPrint('debugger: initstatee');
getData();
}

//TODO:API生えたら非同期処理実装する!
Future<void> getData() {
final Hackathon hackathon = dummyHackathon();
Future<void> 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);
}
}
6 changes: 3 additions & 3 deletions lib/pages/home/widget/notification_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:provider/provider.dart';
class NotificationWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<model.Notification> notification = context.select<HomeState, List<model.Notification>>(
(state) => state.hackathon.notifications,
);
// TODO: hackathonがnullだからそこfix
final List<model.Notification> notification =
context.select<HomeState, List<model.Notification>>((state) => state.hackathon.notifications);
// ignore: cascade_invocations
notification.sort((a, b) => a.createdAt.compareTo(b.createdAt));

Expand Down
3 changes: 1 addition & 2 deletions lib/repositories/hackathon_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class HackathonRepository {
final Map<String, dynamic> hackMap = hackathon.copyWith(id: hackRef.documentID).toJson()
..remove('participants')
..remove('groups')
..remove('questionnaire')
..remove('notifications');
debugPrint(hackMap.toString());
await hackRef.setData(hackMap).whenComplete(() {
Expand Down Expand Up @@ -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が返る
Expand Down