1- import 'dart:math' as math;
2-
31class WallpaperSelector {
2+ static String ? debugWallpaperPath = null ;
3+
44 static const List <String > dayWallpapers = [
55 'assets/wallpaper/day/autumn_park.jpg' ,
66 'assets/wallpaper/day/city_foggy.jpg' ,
@@ -28,17 +28,32 @@ class WallpaperSelector {
2828 'assets/wallpaper/night/town_hillside.jpg' ,
2929 ];
3030
31+ static int _hashDate (DateTime date) {
32+ final dayOfYear = date.difference (DateTime (date.year, 1 , 1 )).inDays + 1 ;
33+ return (date.year * 1000 + dayOfYear) % 2147483647 ;
34+ }
35+
3136 static String selectWallpaper (DateTime utc8Time) {
37+ if (debugWallpaperPath != null ) {
38+ return debugWallpaperPath! ;
39+ }
40+
3241 final hour = utc8Time.hour;
33- final dayOfYear = utc8Time.difference (DateTime (utc8Time.year, 1 , 1 )).inDays + 1 ;
34- final random = math.Random (utc8Time.year * 365 + dayOfYear);
42+ final dateHash = _hashDate (utc8Time);
43+ final periodHash = hour >= 6 && hour < 18
44+ ? 0
45+ : (hour >= 18 && hour < 20 ? 1 : 2 );
46+ final combinedHash = (dateHash * 3 + periodHash) % 2147483647 ;
3547
3648 if (hour >= 6 && hour < 18 ) {
37- return dayWallpapers[random.nextInt (dayWallpapers.length)];
49+ final index = combinedHash % dayWallpapers.length;
50+ return dayWallpapers[index];
3851 } else if (hour >= 18 && hour < 20 ) {
39- return duskWallpapers[random.nextInt (duskWallpapers.length)];
52+ final index = combinedHash % duskWallpapers.length;
53+ return duskWallpapers[index];
4054 } else {
41- return nightWallpapers[random.nextInt (nightWallpapers.length)];
55+ final index = combinedHash % nightWallpapers.length;
56+ return nightWallpapers[index];
4257 }
4358 }
4459
@@ -47,4 +62,3 @@ class WallpaperSelector {
4762 return now.add (const Duration (hours: 8 ));
4863 }
4964}
50-
0 commit comments