// ๐Ÿ” "๋กœ๊ทธ์ธ ์œ ์ง€" ๊ธฐ๋Šฅ. ๋กœ๊ทธ์ธ ์„ฑ๊ณต ์‹œ ๊ณ„์ • ์ •๋ณด๋ฅผ ๊ธฐ๊ธฐ์— ์ €์žฅํ•ด๋‘๊ณ , // ๋‹ค์Œ ์‹คํ–‰ ๋•Œ ๋กœ๊ทธ์ธ ํ™”๋ฉด์„ ๊ฑด๋„ˆ๋›ฐ๊ณ  ๋ฐ”๋กœ ๋Œ€์‹œ๋ณด๋“œ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ํ•œ๋‹ค. // (์„œ๋ฒ„์— ๋ณ„๋„ ์„ธ์…˜/ํ† ํฐ ๊ฐœ๋…์ด ์—†์–ด์„œ, ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์ €์žฅํ•˜์ง€ ์•Š๊ณ  ์‹ ์› ์ •๋ณด๋งŒ ์ €์žฅํ•œ๋‹ค.) import 'dart:convert'; import 'package:shared_preferences/shared_preferences.dart'; class SavedSession { final String userId; final String userName; final String role; final bool isDeviceMatched; const SavedSession({ required this.userId, required this.userName, required this.role, required this.isDeviceMatched, }); Map toJson() => { 'userId': userId, 'userName': userName, 'role': role, 'isDeviceMatched': isDeviceMatched, }; factory SavedSession.fromJson(Map json) => SavedSession( userId: json['userId'] as String, userName: json['userName'] as String, role: json['role'] as String, isDeviceMatched: json['isDeviceMatched'] as bool? ?? true, ); } class SessionStore { static const _key = 'saved_session_v1'; static Future save(SavedSession session) async { try { final prefs = await SharedPreferences.getInstance(); await prefs.setString(_key, jsonEncode(session.toJson())); } catch (_) { // ์ €์žฅ ์‹คํŒจํ•ด๋„ ๋กœ๊ทธ์ธ ์ž์ฒด๋Š” ๊ณ„์† ์ง„ํ–‰ (๋กœ๊ทธ์ธ ์œ ์ง€๋งŒ ์•ˆ ๋  ๋ฟ). } } static Future load() async { try { final prefs = await SharedPreferences.getInstance(); final raw = prefs.getString(_key); if (raw == null) return null; return SavedSession.fromJson(jsonDecode(raw)); } catch (_) { return null; } } static Future clear() async { try { final prefs = await SharedPreferences.getInstance(); await prefs.remove(_key); } catch (_) { // ๋ฌด์‹œ - ์–ด์ฐจํ”ผ ๋กœ๊ทธ์•„์›ƒ ํ™”๋ฉด์œผ๋กœ๋Š” ์ด๋™ํ•œ๋‹ค. } } }