torch_plus 0.0.1
torch_plus: ^0.0.1 copied to clipboard
A package that we can use to easily turn the phone's flashlight on and off
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'),
),
],
),
),
),
);
}
}