light 4.0.0 copy "light: ^4.0.0" to clipboard
light: ^4.0.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')),
    ));
  }
}
24
likes
160
points
4.75k
downloads

Publisher

verified publishercachet.dk

Weekly Downloads

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