Created
February 12, 2020 03:04
-
-
Save frank06/5418589935e1bce843a6bda6df5e749f to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
extension ColorExtension on String { | |
toColor() { | |
var hexColor = this.replaceAll("#", ""); | |
if (hexColor.length == 6) { | |
hexColor = "FF" + hexColor; | |
} | |
if (hexColor.length == 8) { | |
return Color(int.parse("0x$hexColor")); | |
} | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Welcome to Flutter', | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Welcome to Flutter'), | |
), | |
body: Center( | |
child: Text( | |
'Hello World', | |
style: TextStyle(backgroundColor: '#bfeb91'.toColor()), // or 'bfeb91', or 'ffbfeb91' | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment