screen_plugin 0.0.3 screen_plugin: ^0.0.3 copied to clipboard
screen_plugin.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:screen_plugin/screen_controller.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
ScreenController.registerReceiver();
ScreenController.statusChangedListener((open){
print("=================${open.toString()}=================");
}, (t){});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: RaisedButton(
onPressed: (){
_onPressed();
},
child: Text(
"获取",
),
),
),
),
);
}
_onPressed() async{
bool isScreenOn = await ScreenController.isScreenOn();
print("=================${isScreenOn.toString()}=================");
}
}