本文介绍了手机覆盖的应用亮度默认为Flutter中的亮度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Flutter的新手,我想构建一个可以使用flutter控制屏幕亮度的应用,我在 screen 0.0.5
中找到了一个正在工作的插件,它会影响屏幕亮度。
我正在使用
解决方案
尝试一下:
MaterialApp(
theme:ThemeData.dark(),
)
还要检查:
I am new to Flutter, i want to built an app that can control the Screen Brightness using flutter, i found a Plugin in screen 0.0.5
it is working , it can effect the screen brightness.I am using Screen Plugin you can check it.But My Problem is that when i hide the Application then the Brightness Set by my App is overwritten by Mobile's default Brightness?How it is possible to full control the phone brightness?
code
import 'package:flutter/material.dart';
import 'package:screen/screen.dart';
void main() => runApp(MaterialApp(
theme: ThemeData(primarySwatch: Colors.red, brightness: Brightness.dark),
themeMode: ThemeMode.dark,
darkTheme: ThemeData(brightness: Brightness.dark),
debugShowCheckedModeBanner: false,
home: ScreenBrightness()));
//ManageScreenDemoState pageState;
class ScreenBrightness extends StatefulWidget {
@override
_ScreenBrightnessState createState() => _ScreenBrightnessState();
}
class _ScreenBrightnessState extends State<ScreenBrightness> {
@override
double _brightness;
bool _enableKeptOn;
@override
void initState() {
super.initState();
getBrightness();
getIsKeptOnScreen();
}
void getBrightness() async {
double value = await Screen.brightness;
setState(() {
_brightness = double.parse(value.toStringAsFixed(1));
});
}
void getIsKeptOnScreen() async {
bool value = await Screen.isKeptOn;
setState(() {
_enableKeptOn = value;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Screen Brightness")),
body: Column(
children: <Widget>[
// Notice
Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.all(10),
alignment: Alignment(0, 0),
height: 50,
decoration: BoxDecoration(color: Colors.orange),
child: Text(
"Do this example on a Real Phone, not an Emulator.",
style: TextStyle(color: Colors.white),
),
),
// Brightness Settings
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Brightness:"),
(_brightness == null)
? CircularProgressIndicator(
backgroundColor: Colors.grey,
)
: Slider(
activeColor: Colors.grey,
value: _brightness,
min: 0,
max: 1.0,
divisions: 20,
onChanged: (newValue) {
setState(() {
_brightness = newValue;
});
// set screen's brightness
Screen.setBrightness(_brightness);
},
),
Text((_brightness * 100).toStringAsFixed(1) + "%"),
],
),
),
// Kept-On Settings
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Kept on Screen:"),
Text(_enableKeptOn.toString()),
(_enableKeptOn == null)
? CircularProgressIndicator(
backgroundColor: Colors.blue,
)
: Switch(
activeColor: Colors.grey,
value: _enableKeptOn,
onChanged: (flag) {
Screen.keepOn(flag);
getIsKeptOnScreen();
},
)
],
),
)
],
),
);
}
}
Image
解决方案
Try it:
MaterialApp(
theme: ThemeData.dark(),
)
Also check :
how to implement dark mode in flutter
这篇关于手机覆盖的应用亮度默认为Flutter中的亮度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!