Last active
March 14, 2020 21:29
-
-
Save TetsuFe/34c9634ea88e2327dfea3b3c62df1854 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<List<dynamic>> fetchAllForChatListPage() async { | |
final url = BASE_URL + 'fetch_chat_list'; | |
var response = await http.get( | |
url, | |
); | |
if (response.statusCode == 200) { | |
final body = jsonDecode(utf8.decode(response.bodyBytes)) as List<dynamic>; | |
final chats = body | |
.map((v) => { | |
'id': v['id'], | |
'auth_user': v['auth_user'], | |
}) | |
.toList(); | |
return chats; | |
} else { | |
throw Exception( | |
'${response.statusCode}: すみません、エラーにより読み込めませんでした。画面を下にスワイプして再度読み込んでください。'); // Exception.message で取得できる | |
} | |
} | |
/* bloc | |
void fetchCustomChatList() async { | |
try { | |
final customChatList = await chatApi.fetchAllForChatListPage(); | |
setCustomChatList.add(customChatList); | |
} catch (e) { | |
setCustomChatList.addError(e.message); // Exception のメッセージは .message で取得 | |
} | |
} | |
*/ | |
/* builder側 | |
StreamBuilder( | |
initialData: chatListBloc.customChatList.value, | |
stream: chatListBloc.customChatList, | |
builder: (context, snapshot) { | |
if (snapshot.hasError) { | |
return Text(snapshot.error); | |
} else { | |
final customChatList = snapshot.data; | |
for (var customChat in customChatList) { | |
print(customChat['id']); | |
print(customChat['auth_user']); | |
print(customChat['partner']); | |
print(customChat['partnerName']); | |
print(customChat['partner_profile_image']); | |
print(customChat['created_at']); | |
print(customChat['latest_talk']); | |
print(customChat['chat_unread_talk_count']); | |
} | |
return Container(); | |
} | |
}), | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment