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

A plugin to activate the torch for android and ios devices.

example/lib/main.dart

import 'package:flash_light/flash_light.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static final flashLight = FlashLight();

  String _flashlightStatus = 'Unknown flashlight status.';

  Future<void> _toggleFlashlight() async {
    String flashlightStatus;
    try {
      final result = await flashLight.toggle();
      flashlightStatus = 'Flashlight $result % .';
    } on PlatformException catch (e) {
      flashlightStatus = "Failed to toggle flashlight: '${e.message}'.";
    }

    setState(() {
      _flashlightStatus = flashlightStatus;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _toggleFlashlight,
              child: const Text('Toggle Flashlight'),
            )
          ],
        ),
      ),
    );
  }
}
2
likes
150
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin to activate the torch for android and ios devices.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flash_light42

Packages that implement flash_light42