2023-09-08 17:25:26 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:typed_data';
|
2023-09-07 16:51:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:moxxy_native/moxxy_native.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
2023-09-08 17:25:26 +00:00
|
|
|
class MyApp extends StatefulWidget {
|
2023-09-07 16:51:22 +00:00
|
|
|
const MyApp({super.key});
|
|
|
|
|
2023-09-08 17:25:26 +00:00
|
|
|
@override
|
|
|
|
MyAppState createState() => MyAppState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyAppState extends State<MyApp> {
|
|
|
|
String? imagePath;
|
|
|
|
|
2023-09-07 16:51:22 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Plugin example app'),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2023-09-08 13:41:06 +00:00
|
|
|
final result = await MoxxyPickerApi()
|
|
|
|
.pickFiles(FilePickerType.image, false);
|
2023-09-07 16:51:22 +00:00
|
|
|
// ignore: avoid_print
|
|
|
|
print('User picked: $result');
|
|
|
|
},
|
|
|
|
child: const Text('Photo picker'),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2023-09-08 13:41:06 +00:00
|
|
|
final result = await MoxxyPickerApi()
|
|
|
|
.pickFiles(FilePickerType.imageAndVideo, true);
|
2023-09-07 16:51:22 +00:00
|
|
|
// ignore: avoid_print
|
|
|
|
print('User picked: $result');
|
|
|
|
},
|
|
|
|
child: const Text('Photo/Video multi-picker'),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2023-09-08 13:41:06 +00:00
|
|
|
final result = await MoxxyPickerApi()
|
|
|
|
.pickFiles(FilePickerType.generic, true);
|
2023-09-07 16:51:22 +00:00
|
|
|
// ignore: avoid_print
|
|
|
|
print('User picked: $result');
|
|
|
|
},
|
|
|
|
child: const Text('Generic multi-picker'),
|
|
|
|
),
|
2023-09-08 17:25:26 +00:00
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
final result = await MoxxyPickerApi().pickFiles(FilePickerType.image, false);
|
|
|
|
if (result.isEmpty) return;
|
|
|
|
|
|
|
|
final encDest = result.first! + '.enc';
|
|
|
|
final decDest = result.first! + '.dec';
|
|
|
|
final encResult = await MoxxyCryptographyApi().encryptFile(
|
|
|
|
result.first!,
|
|
|
|
encDest,
|
|
|
|
Uint8List.fromList(List.filled(32, 1)),
|
|
|
|
Uint8List.fromList(List.filled(16, 2)),
|
|
|
|
CipherAlgorithm.aes256CbcPkcs7,
|
|
|
|
'SHA-256',
|
|
|
|
);
|
|
|
|
if (encResult == null) {
|
|
|
|
print('Failed to encrypt file');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final decResult = await MoxxyCryptographyApi().decryptFile(
|
|
|
|
encDest,
|
|
|
|
decDest,
|
|
|
|
Uint8List.fromList(List.filled(32, 1)),
|
|
|
|
Uint8List.fromList(List.filled(16, 2)),
|
|
|
|
CipherAlgorithm.aes256CbcPkcs7,
|
|
|
|
'SHA-256',
|
|
|
|
);
|
|
|
|
if (decResult == null) {
|
|
|
|
print('Failed to decrypt file');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
imagePath = decDest;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text('Test cryptography'),
|
|
|
|
),
|
|
|
|
|
|
|
|
if (imagePath != null)
|
|
|
|
Image.file(File(imagePath!)),
|
2023-09-07 16:51:22 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|