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

outdated

A Flutter plugin for probing data from the light sensor using a platform channel. Works for Android only, since the light sensor API is not available on iOS.

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;

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

  void _onDone() {}

  void _onError(error) {
    // Handle the error
  }

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    _light = new Light();
    _light.lightSensorStream.listen(_onData,
        onError: _onError, onDone: _onDone, cancelOnError: true);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new Text('Running on: $_luxString\n'),
        ),
      ),
    );
  }
}
23
likes
0
pub points
90%
popularity

Publisher

verified publishercachet.dk

A Flutter plugin for probing data from the light sensor using a platform channel. Works for Android only, since the light sensor API is not available on iOS.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on light