Created
July 8, 2020 19:17
-
-
Save samuelematias/3e734835acb48167072f049de85574f3 to your computer and use it in GitHub Desktop.
DynamicColor to use on DarkMode. More about: https://stackoverflow.com/posts/62062967/revisions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension DynamicColor on BuildContext { | |
Color dynamicColor({int light, int dark}) { | |
return (Theme.of(this).brightness == Brightness.light) | |
? Color(light) | |
: Color(dark); | |
} | |
/// the white background | |
Color get backgroundColor => | |
dynamicColor(light: 0xFFFFFFFF, dark: 0xFF222A2E); | |
} | |
//How Implement | |
// import 'package:flutter/material.dart'; | |
// import 'buildcontext_extension.dart'; | |
// class Test extends StatelessWidget { | |
// @override | |
// Widget build(BuildContext context) { | |
// return Container( | |
// color: context.backgroundColor, | |
// ); | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment