torch_controller 2.0.1 copy "torch_controller: ^2.0.1" to clipboard
torch_controller: ^2.0.1 copied to clipboard

A controller to manage torch/flash device resource. We give you access to native resources to toggle flashlight, to natively check torch status and more!

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:torch_controller/torch_controller.dart';

void main() {
  TorchController().initialize();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final controller = TorchController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              FutureBuilder<bool?>(
                  future: controller.isTorchActive,
                  builder: (_, snapshot) {
                    final snapshotData = snapshot.data ?? false;

                    if (snapshot.connectionState == ConnectionState.done)
                      return Text(
                          'Is torch on? ${snapshotData ? 'Yes!' : 'No :('}');

                    return Container();
                  }),
              MaterialButton(
                  child: Text('Toggle'),
                  onPressed: () {
                    controller.toggle(intensity: 1);
                    setState(() {});
                  }),
            ],
          ),
        ),
      ),
    );
  }
}
25
likes
160
pub points
89%
popularity

Publisher

unverified uploader

A controller to manage torch/flash device resource. We give you access to native resources to toggle flashlight, to natively check torch status and more!

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on torch_controller