formatBps static method
格式化网络速度
Format net speed
Implementation
static String formatBps(int bps) {
if (bps < 0) return '0 bps'; // 处理负数情况
if (bps < 1000) {
// 小于 1000,显示 bps
return '${bps.toStringAsFixed(0)} bps';
} else if (bps < 1000 * 1000) {
// 1,000 ~ 999,999 -> kbps
return '${(bps / 1000).toStringAsFixed(2)} kbps';
} else if (bps < 1000 * 1000 * 1000) {
// 1,000,000 ~ 999,999,999 -> Mbps
return '${(bps / 1000 / 1000).toStringAsFixed(2)} Mbps';
} else {
// >= 1,000,000,000 -> Gbps
return '${(bps / 1000 / 1000 / 1000).toStringAsFixed(2)} Gbps';
}
}