friend_stress_state.dart 1.75 KB
import 'package:doublefeel_flutter/r.dart';
import 'package:flutter/material.dart';

enum FriendStressState {
  wait(0, '等待数据'),
  stressful(1, '压力过载'),
  slightStress(2, '注意压力'),
  normal(3, '状态正常'),
  energetic(4, '状态优秀');

  const FriendStressState(this.value, this.label);

  final int value;
  final String label;

  static FriendStressState fromValue(int? value) {
    return switch (value) {
      1 => FriendStressState.stressful,
      2 => FriendStressState.slightStress,
      3 => FriendStressState.normal,
      4 => FriendStressState.energetic,
      _ => FriendStressState.wait,
    };
  }

  bool get hasData => this != FriendStressState.wait;

  int? get segmentIndex {
    return switch (this) {
      FriendStressState.stressful => 0,
      FriendStressState.slightStress => 1,
      FriendStressState.normal => 2,
      FriendStressState.energetic => 3,
      FriendStressState.wait => null,
    };
  }

  Color get color {
    return switch (this) {
      FriendStressState.stressful => const Color(0xFFFF5279),
      FriendStressState.slightStress => const Color(0xFFFF9A6E),
      FriendStressState.normal => const Color(0xFF7B9BFB),
      FriendStressState.energetic => const Color(0xFF3BD49D),
      FriendStressState.wait => const Color(0xFFF3F3F3),
    };
  }

  String get iconPath {
    return switch (this) {
      FriendStressState.stressful => R.assetsImagesRealtimeStressOverloadIcon,
      FriendStressState.slightStress =>
        R.assetsImagesRealtimeStressAttentionIcon,
      FriendStressState.normal => R.assetsImagesRealtimeStressNormalIcon,
      FriendStressState.energetic => R.assetsImagesRealtimeStressExcellentIcon,
      FriendStressState.wait => R.assetsImagesRealtimeStressNoDataIcon,
    };
  }
}