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

A package that we can use to easily turn the phone's flashlight on and off

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  bool? isTorched;

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

  void test() {
    TorchPlus.isTorched().then((value) => isTorched = value);
    setState(() {});
  }

  @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: [
              ElevatedButton(onPressed: () {}, child: Text(isTorched.toString())),
              SizedBox(height: 70),
              ElevatedButton(
                onPressed: () async {
                  await TorchPlus.turnOn();
                  setState(() {
                    isTorched = true;
                  });
                },
                child: Text('Turn On'),
              ),
              SizedBox(height: 70),
              ElevatedButton(
                onPressed: () async {
                  await TorchPlus.turnOff();
                  setState(() {
                    isTorched = false;
                  });
                },
                child: Text('Turn Off'),
              ),
              SizedBox(height: 70),
              ElevatedButton(
                onPressed: () async {
                  await TorchPlus.toggle();
                  setState(() {
                    isTorched = !isTorched!;
                  });
                },
                child: Text('Toggle'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
140
points
13
downloads

Publisher

verified publisheryusufnadaroglu.com

Weekly Downloads

A package that we can use to easily turn the phone's flashlight on and off

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on torch_plus

Packages that implement torch_plus