SharedPreferencesの型ごとにやるの面倒くさいからこれで型を意識しなくていいような?
prefs_manager.dart
class PrefsManager { final SharedPreferences _prefs; PrefsManager(this._prefs); Future<void> save<T>(String key, T value) async { if (value is String) { await _prefs.setString(key, value); } else if (value is int) { await _prefs.setInt(key, value); } else if (value is bool) { await _prefs.setBool(key, value); } else if (value is double) { await _prefs.setDouble(key, value); } else { throw ArgumentError('Unsupported type'); } } T? load<T>(String key) { if (T == String) { return _prefs.getString(key) as T?; } else if (T == int) { return _prefs.getInt(key) as T?; } else if (T == bool) { return _prefs.getBool(key) as T?; } else if (T == double) { return _prefs.getDouble(key) as T?; } else { throw ArgumentError('Unsupported type'); } } }