firebase - 无法使用 oneSignal 发送消息,错误:字符串不是 List 类型的子类型
问题描述
我正在尝试使用 oneSignal 使用令牌 ID 从我的设备发送文本,我的令牌 ID 在 firebase 控制台中正确显示但是当我尝试发送它时出现错误type 'String' is not a subtype of type 'List<String>'
请帮我修复它
class _NewMessageState extends State<NewMessage> {
Future<Response> sendNotification(
List<String> tokenIdList, String contents, String heading) async {
return await post(
Uri.parse('https://onesignal.com/api/v1/notifications'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, dynamic>{
"app_id":
"385efff8-************-0fe852ac796c", //kAppId is the App Id that one get from the OneSignal When the application is registered.
"include_player_ids":
tokenIdList, //tokenIdList Is the List of All the Token Id to to Whom notification must be sent.
// android_accent_color reprsent the color of the heading text in the notifiction
"android_accent_color": "FF9976D2",
"small_icon": "ic_stat_onesignal_default",
"large_icon":
"https://www.filepicker.io/api/file/zPloHSmnQsix82nlj9Aj?filename=name.jpg",
"headings": {"en": heading},
"contents": {"en": contents},
}),
);
}
var _enterMessage = '';
//controller for textfield to clear it
final _controller = new TextEditingController();
void _sendMessage() async {
//send message
FocusScope.of(context).unfocus();
final user = FirebaseAuth.instance
.currentUser; //gets the current logged in user gives data like userId
final userData = await FirebaseFirestore.instance
.collection('users')
.doc(user.uid)
.get(); //get username
//create new message
FirebaseFirestore.instance.collection('chat').add(
//no authentication token required
{
'text': _enterMessage,
'createdAt':
Timestamp.now(), //TimeStamp is from cloud firestore package\
'userId': user
.uid, //to seperate chat left and right , differentiate between sender and receiver
'username': userData[
'username'], //the message now fetched will already have usernmae
'userImage': userData['image_url'], //access to url
'tokenId': userData['tokenId'],
}, //createdAT to sort the messages in order
);
_controller.clear(); //clear text field
sendNotification(userData["tokenId"], _enterMessage,
"Testing a message");
}
}
错误出现 sendNotification(userData["tokenId"], _enterMessage,
在 Firebase 的“聊天”集合中正确添加了带有 tokenId 的数据。我只是想不通使用一个信号sendNotification
解决方案
tokenIdList 是字符串列表,id 为数字吗?
推荐阅读
- swift - 使用未解析的标识符“OAuthProvider”
- javascript - 重定向不适用于单个组件中的 react-router
- ios - 找不到框架 Protobuf
- android - 改变了 stopLockTask 的行为?
- python - 来自 R / Python 中的数据帧的波周期子集列表(波从 0 -> 正峰值 -> 0 -> 负峰值 -> 0 进展)
- angular - Angular 指令 - 只有数字和 2 位小数,逗号分隔
- c# - 如何使用 OpenXML dll 在 Excel 中读取合并单元格的数据
- sqlite - 如何一次又一次地重复(递归)查询?
- angular - 上传贴纸/gifs/等。直接来自 Ionic 3 中的 Gboard(移动键盘)
- coq - 如何证明相同的子目标