proximity_screen_lock_ios 1.0.0 copy "proximity_screen_lock_ios: ^1.0.0" to clipboard
proximity_screen_lock_ios: ^1.0.0 copied to clipboard

PlatformiOS

A iOS Flutter plugin that can be used to bind screen activation to proximity sensor

example/lib/main.dart

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',
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
130
pub points
16%
popularity

Publisher

verified publishermantoux.org

A iOS Flutter plugin that can be used to bind screen activation to proximity sensor

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, proximity_screen_lock_platform_interface

More

Packages that depend on proximity_screen_lock_ios