faro_torch 0.0.1 copy "faro_torch: ^0.0.1" to clipboard
faro_torch: ^0.0.1 copied to clipboard

outdated

Plugin to use the camera phone flash without using the camera.

Faro Torch #

pub package

Flutter plugin to use the camera phone flash without using the camera.

⚠️ At the moment, it is only possible to use on Android. We are working on the implementation for iOS

Note: This plugin is still under development, and some APIs might not be available yet. Feedback welcome and Pull Requests are most welcome!

Install #

To use this plugin, add faro_torch as a dependency in your pubspec.yaml file.

Android #

Change the minimum Android sdk version to 23 (or higher) in your android/app/build.gradle file.

minSdkVersion 23

iOS #

Work in progress 🔨

Features: #

  • Check if device has flash
  • Turn on flash
  • Turn off flash

Example #

import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:faro_torch/faro_torch.dart';

void main() => runApp(FaroTorchExmapleApp());

class FaroTorchExmapleApp extends StatefulWidget {
  @override
  _FaroTorchExmapleAppState createState() => _FaroTorchExmapleAppState();
}

class _FaroTorchExmapleAppState extends State<FaroTorchExmapleApp> {
  bool _hasFlash = false;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Faro Torch Plugin example'),
        ),
        body: _buildBody(),
      ),
    );
  }

  Widget _buildBody() {
    return Center(
      child: Container(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: RaisedButton(
                      child: Text("ON"),
                      onPressed: () => _turnOn(),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: RaisedButton(
                      child: Text("OFF"),
                      onPressed: () => _turnOff(),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
  
  Future<void> checkIfDeviceHasFlash() async {
    bool hasFlash = await FaroTorch.hasFlash();

    if (widgetWasRemove()) return;

    setState(() {
      _hasFlash = hasFlash;
    });
  }

  Future _turnOn() async {
    await FaroTorch.turnOn();
  }

  Future _turnOff() async {
    await FaroTorch.turnOff();
  }

  bool widgetWasRemove() => !mounted;
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Plugin to use the camera phone flash without using the camera.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on faro_torch