OpenContacts/lib/models/users/online_status.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
enum OnlineStatus {
offline,
invisible,
away,
busy,
2024-07-15 00:09:15 -04:00
online,
sociable;
static final List<Color> _colors = [
Colors.transparent,
2024-07-15 00:09:15 -04:00
Colors.grey,
Colors.yellow,
Colors.red,
Colors.green,
2024-07-15 00:09:15 -04:00
Colors.blue,
];
Color color(BuildContext context) => this == OnlineStatus.offline || this == OnlineStatus.invisible
? Theme.of(context).colorScheme.onSecondaryContainer.withAlpha(150)
: _colors[index];
factory OnlineStatus.fromString(String? text) {
return OnlineStatus.values.firstWhere(
(element) => element.name.toLowerCase() == text?.toLowerCase(),
2023-09-29 09:33:43 -04:00
orElse: () => OnlineStatus.online,
);
}
int compareTo(OnlineStatus other) {
if (this == other) return 0;
2024-07-15 00:09:15 -04:00
if (this == OnlineStatus.sociable) return -1;
if (other == OnlineStatus.sociable) return 1;
if (this == OnlineStatus.online) return -1;
if (other == OnlineStatus.online) return 1;
if (this == OnlineStatus.away) return -1;
if (other == OnlineStatus.away) return 1;
if (this == OnlineStatus.busy) return -1;
if (other == OnlineStatus.busy) return 1;
return 0;
}
}