在同一个Stack Overflow帖子中提到,screen插件遇到了一些问题。我已经检查了该插件,似乎自2019年3月13日以来没有更新过。另一个可以提供所需功能的插件是wakelock插件。目前作者仍在维护。实际上,最新版本0.5.0+2于2021年3月7日发布。
嗨,我仍在维护它 :) 我们最近增加了macOS支持。此外,Flutter是开源的 - 他们有官方插件,但是他们自己说,如果存在更好的第三方项目,他们将放弃自己的官方解决方案。那么为什么他们要为已经完美运行的东西创建一个呢?- creativecreatorormaybenot 2月8日16:17
我已经测试了wakelock package中给出的示例:
import 'package:flutter/material.dart';
import 'package:wakelock/wakelock.dart';
void main() {
runApp(WakelockExampleApp());
}
class WakelockExampleApp extends StatefulWidget {
@override
_WakelockExampleAppState createState() => _WakelockExampleAppState();
}
class _WakelockExampleAppState extends State<WakelockExampleApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Wakelock example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Spacer(
flex: 3,
),
OutlinedButton(
onPressed: () {
setState(() {
Wakelock.enable();
});
},
child: const Text('enable wakelock'),
),
const Spacer(),
OutlinedButton(
onPressed: () {
setState(() {
Wakelock.disable();
});
},
child: const Text('disable wakelock'),
),
const Spacer(
flex: 2,
),
FutureBuilder(
future: Wakelock.enabled,
builder: (context, AsyncSnapshot<bool> snapshot) {
final data = snapshot.data;
if (data == null) {
return Container();
}
return Text('The wakelock is currently '
'${data ? 'enabled' : 'disabled'}.');
},
),
const Spacer(
flex: 3,
),
],
),
),
),
);
}
}
Here is the output in Android:
![enter image description here](https://istack.dev59.com/KczpT.gif)
在iOS中的输出:
![enter image description here](https://istack.dev59.com/EPkxD.gif)
此外,看起来您已经解决了代码中的上一个问题。很好的是,为了让社区更好地理解这个问题,分享
一个最小化、完整和可验证的示例会很不错。
build
方法中。这就是为什么应用程序无法运行的原因。在你告诉我它对你起作用后,我尝试将其放在主函数中,现在它可以工作了!谢谢! - Curtwagner1984