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,
|
||||
);
|
||||
|
||||
@@ -108,7 +108,7 @@ packages:
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: logging
|
||||
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
|
||||
|
||||
@@ -30,6 +30,7 @@ dependencies:
|
||||
cupertino_icons: ^1.0.2
|
||||
permission_handler: ^10.4.5
|
||||
get_it: ^7.6.0
|
||||
logging: ^1.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user