Skip to content

Commit

Permalink
refactor. color map for pokemon card
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyamAK committed Apr 14, 2024
1 parent 9f79cdb commit f6b5461
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/constants/color.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import 'package:flutter/material.dart';
import 'package:pokedex_tracker/util/color_extension.dart';

const Color primaryColor = Colors.red;
const Color appBarTextColor = Colors.white;
const Color unselectedTabColor = Color(0xFFFAD54F);
const Color displayTextColor = Colors.black;
const Map<String, Color> typesColor = {
"Grass": Colors.greenAccent,
"Water": Colors.blueAccent,
"Fire": Colors.orangeAccent,
"Normal": Colors.grey,
"Flying": Colors.lightBlueAccent,
"Bug": Colors.lightGreenAccent,
"Poison": Colors.deepPurpleAccent,
"Electric": Colors.amberAccent,
"Fighting": Colors.brown,
"Rock": Color(0xFFBD8C7A),
"Ground": Color(0xFF5F1800),
"Fairy": Colors.pinkAccent,
"Psychic": Colors.purpleAccent,
"Dark": Colors.black54,
"Steel": Colors.blueGrey,
"Dragon": Color(0xFF252FF9),
"Ice": Colors.blue
Map<String, Color> typesColor = {
"Grass": '#82C274'.hexToColor(),
"Water": '#74ACF5'.hexToColor(),
"Fire": '#EF7374'.hexToColor(),
"Normal": "#C1C2C1".hexToColor(),
"Flying": '#ADD2F5'.hexToColor(),
"Bug": '#B8C26A'.hexToColor(),
"Poison": "#B884DD".hexToColor(),
"Electric": '#FCD659'.hexToColor(),
"Fighting": '#FFAC59'.hexToColor(),
"Rock": '#CBC7AD'.hexToColor(),
"Ground": '#B88E6F'.hexToColor(),
"Fairy": '#F5A2F5'.hexToColor(),
"Psychic": '#F584A8'.hexToColor(),
"Dark": '#998B8C'.hexToColor(),
"Steel": '#98C2D1'.hexToColor(),
"Dragon": "#8D98EC".hexToColor(),
"Ice": '#81DFF7'.hexToColor(),
"Ghost": "#A284A2".hexToColor()
};
15 changes: 15 additions & 0 deletions lib/util/color_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

extension ColorExtension on String {
Color hexToColor() {
final buffer = StringBuffer();

if(length == 6 || length == 7) {
buffer.write('ff');
}

buffer.write(replaceFirst('#', ''));

return Color(int.parse(buffer.toString(), radix: 16));
}
}

0 comments on commit f6b5461

Please sign in to comment.