lamp2 0.0.1 copy "lamp2: ^0.0.1" to clipboard
lamp2: ^0.0.1 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:lamp2/lamp2.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  bool _hasFlashlight = false;

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

  initFlashlight() async {
    bool hasFlash = await Lamp2.hasFlashlight;
    print("Device has flash ? $hasFlash");
    setState(() {
      _hasFlashlight = hasFlash;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text(_hasFlashlight
                  ? 'Your phone has a Flashlight.'
                  : 'Your phone has no Flashlight.'),
              RaisedButton(
                child: Text('Turn on'),
                onPressed: () => Lamp2.lightOn(),
              ),
              RaisedButton(
                child: Text('Turn off'),
                onPressed: () => Lamp2.lightOff(),
              )
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

A new flutter plugin project.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on lamp2

Packages that implement lamp2