94 lines
3.2 KiB
Dart
94 lines
3.2 KiB
Dart
import 'dart:io'; // Platform 확인용
|
|
import 'package:flutter/material.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:playwith_core/playwith_core.dart';
|
|
import 'lobby_screen.dart';
|
|
|
|
class IntroScreen extends StatefulWidget {
|
|
const IntroScreen({super.key});
|
|
|
|
@override
|
|
State<IntroScreen> createState() => _IntroScreenState();
|
|
}
|
|
|
|
class _IntroScreenState extends State<IntroScreen> {
|
|
final _nicknameController = TextEditingController();
|
|
|
|
Future<void> _enterLobby() async {
|
|
if (_nicknameController.text.trim().isEmpty) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text("닉네임을 입력해주세요.")),
|
|
);
|
|
return;
|
|
}
|
|
|
|
// [수정됨] 플랫폼별 권한 분기 처리
|
|
if (Platform.isAndroid) {
|
|
// 🤖 안드로이드: 명시적 권한 요청 필요
|
|
Map<Permission, PermissionStatus> statuses = await [
|
|
Permission.location, // 안드로이드 12 이하
|
|
Permission.nearbyWifiDevices, // 안드로이드 13 이상
|
|
].request();
|
|
|
|
// 로그 확인용
|
|
bool isNearby = statuses[Permission.nearbyWifiDevices]?.isGranted ?? false;
|
|
bool isLocation = statuses[Permission.location]?.isGranted ?? false;
|
|
print("Android 권한 Check: Nearby=$isNearby, Location=$isLocation");
|
|
|
|
// 둘 다 거부되면 진행 불가 (단, 버전에 따라 하나만 있어도 됨)
|
|
// 여기서는 "둘 다 false일 때만" 막는 것으로 완화
|
|
if (!isNearby && !isLocation) {
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text("❌ 안드로이드는 권한이 필요합니다.")),
|
|
);
|
|
return;
|
|
}
|
|
} else if (Platform.isIOS) {
|
|
// 🍎 iOS: 별도 요청 불필요
|
|
// Info.plist에 설정만 잘 되어 있다면,
|
|
// NetworkManager가 start() 될 때 시스템이 알아서 물어봅니다.
|
|
print("iOS는 권한 체크를 건너뜁니다. (실행 시 자동 팝업됨)");
|
|
}
|
|
|
|
// 초기화 및 입장
|
|
NetworkManager().initialize(nickname: _nicknameController.text.trim());
|
|
|
|
if (!mounted) return;
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const LobbyScreen()),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Text('PlayWith', style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 40),
|
|
TextField(
|
|
controller: _nicknameController,
|
|
decoration: const InputDecoration(
|
|
labelText: '닉네임을 입력하세요',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: _enterLobby,
|
|
style: ElevatedButton.styleFrom(minimumSize: const Size(double.infinity, 50)),
|
|
child: const Text('입장하기'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |