light 4.1.0 copy "light: ^4.1.0" to clipboard
light: ^4.1.0 copied to clipboard

PlatformAndroid

Plugin for collecting data from the ambient light sensor on Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:light/light.dart';

void main() => runApp(LightApp());

class LightApp extends StatefulWidget {
  @override
  LightAppState createState() => LightAppState();
}

class LightAppState extends State<LightApp> {
  String _luxString = 'Unknown';
  StreamSubscription<int>? _lightEvents;

  void startListening() {
    try {
      _lightEvents =
          Light().lightSensorStream.listen((luxValue) => setState(() {
                _luxString = "$luxValue";
              }));
    } catch (exception) {
      print(exception);
    }
  }

  void stopListening() {
    _lightEvents?.cancel();
  }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(title: const Text('Light Example App')),
      body: Center(child: Text('Lux value: $_luxString\n')),
    ));
  }
}
copied to clipboard
24
likes
160
points
4.22k
downloads

Publisher

verified publishercachet.dk

Weekly Downloads

2024.09.22 - 2025.04.06

Plugin for collecting data from the ambient light sensor on Android.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on light