torch_plugin 0.0.2 copy "torch_plugin: ^0.0.2" to clipboard
torch_plugin: ^0.0.2 copied to clipboard

PlatformAndroid

This plugin have the torch and volume control for android.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:torch_plugin/torch_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _torchPlugin = TorchPlugin();
bool _isTorchOn=false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child:Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Torch control',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 20),),
              SizedBox(
                height: 40,
              ),
              IconButton(onPressed: ()async {
                print('button pressed...........');
                if(_isTorchOn){
                  print('Torch off...........$_isTorchOn');

                  _isTorchOn=await _torchPlugin.offTorch();

                  setState(() {
                  });
                }else{
                  print('Torch on...........$_isTorchOn');

                  _isTorchOn=await _torchPlugin.onTorch();
                  setState(() {
                  });
                }
              },
               icon:  Icon(_isTorchOn?Icons.flashlight_off:Icons.flashlight_on,size: 50,))
            ],
          )
      ),
    ));
  }
}
4
likes
140
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

This plugin have the torch and volume control for android.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on torch_plugin

Packages that implement torch_plugin