flutter_myscript 0.0.6
flutter_myscript: ^0.0.6 copied to clipboard
Handling the permission access.
example/lib/main.dart
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_myscript/flutter_myscript.dart';
import 'package:flutter_myscript/flutter_myscript_platform_interface.dart';
// import 'ios_permission.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
// final _flutterMyscriptPlugin = FlutterMyscript();
@override
void initState() {
super.initState();
// initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
// try {
// platformVersion =
// await _flutterMyscriptPlugin.getPlatformVersion() ?? 'Unknown platform version';
// } on PlatformException {
platformVersion = 'Failed to get platform version.';
// }
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
dynamic status = '';
Future<void> requestPermission() async {
final getStatus = await GetPermission.photos.request();
// if (getStatus == GetPermissionStatus.granted) {}
setState(() {
status = "$getStatus [photos]";
});
}
Future<void> checkPermission() async {
Sample1();
Sample2();
var getStatus = await GetPermission.camera.status;
setState(() {
status = getStatus;
});
}
Future<void> checkService() async {
final getStatus = await GetPermission.camera.isDenied;
setState(() {
status = getStatus;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
requestPermission();
},
child: const Text('Request Camera')),
const SizedBox(
height: 30,
),
Text(status.toString()),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
checkPermission();
},
child: const Text('Check Camera Permission')),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
checkService();
},
child: const Text('Check Camera Service')),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () async {
textReconization();
},
child: const Text('Mask Image')),
const SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () async {
await openAppSettings();
},
child: const Text('App Settings')),
],
),
),
),
),
);
}
Future<void> textReconization() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['jpg', 'jpeg', 'png'],
);
if (result != null && result.files.isNotEmpty) {
await MaskController()
.processImage(imagePath: result.files.first.path!)
.then((value) {
print('----------------------');
print(value);
// setState(() {
// maskedImageResult = value;
// });
});
}
}
}