41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
import '../../../shared/utils/format_utils.dart';
|
||
|
|
import '../services/network_speed_monitor.dart';
|
||
|
|
|
||
|
|
class NetworkSpeedIndicator extends StatelessWidget {
|
||
|
|
const NetworkSpeedIndicator({super.key, required this.monitor});
|
||
|
|
|
||
|
|
final NetworkSpeedMonitor monitor;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return ValueListenableBuilder<bool>(
|
||
|
|
valueListenable: monitor.available,
|
||
|
|
builder: (context, available, _) {
|
||
|
|
return ValueListenableBuilder<double>(
|
||
|
|
valueListenable: monitor.speed,
|
||
|
|
builder: (context, speed, _) {
|
||
|
|
final speedText = available ? formatDownloadSpeed(speed) : '--';
|
||
|
|
return Container(
|
||
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: Colors.black54,
|
||
|
|
borderRadius: BorderRadius.circular(4),
|
||
|
|
),
|
||
|
|
child: Text(
|
||
|
|
speedText,
|
||
|
|
style: const TextStyle(
|
||
|
|
color: Colors.white70,
|
||
|
|
fontSize: 12,
|
||
|
|
fontFeatures: [FontFeature.tabularFigures()],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|