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?
Yes Flutter can, you can use the screen plugin: Screen plugin
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. This solution is only for Android and iOS, not desktop cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With