颤动可以改变屏幕的亮度吗? [英] Can flutter change the brightness of the screen?
本文介绍了颤动可以改变屏幕的亮度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
抖动可以改变屏幕的亮度吗?我发现ThemeData中的Brightness只有两个值:明暗.如何在应用程序中将屏幕亮度从1调整为10?
Can flutter change the brightness of the screen? I found that Brightness in ThemeData only has two values: light and dark. How can I adjust the screen brightness from 1 to 10 in the app?
推荐答案
是的,Flutter可以使用屏幕插件: 屏幕插件
Yes Flutter can, you can use the screen plugin: Screen plugin
这是一个实现方法的示例,您只需为所需的起始值设置_brightness
并使用Slider对其进行更改:
This is an example of how to implement it, You just have to set _brightness
for the start value you want and change it using the Slider:
import 'package:flutter/material.dart';
import 'package:screen/screen.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isKeptOn = false;
double _brightness = 1.0;
@override
initState() {
super.initState();
initPlatformState();
}
initPlatformState() async {
bool keptOn = await Screen.isKeptOn;
double brightness = await Screen.brightness;
setState((){
_isKeptOn = keptOn;
_brightness = brightness;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(title: new Text('Screen plugin example')),
body: new Center(
child: new Column(
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Screen is kept on ? "),
new Checkbox(value: _isKeptOn, onChanged: (bool b){
Screen.keepOn(b);
setState((){_isKeptOn = b; });
})
]
),
new Text("Brightness :"),
new Slider(value : _brightness, onChanged : (double b){
setState((){
_brightness = b;
});
Screen.setBrightness(b);
})
]
)
),
),
);
}
}
如果您需要更多说明,请告诉我.
Let me know if you need any more explanation.
这篇关于颤动可以改变屏幕的亮度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文