friend_stress_state.dart 1.63 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);

  final int value;

  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,
    };
  }
}