light_sensor 3.0.0 copy "light_sensor: ^3.0.0" to clipboard
light_sensor: ^3.0.0 copied to clipboard

PlatformAndroid

A Flutter plugin for Android allowing access to the device light sensor.

example/lib/main.dart

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

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Light sensor example')),
        body: Center(
          child: FutureBuilder<bool>(
            future: LightSensor.hasSensor(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                final bool hasSensor = snapshot.data!;
                if (hasSensor) {
                  return StreamBuilder<int>(
                    stream: LightSensor.luxStream(),
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return Text('Running on: ${snapshot.data} LUX');
                      } else {
                        return const Text('Running on: unknown');
                      }
                    },
                  );
                } else {
                  return const Text("Your device doesn't have a light sensor");
                }
              } else {
                return const Center(child: CircularProgressIndicator());
              }
            },
          ),
        ),
      ),
    );
  }
}
5
likes
130
pub points
75%
popularity

Publisher

unverified uploader

A Flutter plugin for Android allowing access to the device light sensor.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on light_sensor