flutter_keepscreenon 0.1.1
flutter_keepscreenon: ^0.1.1 copied to clipboard

Flutter Android iOS

A package can help you to keep the device's screen on programmatically without any permission.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_keepscreenon/flutter_keepscreenon.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool activeFlag = false;
  String errMsg = '';

  toggleFlag() async {
    try {
      if (activeFlag)
        await FlutterKeepscreenon.keepScreenOn(false);
      else
        await FlutterKeepscreenon.keepScreenOn(true);
      setState(() => activeFlag = !activeFlag);
    } on PlatformException catch (e) {
      print(e);
      setState(() => errMsg = e.message);
    }

    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter_keepscreenon plugin example app'),
        ),
        body: Center(
            child: Container(
          height: 100.0,
          child: Column(
            children: <Widget>[
              Switch(
                onChanged: (bool value) => toggleFlag(),
                value: activeFlag,
              ),
              Text(
                activeFlag ? 'It\'s on!' : 'It\'s off!',
              ),
              Text(
                errMsg,
              ),
            ],
          ),
        )),
      ),
    );
  }
}
0
likes
90
pub points
0%
popularity

A package can help you to keep the device's screen on programmatically without any permission.

Repository (GitHub)
View/report issues

Uploader

fnatic.roach@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_keepscreenon