Skip to content

Instantly share code, notes, and snippets.

@samuelematias
Created July 8, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/3e734835acb48167072f049de85574f3 to your computer and use it in GitHub Desktop.
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
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