allscore_app/lib/dialogs/survey_dialog.dart

138 lines
5.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
2025-01-18 09:28:24 +00:00
import '../survey/survey_page.dart';
/// Shows the survey modal (팝업(모달) 자체를 보여주는 함수)
2025-01-18 09:28:24 +00:00
Future<void> showSurveyDialog(BuildContext context, String nickname) async {
showDialog(
context: context,
barrierDismissible: false, // 바깥 영역 터치로 닫기 방지
2025-01-18 09:28:24 +00:00
builder: (_) => SurveyDialog(nickname: nickname),
);
}
/// The actual AlertDialog widget (실제 AlertDialog 형태의 위젯)
class SurveyDialog extends StatefulWidget {
2025-01-18 09:28:24 +00:00
final String nickname;
const SurveyDialog({
Key? key,
required this.nickname,
}) : super(key: key);
@override
State<SurveyDialog> createState() => _SurveyDialogState();
}
class _SurveyDialogState extends State<SurveyDialog> {
bool _todayNotSee = false;
// "오늘 하루 보지 않기" 체크 여부
2025-01-29 16:34:46 +00:00
// Scale factor for font size (폰트 크기 조절 스케일 인자)
double scaleFactor = 1.0;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_updateScaleFactor();
}
// Adjust font size by screen width (화면 크기에 따라 폰트 크기 조절)
void _updateScaleFactor() {
final screenWidth = MediaQuery.of(context).size.width;
const baseWidth = 400.0;
setState(() {
scaleFactor = (screenWidth / baseWidth).clamp(0.8, 1.4);
});
}
@override
Widget build(BuildContext context) {
return AlertDialog(
2025-01-29 16:34:46 +00:00
title: Text('Survey Participation Notice', style: TextStyle(fontSize: 24 * scaleFactor)),
// '설문 참여 안내'
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
2025-01-29 16:34:46 +00:00
Text(
'Hello, thank you for using the "ALLSCORE" app.\n\n'
'We have prepared a simple survey to provide better service.\n'
'Your participation will greatly help the apps improvement!\n'
2025-01-29 16:34:46 +00:00
'(It takes about 1 minute.)',
// '안녕하세요, "올스코어" 앱을 이용해주셔서 감사합니다.\n\n'
// '더 나은 서비스 제공을 위해 간단한 설문조사를 준비했습니다.\n'
// '설문조사에 참여해주시면 앱 발전에 큰 도움이 됩니다!\n'
// '(약 1분 소요)'
2025-01-29 16:34:46 +00:00
style: TextStyle(fontSize: 15 * scaleFactor),
),
const SizedBox(height: 16),
// "Today do not see again" checkbox ("오늘 하루 보지 않기" 체크박스)
Row(
children: [
2025-01-29 16:34:46 +00:00
Transform.scale(
scale: scaleFactor,
child: Checkbox(
value: _todayNotSee,
onChanged: (val) {
setState(() {
_todayNotSee = val ?? false;
});
},
),
),
2025-01-29 16:34:46 +00:00
Text('Do not show again today', style: TextStyle(fontSize: 12 * scaleFactor)),
// '오늘 하루 보지 않기'
],
),
],
),
),
actions: [
// "Close" button ("닫기" 버튼)
TextButton(
onPressed: () async {
// If "Do not show again today" is checked, store in SharedPreferences
// (오늘 하루 보지 않기를 체크했다면, SharedPreferences 저장)
if (_todayNotSee) {
final prefs = await SharedPreferences.getInstance();
// e.g. survey_popup_today = 'Y'
await prefs.setString('survey_popup_today', 'Y');
}
Navigator.pop(context); // close popup (팝업 닫기)
},
style: TextButton.styleFrom(backgroundColor: Colors.grey),
2025-01-29 16:34:46 +00:00
child: Text(
'Close',
// '닫기'
2025-01-29 16:34:46 +00:00
style: TextStyle(color: Colors.white, fontSize: 12 * scaleFactor),
),
),
// "Participate in Survey" button ("설문 참여" 버튼)
TextButton(
onPressed: () async {
// If "Do not show again today" is checked, store in SharedPreferences
// (오늘 하루 보지 않기를 체크했다면, SharedPreferences 저장)
if (_todayNotSee) {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('survey_popup_today', 'Y');
}
Navigator.pop(context); // close popup (팝업 닫고)
// Navigate to the temporary survey page (임시 설문 페이지로 이동)
Navigator.push(
context,
2025-01-18 09:28:24 +00:00
MaterialPageRoute(builder: (_) => SurveyPage(nickname: widget.nickname)),
);
},
style: TextButton.styleFrom(backgroundColor: Colors.black),
2025-01-29 16:34:46 +00:00
child: Text(
'Participate in Survey',
// '설문 참여'
2025-01-29 16:34:46 +00:00
style: TextStyle(color: Colors.white, fontSize: 12 * scaleFactor),
),
),
],
);
}
}