I have noticed color shade difference between scaffold color and safe area color eventhough i am applying same colors to it.
IT’s NOT WORKING if i applying following
Color color=const Color(0xE8024585);
but ITS WORKING with following
Color color=Colors.blue;
so what is exact issue
class PractiseScreen extends StatelessWidget {
const PractiseScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Color color=const Color(0xE8024585);
//Color color=Colors.blue;// this is showing same color
return Container(
color: color,
child: SafeArea(
child: Scaffold(
backgroundColor: color,
body: Container(
color: color,
child: Center(child: Text('Safearea is darker than scaffod',style: TextStyle(
color: Colors.white
),),),
),
),),
);
}
}
2
Answers
This issue is because of the opacity component in the color you’re using
Color(0xE8024585)
. when you want to use a color with hexadecimal value the first 2 digits are the alpha channel which is for the opacity of the color.Colors.blue
is a predefined color that its alpa is0xFF
. by changing your alpha part to0xFF
your issue is going to be solve.because using0xFF
for the alpha side means that you want a fully opaque color.FF
==> 100% of opacity.Happy coding…
Interestingly, here’s how I resolved that case:
Replace your code snippet,
with,
UPDATE:
To achieve the same output with using your current code snippet, here’s how:
Use
SystemChrome.setSystemUIOverlayStyle
:This will be the output from the two modified code snippets:
Don’t mind the padding-like from the upper-left corner; it’s due to my device’s front camera.
I hope it helps!