proximity_screen_lock_ios 1.0.0 proximity_screen_lock_ios: ^1.0.0 copied to clipboard
A iOS Flutter plugin that can be used to bind screen activation to proximity sensor
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:proximity_screen_lock_ios/proximity_screen_lock_ios.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _proximityScreenLock = ProximityScreenLockIos();
var isActive = false;
@override
void initState() {
super.initState();
setProximitySensorActive();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> setProximitySensorActive() async {
try {
await _proximityScreenLock.setActive(isActive);
} catch (e) {
debugPrint('Something went wrong: $e');
}
}
void toggle() {
setState(() => isActive = !isActive);
setActive(isActive);
}
void setActive(bool value) {
_proximityScreenLock.setActive(value);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: TextButton(
onPressed: toggle,
child: Text(
isActive ? 'De-activate' : 'Activate',
),
),
),
),
);
}
}