icapps_torch_compat 2.0.0 copy "icapps_torch_compat: ^2.0.0" to clipboard
icapps_torch_compat: ^2.0.0 copied to clipboard

Plugin to turn on / off the torch (or flash of the camera) on all supported versions of Android (4.1+) and iOS

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:icapps_torch_compat/icapps_torch_compat.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> {
  bool? _hasTorch;

  @override
  void initState() {
    super.initState();
    initTorchState();
  }

  Future<void> initTorchState() async {
    _hasTorch = await TorchCompat.hasTorch;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              Text('hasTorch: $_hasTorch'),
              ElevatedButton(
                onPressed: () async {
                  await TorchCompat.turnOn();
                  await Future.delayed(const Duration(seconds: 2));
                  await TorchCompat.turnOff();
                },
                child: const Text('Turn on torch for 2 seconds'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
110
pub points
55%
popularity

Publisher

verified publishericapps.com

Plugin to turn on / off the torch (or flash of the camera) on all supported versions of Android (4.1+) and iOS

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on icapps_torch_compat