This commit is contained in:
lunaticbum 2025-11-25 17:25:16 +09:00
parent bc57468aaa
commit 283f08786e
3 changed files with 817 additions and 536 deletions

View File

@ -2,7 +2,7 @@ import 'dart:convert';
import 'package:bonsoir/bonsoir.dart'; import 'package:bonsoir/bonsoir.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:playwith_core/playwith_core.dart'; // GameChatOverlay import 'package:playwith_core/playwith_core.dart'; // Core (AvatarWidget, NetworkManager )
import 'package:playwith_game_quiz/quiz_game.dart'; import 'package:playwith_game_quiz/quiz_game.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
@ -22,6 +22,7 @@ class _LobbyScreenState extends State<LobbyScreen> {
void initState() { void initState() {
super.initState(); super.initState();
//
_net.logStream.listen((log) { _net.logStream.listen((log) {
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
@ -39,6 +40,7 @@ class _LobbyScreenState extends State<LobbyScreen> {
}); });
}); });
//
_net.messageStream.listen((data) { _net.messageStream.listen((data) {
if (data['type'] == 'GAME_START') { if (data['type'] == 'GAME_START') {
final String gameId = data['gameId']; final String gameId = data['gameId'];
@ -49,10 +51,8 @@ class _LobbyScreenState extends State<LobbyScreen> {
}); });
} }
// []
void _startGameAndNavigate(BaseGame game) { void _startGameAndNavigate(BaseGame game) {
if (!mounted) return; if (!mounted) return;
game.onStart(); game.onStart();
Navigator.push( Navigator.push(
@ -65,13 +65,11 @@ class _LobbyScreenState extends State<LobbyScreen> {
gameView = game.buildGuestView(context); gameView = game.buildGuestView(context);
} }
// : //
return Stack( return Stack(
children: [ children: [
gameView, // 1. gameView,
const SafeArea( const SafeArea(child: GameChatOverlay()),
child: GameChatOverlay(), // 2. (Core )
),
], ],
); );
}), }),
@ -85,25 +83,26 @@ class _LobbyScreenState extends State<LobbyScreen> {
builder: (context, child) { builder: (context, child) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('대기실: ${_net.me.nickname}'), title: const Text('대기실'),
centerTitle: true,
actions: [ actions: [
if (_net.role == NetworkRole.host) //
IconButton(
icon: const Icon(Icons.qr_code, size: 30),
onPressed: () => _showHostQRDialog(),
),
if (_net.role != NetworkRole.none) if (_net.role != NetworkRole.none)
IconButton( IconButton(
icon: const Icon(Icons.exit_to_app), icon: const Icon(Icons.exit_to_app, color: Colors.red),
tooltip: "나가기",
onPressed: () => _net.stopNetwork(), onPressed: () => _net.stopNetwork(),
) )
], ],
), ),
body: Column( body: Column(
children: [ children: [
Expanded(flex: 3, child: _buildBody()), // ( )
const Divider(thickness: 2, color: Colors.grey), Expanded(flex: 3, child: _buildMainBody()),
const Divider(thickness: 1, height: 1),
// ()
_buildDebugConsole(), _buildDebugConsole(),
], ],
), ),
@ -112,93 +111,85 @@ class _LobbyScreenState extends State<LobbyScreen> {
); );
} }
Widget _buildDebugConsole() { // [Main Body] vs
return Column( Widget _buildMainBody() {
children: [ // 1. ( )
Container( if (_net.role == NetworkRole.none) {
width: double.infinity, return _buildInitView();
padding: const EdgeInsets.all(8.0), }
color: Colors.black87,
child: const Text("DEBUG LOGS", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), // 2. ( - / UI)
), return _buildLobbyView();
SizedBox( }
height: 150,
child: Container( // ------------------------------------------------------------------------
color: Colors.black, // 1. ( / )
child: ListView.builder( // ------------------------------------------------------------------------
controller: _scrollController, Widget _buildInitView() {
itemCount: _logs.length, return Center(
itemBuilder: (context, index) { child: SingleChildScrollView(
return Padding( child: Column(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 2.0), mainAxisAlignment: MainAxisAlignment.center,
child: Text( children: [
_logs[index], const Text("게임을 시작해볼까요?", style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
style: const TextStyle(color: Colors.greenAccent, fontSize: 12, fontFamily: 'Courier'), const SizedBox(height: 40),
),
); Row(
}, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_BigButton(
title: "방 만들기\n(Host)",
color: Colors.blue[100]!,
icon: Icons.add_home_work,
onTap: () {
_net.startHosting("${_net.me.nickname}의 방");
// QR
Future.delayed(const Duration(milliseconds: 500), () {
if (mounted && _net.role == NetworkRole.host) _showHostQRDialog();
});
},
),
_BigButton(
title: "방 찾기\n(Guest)",
color: Colors.green[100]!,
icon: Icons.search,
onTap: () => _showRoomListDialog(),
),
],
), ),
), const SizedBox(height: 30),
ElevatedButton.icon(
icon: const Icon(Icons.qr_code_scanner),
label: const Text("QR 코드로 접속하기"),
style: ElevatedButton.styleFrom(padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15)),
onPressed: () => _openQRScanner(),
),
const SizedBox(height: 10),
TextButton(
onPressed: () => _showManualJoinDialog(),
child: const Text("IP 주소 직접 입력 (비상용)", style: TextStyle(color: Colors.grey)),
),
],
), ),
], ),
); );
} }
Widget _buildBody() { // ------------------------------------------------------------------------
if (_net.role == NetworkRole.none) { // 2. ( UI)
return Center( // ------------------------------------------------------------------------
child: SingleChildScrollView( Widget _buildLobbyView() {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_BigButton(
title: "방 만들기\n(Host)",
color: Colors.blue[100]!,
icon: Icons.add_home_work,
onTap: () {
_net.startHosting("${_net.me.nickname}의 방");
Future.delayed(const Duration(milliseconds: 500), () {
if (mounted && _net.role == NetworkRole.host) _showHostQRDialog();
});
},
),
_BigButton(
title: "방 찾기\n(Guest)",
color: Colors.green[100]!,
icon: Icons.search,
onTap: () => _showRoomListDialog(),
),
],
),
const SizedBox(height: 30),
ElevatedButton.icon(
icon: const Icon(Icons.qr_code_scanner, size: 28),
label: const Text("QR 코드로 접속하기"),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
),
onPressed: () => _openQRScanner(),
),
const SizedBox(height: 10),
TextButton(
onPressed: () => _showManualJoinDialog(),
child: const Text("IP 주소 직접 입력 (비상용)", style: TextStyle(color: Colors.grey)),
),
],
),
),
);
}
return Column( return Column(
children: [ children: [
// A.
Container( Container(
padding: const EdgeInsets.all(20.0),
color: Colors.grey[100],
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.grey[100],
border: const Border(bottom: BorderSide(color: Colors.black12)),
),
child: Column( child: Column(
children: [ children: [
Row( Row(
@ -213,69 +204,90 @@ class _LobbyScreenState extends State<LobbyScreen> {
], ],
), ),
//
if (_net.role == NetworkRole.host) ...[ if (_net.role == NetworkRole.host) ...[
const SizedBox(height: 10), const SizedBox(height: 15),
Row( Container(
mainAxisAlignment: MainAxisAlignment.center, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
children: [ decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20), border: Border.all(color: Colors.blue.shade100)),
SelectableText( child: Row(
"IP: ${_net.hostIp} / Port: ${_net.hostPort}", mainAxisSize: MainAxisSize.min,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16), children: [
), Text("IP: ${_net.hostIp} : ${_net.hostPort}", style: const TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(width: 10), const SizedBox(width: 10),
InkWell( InkWell(
onTap: () => _showHostQRDialog(), onTap: () => _showHostQRDialog(),
child: const Icon(Icons.qr_code, color: Colors.black87), child: const Icon(Icons.qr_code, color: Colors.black87),
) )
], ],
),
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
const Text("QR 버튼을 눌러 친구들을 초대하세요!", style: TextStyle(fontSize: 12, color: Colors.grey)), const Text("QR 코드를 눌러 친구를 초대하세요!", style: TextStyle(fontSize: 12, color: Colors.grey)),
], ] else ...[
//
const SizedBox(height: 10),
Text("방장 IP: ${_net.hostIp ?? '...'}", style: const TextStyle(color: Colors.grey)),
]
], ],
), ),
), ),
const Divider(height: 1), // B. ( + )
Expanded( Expanded(
child: ListView( child: ListView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
children: [ children: [
const Text("참가자 목록", style: TextStyle(color: Colors.grey)), const Text("대기 중인 참가자", style: TextStyle(color: Colors.grey, fontWeight: FontWeight.bold)),
const SizedBox(height: 10), const SizedBox(height: 10),
_buildUserTile(_net.me),
..._net.guestList.map((guest) => _buildUserTile(guest)),
// 1. ( )
_buildUserTile(_net.me, isMe: true),
// 2.
..._net.guestList.map((guest) => _buildUserTile(guest, isMe: false)),
//
if (_net.guestList.isEmpty && _net.role == NetworkRole.host) if (_net.guestList.isEmpty && _net.role == NetworkRole.host)
const Padding( Padding(
padding: EdgeInsets.all(40.0), padding: const EdgeInsets.only(top: 40.0),
child: Center(child: Text("참가자를 기다리는 중...\nQR 코드를 보여주세요.", textAlign: TextAlign.center, style: TextStyle(color: Colors.grey))), child: Center(
child: Column(
children: const [
CircularProgressIndicator(),
SizedBox(height: 20),
Text("친구를 기다리는 중...", style: TextStyle(color: Colors.grey)),
],
),
),
), ),
], ],
), ),
), ),
// C.
_buildReadyButton(), _buildReadyButton(),
], ],
); );
} }
Widget _buildUserTile(UserInfo user) { Widget _buildUserTile(UserInfo user, {required bool isMe}) {
bool isMe = user.id == _net.me.id;
return Card( return Card(
elevation: 2, elevation: user.isReady ? 4 : 1,
color: user.isReady ? Colors.green[50] : Colors.white, color: user.isReady ? Colors.green[50] : Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: user.isReady ? const BorderSide(color: Colors.green, width: 2) : BorderSide.none,
),
margin: const EdgeInsets.symmetric(vertical: 6), margin: const EdgeInsets.symmetric(vertical: 6),
child: ListTile( child: ListTile(
leading: CircleAvatar( contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
backgroundColor: Color(user.colorValue), leading: AvatarWidget(user: user, size: 50), // Core의 AvatarWidget
child: Text(user.nickname[0], style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
title: Text( title: Text(
user.nickname + (isMe ? " (나)" : ""), user.nickname + (isMe ? " (나)" : ""),
style: const TextStyle(fontWeight: FontWeight.bold), style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
), ),
subtitle: Text(isMe ? "준비 버튼을 눌러주세요" : (user.isReady ? "준비 완료!" : "준비 중..."), style: TextStyle(color: Colors.grey[600], fontSize: 12)),
trailing: user.isReady trailing: user.isReady
? const Icon(Icons.check_circle, color: Colors.green, size: 32) ? const Icon(Icons.check_circle, color: Colors.green, size: 32)
: const Icon(Icons.hourglass_empty, color: Colors.grey, size: 32), : const Icon(Icons.hourglass_empty, color: Colors.grey, size: 32),
@ -285,9 +297,9 @@ class _LobbyScreenState extends State<LobbyScreen> {
Widget _buildReadyButton() { Widget _buildReadyButton() {
bool isReady = _net.me.isReady; bool isReady = _net.me.isReady;
bool canReady = _net.role == NetworkRole.host // : ( )
? _net.guestList.isNotEmpty //
: true; bool canReady = _net.role == NetworkRole.host ? _net.guestList.isNotEmpty : true;
return Container( return Container(
width: double.infinity, width: double.infinity,
@ -300,27 +312,79 @@ class _LobbyScreenState extends State<LobbyScreen> {
onPressed: canReady onPressed: canReady
? () => _net.toggleReady() ? () => _net.toggleReady()
: () { : () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("참가자가 들어와야 게임을 시작할 수 있습니다."))); ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("친구를 초대해야 시작할 수 있습니다!")));
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: !canReady backgroundColor: !canReady
? Colors.grey ? Colors.grey[300]
: (isReady ? Colors.redAccent : Colors.blueAccent), : (isReady ? Colors.redAccent : Colors.blueAccent),
padding: const EdgeInsets.symmetric(vertical: 18), padding: const EdgeInsets.symmetric(vertical: 18),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
elevation: canReady ? 5 : 0, elevation: canReady ? 5 : 0,
), ),
child: Text( child: Text(
isReady ? "준비 취소 (WAIT)" : "준비 완료 (READY)", isReady ? "준비 취소 (WAIT)" : "준비 완료 (READY)",
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white), style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: !canReady ? Colors.grey : Colors.white
),
), ),
), ),
); );
} }
// ------------------------------------------------------------------------
// [Components]
// ------------------------------------------------------------------------
Widget _buildDebugConsole() {
return Column(
children: [
GestureDetector(
onTap: () => _scrollController.jumpTo(_scrollController.position.maxScrollExtent),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
color: Colors.black87,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text("DEBUG LOGS", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 10)),
Icon(Icons.keyboard_arrow_down, color: Colors.white, size: 14)
],
),
),
),
SizedBox(
height: 100,
child: Container(
color: Colors.black,
child: ListView.builder(
controller: _scrollController,
itemCount: _logs.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 1.0),
child: Text(
_logs[index],
style: const TextStyle(color: Colors.greenAccent, fontSize: 10, fontFamily: 'Courier'),
),
);
},
),
),
),
],
);
}
// ------------------------------------------------------------------------
// [Dialogs] QR, ,
// ------------------------------------------------------------------------
void _showHostQRDialog() { void _showHostQRDialog() {
if (_net.hostIp == null || _net.hostPort == null) return; if (_net.hostIp == null || _net.hostPort == null) return;
final qrData = jsonEncode({'ip': _net.hostIp, 'port': _net.hostPort}); final qrData = jsonEncode({'ip': _net.hostIp, 'port': _net.hostPort});
showDialog( showDialog(
context: context, context: context,
builder: (context) => Dialog( builder: (context) => Dialog(
@ -330,7 +394,7 @@ class _LobbyScreenState extends State<LobbyScreen> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
const Text("초대 QR 코드", style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)), const Text("친구 초대", style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
const SizedBox(height: 20), const SizedBox(height: 20),
Container( Container(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
@ -338,7 +402,7 @@ class _LobbyScreenState extends State<LobbyScreen> {
child: QrImageView(data: qrData, version: QrVersions.auto, size: 220.0), child: QrImageView(data: qrData, version: QrVersions.auto, size: 220.0),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
Text("IP: ${_net.hostIp} / Port: ${_net.hostPort}", style: const TextStyle(color: Colors.grey)), SelectableText("IP: ${_net.hostIp}\nPort: ${_net.hostPort}", textAlign: TextAlign.center, style: const TextStyle(color: Colors.grey)),
const SizedBox(height: 20), const SizedBox(height: 20),
ElevatedButton(onPressed: () => Navigator.pop(context), child: const Text("닫기")) ElevatedButton(onPressed: () => Navigator.pop(context), child: const Text("닫기"))
], ],
@ -352,20 +416,18 @@ class _LobbyScreenState extends State<LobbyScreen> {
bool isScanCompleted = false; bool isScanCompleted = false;
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Scaffold( builder: (context) => Scaffold(
appBar: AppBar(title: const Text("QR 코드 스캔")), appBar: AppBar(title: const Text("QR 스캔")),
body: MobileScanner( body: MobileScanner(
onDetect: (capture) { onDetect: (capture) {
if (isScanCompleted) return; if (isScanCompleted) return;
final List<Barcode> barcodes = capture.barcodes; for (final barcode in capture.barcodes) {
for (final barcode in barcodes) { if (barcode.rawValue != null) {
final String? code = barcode.rawValue;
if (code != null) {
try { try {
final data = jsonDecode(code); final data = jsonDecode(barcode.rawValue!);
if (data['ip'] != null && data['port'] != null) { if (data['ip'] != null && data['port'] != null) {
isScanCompleted = true; isScanCompleted = true;
Navigator.pop(context); Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("QR 인식 성공! 접속 중..."))); ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("접속 중...")));
_net.joinRoom(data['ip'], data['port']); _net.joinRoom(data['ip'], data['port']);
return; return;
} }
@ -382,7 +444,7 @@ class _LobbyScreenState extends State<LobbyScreen> {
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: const Text("방 찾는 중..."), title: const Text("방 찾"),
content: SizedBox( content: SizedBox(
width: double.maxFinite, width: double.maxFinite,
height: 300, height: 300,
@ -390,19 +452,17 @@ class _LobbyScreenState extends State<LobbyScreen> {
stream: _net.discoverRooms(), stream: _net.discoverRooms(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data!.isEmpty) { if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const Center(child: Text("검색 중... (로그를 확인하세요)")); return const Center(child: Text("검색 중...\n같은 와이파이인지 확인하세요."));
} }
final services = snapshot.data!;
return ListView.builder( return ListView.builder(
itemCount: services.length, itemCount: snapshot.data!.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final service = services[index]; final service = snapshot.data![index];
final displayName = service.name.split('#').first;
final ip = service.attributes?['ip'] ?? '알 수 없음'; final ip = service.attributes?['ip'] ?? '알 수 없음';
return ListTile( return ListTile(
leading: const Icon(Icons.meeting_room), leading: const Icon(Icons.meeting_room),
title: Text(displayName), title: Text(service.name.split('#').first),
subtitle: Text("IP: $ip"), subtitle: Text(ip),
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context);
if (service.attributes != null && service.attributes!['ip'] != null) { if (service.attributes != null && service.attributes!['ip'] != null) {
@ -421,26 +481,25 @@ class _LobbyScreenState extends State<LobbyScreen> {
} }
void _showManualJoinDialog() { void _showManualJoinDialog() {
final ipController = TextEditingController(text: "192.168."); final ipCtrl = TextEditingController(text: "192.168.");
final portController = TextEditingController(); final portCtrl = TextEditingController();
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: const Text("수동 접속"), title: const Text("직접 입력"),
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
const Text("방장 화면의 IP/Port를 입력하세요."), TextField(controller: ipCtrl, decoration: const InputDecoration(labelText: "IP Address")),
TextField(controller: ipController, decoration: const InputDecoration(labelText: "IP")), TextField(controller: portCtrl, decoration: const InputDecoration(labelText: "Port")),
TextField(controller: portController, decoration: const InputDecoration(labelText: "Port")),
], ],
), ),
actions: [ actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text("취소")), TextButton(onPressed: () => Navigator.pop(context), child: const Text("취소")),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
final ip = ipController.text.trim(); final ip = ipCtrl.text.trim();
final port = int.tryParse(portController.text.trim()); final port = int.tryParse(portCtrl.text.trim());
if (ip.isNotEmpty && port != null) { if (ip.isNotEmpty && port != null) {
Navigator.pop(context); Navigator.pop(context);
_net.joinRoom(ip, port); _net.joinRoom(ip, port);
@ -455,29 +514,16 @@ class _LobbyScreenState extends State<LobbyScreen> {
} }
class _BigButton extends StatelessWidget { class _BigButton extends StatelessWidget {
final String title; final String title; final Color color; final IconData icon; final VoidCallback onTap;
final Color color;
final IconData icon;
final VoidCallback onTap;
const _BigButton({required this.title, required this.color, required this.icon, required this.onTap}); const _BigButton({required this.title, required this.color, required this.icon, required this.onTap});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: onTap, onTap: onTap,
child: Container( child: Container(
width: 140, height: 140, width: 130, height: 130,
decoration: BoxDecoration( decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10, offset: const Offset(0, 5))]),
color: color, borderRadius: BorderRadius.circular(20), child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Icon(icon, size: 40, color: Colors.black54), const SizedBox(height: 10), Text(title, textAlign: TextAlign.center, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold))]),
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10, offset: const Offset(0, 5))],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 40, color: Colors.black54),
const SizedBox(height: 10),
Text(title, textAlign: TextAlign.center, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
],
),
), ),
); );
} }

View File

@ -0,0 +1,108 @@
enum QuizType { text, image } //
class QuizItem {
final QuizType type;
final String question; //
final String answer; //
final List<String> options; // (, /OX)
QuizItem({
required this.type,
required this.question,
required this.answer,
required this.options,
});
Map<String, dynamic> toJson() => {
'type': type.name,
'question': question,
'answer': answer,
'options': options,
};
factory QuizItem.fromJson(Map<String, dynamic> json) {
return QuizItem(
type: json['type'] == 'image' ? QuizType.image : QuizType.text,
question: json['question'],
answer: json['answer'],
options: List<String>.from(json['options'] ?? []),
);
}
}
class QuizSet {
static List<QuizItem> getDummy10() {
return [
// 1. [OX]
QuizItem(
type: QuizType.text,
question: "사과는 영어로 Apple이다.",
answer: "O",
options: ["O", "X"],
),
// 2. [OX]
QuizItem(
type: QuizType.text,
question: "북극곰의 피부색은 흰색이다.",
answer: "X", //
options: ["O", "X"],
),
// 3. [OX]
QuizItem(
type: QuizType.text,
question: "돌고래는 '어류(물고기)'다.",
answer: "X", //
options: ["O", "X"],
),
// 4. [4]
QuizItem(
type: QuizType.text,
question: "임진왜란이 일어난 해는?",
answer: "1592년",
options: ["1392년", "1492년", "1592년", "1950년"],
),
// 5. [4]
QuizItem(
type: QuizType.text,
question: "왕이 넘어지면?",
answer: "킹콩",
options: ["왕콩", "킹콩", "전하", "꽈당"],
),
// 6. [/] ( )
QuizItem(
type: QuizType.text,
question: "가는 말이 고와야 [ ? ]가 곱다.",
answer: "오는 말",
options: ["오는 말", "가는 발", "너의 말", "우리 말"],
),
// 7. []
QuizItem(
type: QuizType.text,
question: "5 + 5 × 5 = ?",
answer: "30",
options: ["25", "30", "50", "10"],
),
// 8. []
QuizItem(
type: QuizType.text,
question: "미국의 수도는 어디일까요?",
answer: "워싱턴 D.C.",
options: ["뉴욕", "LA", "워싱턴 D.C.", "시카고"],
),
// 9. []
QuizItem(
type: QuizType.text,
question: "세상에서 가장 뜨거운 바다는?",
answer: "열바다",
options: ["불바다", "열바다", "사랑해", "동해"],
),
// 10. [OX]
QuizItem(
type: QuizType.text,
question: "개발자님은 이 앱을 완성할 수 있다!",
answer: "O",
options: ["O", "X"],
),
];
}
}

File diff suppressed because it is too large Load Diff