gpt4 book ai didi

flutter - flutter 可以改变屏幕的亮度吗?

转载 作者:行者123 更新时间:2023-12-04 14:12:23 25 4
gpt4 key购买 nike

Flutter 可以改变屏幕的亮度吗?我发现 ThemeData 中的 Brightness 只有两个值:light 和 dark。如何在应用程序中将屏幕亮度从 1 调整到 10?

最佳答案

是的 Flutter 可以,你可以使用 screen 插件:
Screen plugin
这是一个如何实现它的例子,你只需要设置 _brightness对于您想要的起始值并使用滑块更改它:

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);
})
]
)
),
),
);
}
}
如果您需要更多解释,请告诉我。

关于flutter - flutter 可以改变屏幕的亮度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63233620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com