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

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(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _luxString = 'Unknown';
  Light? _light;
  StreamSubscription? _subscription;

  void onData(int luxValue) async {
    print("Lux value: $luxValue");
    setState(() {
      _luxString = "$luxValue";
    });
  }

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

  void startListening() {
    _light = Light();
    try {
      _subscription = _light?.lightSensorStream.listen(onData);
    } on LightException catch (exception) {
      print(exception);
    }
  }

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

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Light Example App'),
        ),
        body: new Center(
          child: new Text('Lux value: $_luxString\n'),
        ),
      ),
    );
  }
}
24
likes
150
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