Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved. 2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file. 3 : 4 : import 'dart:math'; 5 : 6 : import 'package:flutter/material.dart'; 7 : 8 : extension IntExt on int { 9 3 : static final Map<String, IconData> _cache = {}; 10 : 11 1 : IconData toIcon() { 12 2 : if (_cache.containsKey(this)) { 13 0 : return _cache[this]!; 14 : } else { 15 : const String fontFamily = 'MaterialIcons'; 16 1 : return IconData(this, fontFamily: fontFamily); 17 : } 18 : } 19 : 20 0 : String toByteSize() { 21 : const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; 22 0 : if (this == 0) return '0 B'; 23 0 : final i = (log(this) / log(1024)).floor(); 24 0 : return '${(this / pow(1024, i)).toStringAsFixed(2)} ${sizes[i]}'; 25 : } 26 : }