Skip to content

Instantly share code, notes, and snippets.

View H3mnz's full-sized avatar

H3mnz H3mnz

View GitHub Profile
@ArefMozafari
ArefMozafari / DartGist2.dart
Last active August 5, 2021 17:11
Flutter/Dart - How to convert En/Fa entered number to each other
extension StringExtentions on String {
String replaceFaNumToEnNum() {
const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const farsi = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
String value = this;
for (int i = 0; i < farsi.length; i++) {
value = value.replaceAll(farsi[i], english[i]);
}
@zzpmaster
zzpmaster / formatBytes.dart
Last active April 21, 2025 17:26
convert bytes to kb mb in dart
static String formatBytes(int bytes, int decimals) {
if (bytes <= 0) return "0 B";
const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var i = (log(bytes) / log(1024)).floor();
return ((bytes / pow(1024, i)).toStringAsFixed(decimals)) +
' ' +
suffixes[i];
}