如何在 Flutter 中确定十二生肖

Sid*_*gam 5 flutter

我怎样才能在颤振中写这个?我已经用 swift 制作了这个应用程序,现在我正在 flutter 中制作该应用程序,什么是获取十二生肖的最佳方法。谢谢

let calendar = Calendar.current
    let d = calendar.component(.day, from: date)
    let m = calendar.component(.month, from: date)

    switch (d,m) {
    case (21...31,1),(1...19,2):
        return "aquarius"
    case (20...29,2),(1...20,3):
        return "pisces"
    case (21...31,3),(1...20,4):
        return "aries"
    case (21...30,4),(1...21,5):
        return "taurus"
    case (22...31,5),(1...21,6):
        return "gemini"
    case (22...30,6),(1...22,7):
        return "cancer"
    case (23...31,7),(1...22,8):
        return "leo"
    case (23...31,8),(1...23,9):
        return "virgo"
    case (24...30,9),(1...23,10):
        return "libra"
    case (24...31,10),(1...22,11):
        return "scorpio"
    case (23...30,11),(1...21,12):
        return "sagittarius"
    default:
        return "capricorn"
    }
Run Code Online (Sandbox Code Playgroud)

İlk*_*kin 5

String getZodiacSign(DateTime birthdate) {
  const List<String> signNames = [
    "Capricorn",
    "Aquarius",
    "Pisces",
    "Aries",
    "Taurus",
    "Gemini",
    "Cancer",
    "Leo",
    "Virgo",
    "Libra",
    "Scorpio",
    "Sagittarius",
    "Capricorn"
  ];
  const List<int> signDays = [0, 22, 20, 21, 21, 22, 23, 23, 23, 23, 23, 22, 22];

  if (birthdate.day < signDays[birthdate.month])
    return signNames[birthdate.month - 1];
  else
    return signNames[birthdate.month];
}
Run Code Online (Sandbox Code Playgroud)


Sid*_*gam 3

找出了基本的解决方案。


String getZodicaSign(DateTime date)  {
    var days = date.day;
    var months = date.month;
   if (months == 1) {
        if (days >= 21) {
            return "Aquarius";
        }else {
            return "Capricorn";
        }
    }else if (months == 2) {
        if (days >= 20) {
            return "Picis";
        }else {
            return "Aquarius";
        }
    }else if (months == 3) {
        if (days >= 21) {
            return "Aries";
        }else {
            return "Pisces";
        }
    }else if (months == 4) {
        if (days >= 21) {
            return "Taurus";
        }else {
            return "Aries";
        }
    }else if (months == 5) {
        if (days >= 22) {
            return "Gemini";
        }else {
            return "Taurus";
        }
    }else if (months == 6) {
        if (days >= 22) {
            return "Cancer";
        }else {
            return "Gemini";
        }
    }else if (months == 7) {
        if (days >= 23) {
            return "Leo";
        }else {
            return "Cancer";
        }
    }else if (months == 8) {
        if (days >= 23) {
            return "Virgo";
        }else {
            return "Leo";
        }
    }else if (months == 9) {
        if (days >= 24) {
            return "Libra";
        }else {
            return "Virgo";
        }
    }else if (months == 10) {
        if (days >= 24) {
            return "Scorpio";
        }else {
            return "Libra";
        }
    }else if (months == 11) {
        if (days >= 23) {
            return "Sagittarius";
        }else {
            return "Scorpio";
        }
    }else if (months == 12) {
        if (days >= 22) {
            return "Capricorn";
        }else {
            return "Sagittarius";
        }
    }
    return "";
  }
Run Code Online (Sandbox Code Playgroud)