veilidchat/lib/components/signal_strength_meter.dart

67 lines
2.1 KiB
Dart
Raw Normal View History

2023-08-17 18:10:24 -04:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:signal_strength_indicator/signal_strength_indicator.dart';
2023-10-09 16:52:37 -04:00
import 'package:go_router/go_router.dart';
2023-08-17 18:10:24 -04:00
import '../providers/connection_state.dart';
import '../tools/tools.dart';
2023-10-21 19:23:43 -04:00
import '../veilid_support/veilid_support.dart';
2023-08-17 18:10:24 -04:00
class SignalStrengthMeterWidget extends ConsumerWidget {
const SignalStrengthMeterWidget({super.key});
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
const iconSize = 16.0;
2023-10-21 19:23:43 -04:00
final connState = ref.watch(connectionStateProvider);
2023-09-30 21:00:22 -04:00
2023-08-17 18:10:24 -04:00
late final double value;
late final Color color;
late final Color inactiveColor;
2023-10-21 19:23:43 -04:00
switch (connState.attachment.state) {
case AttachmentState.detached:
2023-08-17 18:10:24 -04:00
return Icon(Icons.signal_cellular_nodata,
size: iconSize, color: scale.grayScale.text);
2023-10-21 19:23:43 -04:00
case AttachmentState.detaching:
2023-08-17 18:10:24 -04:00
return Icon(Icons.signal_cellular_off,
size: iconSize, color: scale.grayScale.text);
2023-10-21 19:23:43 -04:00
case AttachmentState.attaching:
2023-08-17 18:10:24 -04:00
value = 0;
color = scale.primaryScale.text;
2023-10-21 19:23:43 -04:00
case AttachmentState.attachedWeak:
2023-08-17 18:10:24 -04:00
value = 1;
color = scale.primaryScale.text;
2023-10-21 19:23:43 -04:00
case AttachmentState.attachedStrong:
2023-08-17 18:10:24 -04:00
value = 2;
color = scale.primaryScale.text;
2023-10-21 19:23:43 -04:00
case AttachmentState.attachedGood:
2023-08-17 18:10:24 -04:00
value = 3;
color = scale.primaryScale.text;
2023-10-21 19:23:43 -04:00
case AttachmentState.fullyAttached:
2023-08-17 18:10:24 -04:00
value = 4;
color = scale.primaryScale.text;
2023-10-21 19:23:43 -04:00
case AttachmentState.overAttached:
2023-08-17 18:10:24 -04:00
value = 4;
color = scale.secondaryScale.subtleText;
}
inactiveColor = scale.grayScale.subtleText;
2023-10-09 16:52:37 -04:00
return GestureDetector(
onLongPress: () async {
await context.push('/developer');
},
child: SignalStrengthIndicator.bars(
value: value,
activeColor: color,
inactiveColor: inactiveColor,
size: iconSize,
barCount: 4,
spacing: 1,
));
2023-08-17 18:10:24 -04:00
}
}