flutter_voip_push_notification_v2 0.0.3
flutter_voip_push_notification_v2: ^0.0.3 copied to clipboard
Flutter VoIP Push Notification - Currently iOS >= 8.0 only
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_voip_push_notification_v2/flutter_voip_push_notification_v2.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _pushToken = '';
final FlutterVoipPushNotificationV2 _voipPush = FlutterVoipPushNotificationV2();
@override
void initState() {
super.initState();
configure();
}
// Configures a voip push notification
Future<void> configure() async {
// request permission (required)
await _voipPush.requestNotificationPermissions();
// // listen to voip device token changes
_voipPush.onTokenRefresh.listen(onToken);
// // do configure voip push
_voipPush.configure(onMessage: onMessage, onResume: onResume);
}
/// Called when the device token changes
void onToken(String token) {
// send token to your apn provider server
setState(() {
_pushToken = token;
});
}
/// Called to receive notification when app is in foreground
///
/// [isLocal] is true if its a local notification or false otherwise (remote notification)
/// [payload] the notification payload to be processed. use this to present a local notification
Future<dynamic>? onMessage(bool isLocal, Map<String, dynamic> payload) {
// handle foreground notification
print("received on foreground payload: $payload, isLocal=$isLocal");
return null;
}
/// Called to receive notification when app is resuming from background
///
/// [isLocal] is true if its a local notification or false otherwise (remote notification)
/// [payload] the notification payload to be processed. use this to present a local notification
Future<dynamic>? onResume(bool isLocal, Map<String, dynamic> payload) {
// handle background notification
print("received on background payload: $payload, isLocal=$isLocal");
showLocalNotification(payload);
return null;
}
showLocalNotification(Map<String, dynamic> notification) {
String alert = notification["aps"]["alert"];
_voipPush.presentLocalNotification(LocalNotification(
alertBody: "Hello $alert",
alertAction: '',
));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Received Voip Push token: $_pushToken\n'),
),
),
);
}
}