Line data Source code
1 : import 'package:flutter/widgets.dart'; 2 : 3 : class FontWeightMapper { 4 15 : static Map<String, FontWeight> map = { 5 : 'Thin': FontWeight.w100, 6 : 'Extra-light': FontWeight.w200, 7 : 'Light': FontWeight.w300, 8 : 'Normal': FontWeight.w400, 9 : 'Medium': FontWeight.w500, 10 : 'Semi-bold': FontWeight.w600, 11 : 'Bold': FontWeight.w700, 12 : 'Extra-bold': FontWeight.w800, 13 : 'Black': FontWeight.w900, 14 : }; 15 : 16 5 : static String toFontKey(FontWeight fontWeight) { 17 : if (fontWeight == null) { 18 : return 'Normal'; 19 : } 20 : 21 : String key; 22 9 : for (var entry in map.entries) { 23 6 : if (fontWeight == entry.value) { 24 3 : key = entry.key; 25 : break; 26 : } 27 : } 28 : return key; 29 : } 30 : 31 3 : static FontWeight toFontWeight(String key) { 32 6 : return map[key]; 33 : } 34 : }