Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 59 additions & 24 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/material.dart';

class HomeScreen extends StatefulWidget {
Expand All @@ -9,10 +10,38 @@ class HomeScreen extends StatefulWidget {

class _HomeScreenState extends State<HomeScreen> {
String originalText = "이것과 동일하게 입력하시오";
bool isAnswer = false;

int totalSeconds = 0;
bool isTimerRunning = false;
late Timer timer;

bool isSubmitted = false;
String answerResult = "";

final textController = TextEditingController();

void onTick(Timer timer) {
setState(() {
totalSeconds = totalSeconds + 1;
});
}

void onStartTyping() {
if (isSubmitted == true) {
isSubmitted = false;
}
if (isTimerRunning == false) {
isTimerRunning = true;
totalSeconds = 0;
} else {
return;
}
timer = Timer.periodic(
const Duration(seconds: 1),
onTick,
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -56,6 +85,7 @@ class _HomeScreenState extends State<HomeScreen> {
),
TextFormField(
controller: textController,
onTap: onStartTyping,
cursorColor: Colors.white,
style: const TextStyle(
color: Colors.white,
Expand All @@ -69,41 +99,32 @@ class _HomeScreenState extends State<HomeScreen> {
border: OutlineInputBorder(),
),
onFieldSubmitted: (String text) {
setState(() {
if (originalText == textController.text) {
isAnswer = true;
} else {
isAnswer = false;
}
});
submitAnswer();
},
),
Center(
child: IconButton(
iconSize: 50,
onPressed: () {
setState(() {
if (originalText == textController.text) {
isAnswer = true;
} else {
isAnswer = false;
}
});
},
onPressed: submitAnswer,
icon: const Icon(
Icons.keyboard,
color: Colors.white,
),
),
),
Visibility(
visible: isAnswer,
child: const Text(
'정답입니다!',
style: TextStyle(
color: Colors.white,
),
))
visible: isSubmitted,
child: Text(
answerResult,
style: const TextStyle(
color: Colors.white,
),
),
),
Text(
'$totalSeconds',
style: const TextStyle(color: Colors.white, fontSize: 50),
)
],
),
),
Expand All @@ -118,4 +139,18 @@ class _HomeScreenState extends State<HomeScreen> {
),
);
}

void submitAnswer() {
setState(() {
timer.cancel();
isSubmitted = true;
isTimerRunning = false;
if (originalText == textController.text) {
answerResult = "정답입니다!";
} else {
answerResult = "틀렸습니다.";
}
textController.text = "";
});
}
}