feat: Provide a much cleaner Dart API
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// ignore_for_file: avoid_print
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -10,13 +11,14 @@ import 'package:permission_handler/permission_handler.dart';
|
||||
Future<void> serviceHandleData(Map<String, dynamic>? data) async {
|
||||
print('[BG] Received data $data');
|
||||
GetIt.I.get<BackgroundService>().send(
|
||||
TestEvent(),
|
||||
id: data!['id']! as String,
|
||||
);
|
||||
TestEvent(),
|
||||
id: data!['id']! as String,
|
||||
);
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> serviceEntrypoint(String initialLocale) async {
|
||||
// avoid_print
|
||||
print('Initial locale: $initialLocale');
|
||||
}
|
||||
|
||||
@@ -34,15 +36,15 @@ class MyApp extends StatefulWidget {
|
||||
class TestCommand extends BackgroundCommand {
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {
|
||||
'request': 'return_name',
|
||||
};
|
||||
'request': 'return_name',
|
||||
};
|
||||
}
|
||||
|
||||
class TestEvent extends BackgroundEvent {
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': 'Moxxy',
|
||||
};
|
||||
'name': 'Moxxy',
|
||||
};
|
||||
}
|
||||
|
||||
class MyAppState extends State<MyApp> {
|
||||
@@ -61,7 +63,6 @@ class MyAppState extends State<MyApp> {
|
||||
onPressed: () async {
|
||||
final result = await MoxxyPickerApi()
|
||||
.pickFiles(FilePickerType.image, false);
|
||||
// ignore: avoid_print
|
||||
print('User picked: $result');
|
||||
},
|
||||
child: const Text('Photo picker'),
|
||||
@@ -70,7 +71,6 @@ class MyAppState extends State<MyApp> {
|
||||
onPressed: () async {
|
||||
final result = await MoxxyPickerApi()
|
||||
.pickFiles(FilePickerType.imageAndVideo, true);
|
||||
// ignore: avoid_print
|
||||
print('User picked: $result');
|
||||
},
|
||||
child: const Text('Photo/Video multi-picker'),
|
||||
@@ -79,7 +79,6 @@ class MyAppState extends State<MyApp> {
|
||||
onPressed: () async {
|
||||
final result = await MoxxyPickerApi()
|
||||
.pickFiles(FilePickerType.generic, true);
|
||||
// ignore: avoid_print
|
||||
print('User picked: $result');
|
||||
},
|
||||
child: const Text('Generic multi-picker'),
|
||||
@@ -101,7 +100,6 @@ class MyAppState extends State<MyApp> {
|
||||
'SHA-256',
|
||||
);
|
||||
if (encResult == null) {
|
||||
// ignore: avoid_print
|
||||
print('Failed to encrypt file');
|
||||
return;
|
||||
}
|
||||
@@ -115,7 +113,6 @@ class MyAppState extends State<MyApp> {
|
||||
'SHA-256',
|
||||
);
|
||||
if (decResult == null) {
|
||||
// ignore: avoid_print
|
||||
print('Failed to decrypt file');
|
||||
return;
|
||||
}
|
||||
@@ -146,7 +143,7 @@ class MyAppState extends State<MyApp> {
|
||||
|
||||
await Permission.notification.request();
|
||||
|
||||
final srv = ForegroundService();
|
||||
final srv = getForegroundService();
|
||||
await srv.start(
|
||||
const ServiceConfig(
|
||||
serviceEntrypoint,
|
||||
@@ -159,7 +156,7 @@ class MyAppState extends State<MyApp> {
|
||||
);
|
||||
|
||||
await Future<void>.delayed(const Duration(milliseconds: 600));
|
||||
await srv.dataSender.sendData(
|
||||
await getForegroundService().send(
|
||||
TestCommand(),
|
||||
awaitable: false,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user