mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-03 10:36:43 -04:00
87 lines
3 KiB
Dart
87 lines
3 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
|
|
|
import '../../proto/proto.dart' as proto;
|
|
|
|
class AvailabilityWidget extends StatelessWidget {
|
|
const AvailabilityWidget(
|
|
{required this.availability,
|
|
required this.color,
|
|
this.vertical = true,
|
|
super.key});
|
|
|
|
static Widget availabilityIcon(
|
|
proto.Availability availability,
|
|
Color color,
|
|
) {
|
|
late final Widget icon;
|
|
switch (availability) {
|
|
case proto.Availability.AVAILABILITY_AWAY:
|
|
icon = SvgPicture.asset('assets/images/toilet.svg',
|
|
colorFilter: ColorFilter.mode(color, BlendMode.srcATop));
|
|
case proto.Availability.AVAILABILITY_BUSY:
|
|
icon = const Icon(Icons.event_busy, applyTextScaling: true);
|
|
case proto.Availability.AVAILABILITY_FREE:
|
|
icon = const Icon(Icons.event_available, applyTextScaling: true);
|
|
case proto.Availability.AVAILABILITY_OFFLINE:
|
|
icon = const Icon(Icons.cloud_off, applyTextScaling: true);
|
|
case proto.Availability.AVAILABILITY_UNSPECIFIED:
|
|
icon = const Icon(Icons.question_mark, applyTextScaling: true);
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
static String availabilityName(proto.Availability availability) {
|
|
late final String name;
|
|
switch (availability) {
|
|
case proto.Availability.AVAILABILITY_AWAY:
|
|
name = translate('availability.away');
|
|
case proto.Availability.AVAILABILITY_BUSY:
|
|
name = translate('availability.busy');
|
|
case proto.Availability.AVAILABILITY_FREE:
|
|
name = translate('availability.free');
|
|
case proto.Availability.AVAILABILITY_OFFLINE:
|
|
name = translate('availability.offline');
|
|
case proto.Availability.AVAILABILITY_UNSPECIFIED:
|
|
name = translate('availability.unspecified');
|
|
}
|
|
return name;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final textTheme = theme.textTheme;
|
|
|
|
final name = availabilityName(availability);
|
|
final icon = availabilityIcon(availability, color);
|
|
|
|
return vertical
|
|
? Column(mainAxisSize: MainAxisSize.min, children: [
|
|
icon,
|
|
Text(name, style: textTheme.labelSmall!.copyWith(color: color))
|
|
])
|
|
: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
icon,
|
|
Text(' $name', style: textTheme.labelLarge!.copyWith(color: color))
|
|
]);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
final proto.Availability availability;
|
|
final Color color;
|
|
final bool vertical;
|
|
|
|
@override
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
super.debugFillProperties(properties);
|
|
properties
|
|
..add(
|
|
DiagnosticsProperty<proto.Availability>('availability', availability))
|
|
..add(DiagnosticsProperty<bool>('vertical', vertical))
|
|
..add(ColorProperty('color', color));
|
|
}
|
|
}
|