do a few more remaining todos
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||
import 'package:simplecloudnotifier/utils/notifier.dart';
|
||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||
import 'package:simplecloudnotifier/utils/ui.dart';
|
||||
@@ -48,6 +53,12 @@ class _DebugActionsPageState extends State<DebugActionsPage> {
|
||||
text: 'Show Simple Notification',
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
UI.button(
|
||||
big: false,
|
||||
onPressed: _copyToken,
|
||||
text: 'Query+Copy FCM Token',
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
UI.button(
|
||||
big: false,
|
||||
onPressed: _sendTokenToServer,
|
||||
@@ -66,7 +77,46 @@ class _DebugActionsPageState extends State<DebugActionsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _sendTokenToServer() {
|
||||
//TODO
|
||||
void _sendTokenToServer() async {
|
||||
try {
|
||||
final auth = AppAuth();
|
||||
|
||||
final clientID = auth.getClientID();
|
||||
if (clientID == null) {
|
||||
Toaster.error("Error", "No Client set");
|
||||
return;
|
||||
}
|
||||
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken == null) {
|
||||
Toaster.error("Error", "No FCM token returned from Firebase");
|
||||
return;
|
||||
}
|
||||
|
||||
var newClient = await APIClient.updateClient(auth, clientID, fcmToken: fcmToken);
|
||||
auth.setClientAndClientID(newClient);
|
||||
|
||||
Toaster.success("Success", "Token sent to server");
|
||||
} catch (exc, trace) {
|
||||
Toaster.error("Error", "An error occurred while sending the token: ${exc.toString()}");
|
||||
ApplicationLog.error("An error occurred while sending the token: ${exc.toString()}", trace: trace);
|
||||
}
|
||||
}
|
||||
|
||||
void _copyToken() async {
|
||||
try {
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken == null) {
|
||||
Toaster.error("Error", "No FCM token returned from Firebase");
|
||||
return;
|
||||
}
|
||||
|
||||
Clipboard.setData(new ClipboardData(text: fcmToken));
|
||||
Toaster.info("Clipboard", 'Copied text to Clipboard');
|
||||
print('================= [CLIPBOARD] =================\n${fcmToken}\n================= [/CLIPBOARD] =================');
|
||||
} catch (exc, trace) {
|
||||
Toaster.error("Error", "An error occurred while sending the token: ${exc.toString()}");
|
||||
ApplicationLog.error("An error occurred while sending the token: ${exc.toString()}", trace: trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user