오대리ㅣㅣㅣㅣ
This commit is contained in:
93
mobile/lib/features/settings/settings_page.dart
Normal file
93
mobile/lib/features/settings/settings_page.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../core/app_settings.dart';
|
||||
import '../../core/chat_socket.dart';
|
||||
import '../../core/fcm_service.dart';
|
||||
import '../../core/msn_api.dart';
|
||||
import '../../core/session_controller.dart';
|
||||
class SettingsPage extends ConsumerStatefulWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<SettingsPage> createState() => _SettingsPageState();
|
||||
}
|
||||
|
||||
class _SettingsPageState extends ConsumerState<SettingsPage> {
|
||||
String _version = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
PackageInfo.fromPlatform().then((p) {
|
||||
if (mounted) setState(() => _version = '${p.version} (${p.buildNumber})');
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _logout() async {
|
||||
await ref.read(chatSocketProvider).disconnect();
|
||||
await ref.read(sessionProvider.notifier).logout();
|
||||
if (!mounted) return;
|
||||
context.go('/login');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeMode = ref.watch(themeModeProvider);
|
||||
final notifOn = ref.watch(notificationsEnabledProvider);
|
||||
final tt = Theme.of(context).textTheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(title: const Text('설정')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 32),
|
||||
children: [
|
||||
Text('IYKYKA', style: tt.titleLarge),
|
||||
if (_version.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 16),
|
||||
child: Text('버전 $_version', style: tt.bodySmall),
|
||||
),
|
||||
const Divider(),
|
||||
const SizedBox(height: 8),
|
||||
Text('화면', style: tt.titleSmall),
|
||||
const SizedBox(height: 8),
|
||||
SegmentedButton<ThemeMode>(
|
||||
segments: const [
|
||||
ButtonSegment(value: ThemeMode.system, label: Text('시스템')),
|
||||
ButtonSegment(value: ThemeMode.light, label: Text('라이트')),
|
||||
],
|
||||
selected: {themeMode},
|
||||
onSelectionChanged: (s) {
|
||||
if (s.isEmpty) return;
|
||||
ref.read(themeModeProvider.notifier).setThemeMode(s.first);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text('알림', style: tt.titleSmall),
|
||||
SwitchListTile(
|
||||
title: const Text('푸시 알림 허용'),
|
||||
subtitle: const Text('기기에서 알림을 허용한 경우에 적용됩니다'),
|
||||
value: notifOn,
|
||||
onChanged: (v) async {
|
||||
await ref.read(notificationsEnabledProvider.notifier).setEnabled(v);
|
||||
if (v) {
|
||||
try {
|
||||
await initializeFcmAndLocalNotifications(ref.read(msnApiProvider));
|
||||
} catch (_) {}
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.tonal(
|
||||
onPressed: _logout,
|
||||
child: const Text('로그아웃'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user