fix(repo): Remove notification examples

This commit is contained in:
PapaTutuWawa 2023-09-03 13:09:44 +02:00
parent f2b140de18
commit fe07b2a488
3 changed files with 69 additions and 170 deletions

View File

@ -1,11 +1,9 @@
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:moxplatform/moxplatform.dart';
import 'package:path/path.dart';
import 'package:permission_handler/permission_handler.dart';
/// The id of the notification channel.
const channelId = "me.polynom.moxplatform.testing3";
@ -31,54 +29,6 @@ class MyApp extends StatefulWidget {
}
class MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initStateAsync();
}
Future<void> initStateAsync() async {
await Permission.notification.request();
await MoxplatformPlugin.notifications.createNotificationChannels(
[
NotificationChannel(
id: channelId,
title: "Test1",
description: "Test notification channel",
importance: NotificationChannelImportance.MIN,
showBadge: true,
vibration: false,
enableLights: false,
),
NotificationChannel(
id: otherChannelId,
title: "Test2",
description: "Test notification channel for warnings",
importance: NotificationChannelImportance.MIN,
showBadge: true,
vibration: false,
enableLights: false,
),
],
);
await MoxplatformPlugin.notifications.setI18n(
NotificationI18nData(
reply: "答える",
markAsRead: "読みた",
you: "あなた",
),
);
MoxplatformPlugin.notifications.getEventStream().listen((event) {
// ignore: avoid_print
print(
'NotificationEvent(type: ${event.type}, jid: ${event.jid}, payload: ${event.payload}, extras: ${event.extra})',
);
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
@ -106,10 +56,6 @@ class MyHomePageState extends State<MyHomePage> {
Sender('Raiden Shogun', 'raiden@tevhat'),
];
/// List of sent messages.
List<NotificationMessage> messages =
List<NotificationMessage>.empty(growable: true);
Future<void> _cryptoTest() async {
final result = await FilePicker.platform.pickFiles();
if (result == null) {
@ -187,87 +133,6 @@ class MyHomePageState extends State<MyHomePage> {
},
child: const Text('Test recordSentMessage (notes fallback)'),
),
ElevatedButton(
onPressed: () async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
);
// ignore: avoid_print
print('Picked file: ${result?.files.single.path}');
// Create a new message.
final senderIndex = Random().nextInt(senders.length);
final time = DateTime.now().millisecondsSinceEpoch;
messages.add(NotificationMessage(
jid: senders[senderIndex].jid,
sender: senders[senderIndex].name,
content: NotificationMessageContent(
body: result != null ? null : 'Message #${messages.length}',
mime: 'image/jpeg',
path: result?.files.single.path,
),
timestamp: time,
));
await Future<void>.delayed(const Duration(seconds: 4));
await MoxplatformPlugin.notifications.showMessagingNotification(
MessagingNotification(
id: 2343,
title: 'Test conversation',
messages: messages,
channelId: channelId,
jid: 'testjid',
isGroupchat: true,
extra: {
'jid': 'testjid',
'avatarPath': 'lol',
'rio': 'cute',
},
),
);
},
child: const Text('Show messaging notification'),
),
ElevatedButton(
onPressed: () {
MoxplatformPlugin.notifications.showNotification(
RegularNotification(
id: 4384,
title: 'Warning',
body: 'Something brokey',
channelId: otherChannelId,
icon: NotificationIcon.warning,
),
);
},
child: const Text('Show warning notification'),
),
ElevatedButton(
onPressed: () {
MoxplatformPlugin.notifications.showNotification(
RegularNotification(
id: 4384,
title: 'Error',
body: "Lol, you're on your own",
channelId: otherChannelId,
icon: NotificationIcon.error,
),
);
},
child: const Text('Show error notification'),
),
ElevatedButton(
onPressed: () async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
);
if (result == null) return;
MoxplatformPlugin.notifications
.setNotificationSelfAvatar(result.files.single.path!);
},
child: const Text('Set notification self-avatar'),
),
ElevatedButton(
onPressed: () async {
// ignore: avoid_print

View File

@ -40,8 +40,6 @@ dependencies:
file_picker: 5.2.0+1
path: 1.8.3
permission_handler: 10.4.3
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.

View File

@ -61,7 +61,7 @@ class _MoxplatformApiCodec extends StandardMessageCodec {
@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
case 128:
return CryptographyResult.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
@ -82,10 +82,10 @@ class MoxplatformApi {
/// Platform APIs
Future<String> getPersistentDataPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getPersistentDataPath', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getPersistentDataPath',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -109,10 +109,10 @@ class MoxplatformApi {
Future<String> getCacheDataPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getCacheDataPath', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.getCacheDataPath',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -136,10 +136,10 @@ class MoxplatformApi {
Future<void> openBatteryOptimisationSettings() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.openBatteryOptimisationSettings', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.openBatteryOptimisationSettings',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -158,10 +158,10 @@ class MoxplatformApi {
Future<bool> isIgnoringBatteryOptimizations() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.isIgnoringBatteryOptimizations', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.isIgnoringBatteryOptimizations',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -184,12 +184,18 @@ class MoxplatformApi {
}
/// Contacts APIs
Future<void> recordSentMessage(String arg_name, String arg_jid, String? arg_avatarPath, FallbackIconType arg_fallbackIcon) async {
Future<void> recordSentMessage(String arg_name, String arg_jid,
String? arg_avatarPath, FallbackIconType arg_fallbackIcon) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.recordSentMessage', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.recordSentMessage',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_name, arg_jid, arg_avatarPath, arg_fallbackIcon.index]) as List<Object?>?;
final List<Object?>? replyList = await channel.send(<Object?>[
arg_name,
arg_jid,
arg_avatarPath,
arg_fallbackIcon.index
]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -207,12 +213,25 @@ class MoxplatformApi {
}
/// Cryptography APIs
Future<CryptographyResult?> encryptFile(String arg_sourcePath, String arg_destPath, Uint8List arg_key, Uint8List arg_iv, CipherAlgorithm arg_algorithm, String arg_hashSpec) async {
Future<CryptographyResult?> encryptFile(
String arg_sourcePath,
String arg_destPath,
Uint8List arg_key,
Uint8List arg_iv,
CipherAlgorithm arg_algorithm,
String arg_hashSpec) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.encryptFile', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.encryptFile',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_sourcePath, arg_destPath, arg_key, arg_iv, arg_algorithm.index, arg_hashSpec]) as List<Object?>?;
final List<Object?>? replyList = await channel.send(<Object?>[
arg_sourcePath,
arg_destPath,
arg_key,
arg_iv,
arg_algorithm.index,
arg_hashSpec
]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -229,12 +248,25 @@ class MoxplatformApi {
}
}
Future<CryptographyResult?> decryptFile(String arg_sourcePath, String arg_destPath, Uint8List arg_key, Uint8List arg_iv, CipherAlgorithm arg_algorithm, String arg_hashSpec) async {
Future<CryptographyResult?> decryptFile(
String arg_sourcePath,
String arg_destPath,
Uint8List arg_key,
Uint8List arg_iv,
CipherAlgorithm arg_algorithm,
String arg_hashSpec) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.decryptFile', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.decryptFile',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_sourcePath, arg_destPath, arg_key, arg_iv, arg_algorithm.index, arg_hashSpec]) as List<Object?>?;
final List<Object?>? replyList = await channel.send(<Object?>[
arg_sourcePath,
arg_destPath,
arg_key,
arg_iv,
arg_algorithm.index,
arg_hashSpec
]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -251,12 +283,14 @@ class MoxplatformApi {
}
}
Future<Uint8List?> hashFile(String arg_sourcePath, String arg_hashSpec) async {
Future<Uint8List?> hashFile(
String arg_sourcePath, String arg_hashSpec) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.hashFile', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.hashFile',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_sourcePath, arg_hashSpec]) as List<Object?>?;
final List<Object?>? replyList = await channel
.send(<Object?>[arg_sourcePath, arg_hashSpec]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
@ -274,12 +308,14 @@ class MoxplatformApi {
}
/// Media APIs
Future<bool> generateVideoThumbnail(String arg_src, String arg_dest, int arg_maxWidth) async {
Future<bool> generateVideoThumbnail(
String arg_src, String arg_dest, int arg_maxWidth) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.generateVideoThumbnail', codec,
'dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.generateVideoThumbnail',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_src, arg_dest, arg_maxWidth]) as List<Object?>?;
final List<Object?>? replyList = await channel
.send(<Object?>[arg_src, arg_dest, arg_maxWidth]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',