Last active
April 13, 2023 20:51
-
-
Save kkiopk/2cd003139c154aa2f792ef1b5a1b8422 to your computer and use it in GitHub Desktop.
플러터 챌린지 11 of 14 과제 T.T
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:async'; | |
class HomeScreen extends StatefulWidget { | |
const HomeScreen({Key? key}) : super(key: key); | |
@override | |
State<HomeScreen> createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> { | |
static const twentyFiveMinutes = 1500; | |
int totalSeconds = twentyFiveMinutes; | |
bool isRunning = false; | |
int totalPomodoros = 0; | |
late Timer timer; | |
void onTick(Timer timer) { | |
if (totalSeconds == 0) { | |
setState(() { | |
totalPomodoros = totalPomodoros + 1; | |
isRunning = false; | |
totalSeconds = twentyFiveMinutes; | |
}); | |
timer.cancel(); | |
} else { | |
setState(() { | |
totalSeconds = totalSeconds - 1; | |
}); | |
} | |
} | |
void onStartPressed() { | |
timer = Timer.periodic( | |
const Duration(seconds: 1), | |
onTick, | |
); | |
setState(() { | |
isRunning = true; | |
}); | |
} | |
void onPausePressed() { | |
timer.cancel(); | |
setState(() { | |
isRunning = false; | |
}); | |
} | |
void onResetPressed() { | |
timer.cancel(); | |
setState(() { | |
totalSeconds = twentyFiveMinutes; | |
isRunning = false; | |
}); | |
} | |
String formatHour(int seconds) { | |
var duration = Duration(seconds: seconds); | |
return duration.toString().split(".").first.substring(2, 4); | |
} | |
String formatMin(int seconds) { | |
var duration = Duration(seconds: seconds); | |
return duration.toString().split(".").first.substring(5, 7); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: | |
const Color(0xFFE7626C), //Theme.of(context).dialogBackgroundColor, | |
body: Column( | |
children: [ | |
const Flexible( | |
flex: 1, | |
child: Center(), | |
), | |
Flexible( | |
flex: 2, | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: [ | |
Text( | |
'POMOTIMER', | |
style: TextStyle( | |
color: Theme.of(context).cardColor, | |
fontSize: 20, | |
fontWeight: FontWeight.w400), | |
), | |
], | |
), | |
), | |
), | |
Flexible( | |
flex: 6, | |
child: Container( | |
alignment: Alignment.bottomCenter, | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text( | |
formatHour(totalSeconds), | |
style: TextStyle( | |
color: Theme.of(context).cardColor, | |
fontSize: 86, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
), | |
Text( | |
':', | |
style: TextStyle( | |
color: Theme.of(context).cardColor, | |
fontSize: 60, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text( | |
formatMin(totalSeconds), | |
style: TextStyle( | |
color: Theme.of(context).cardColor, | |
fontSize: 86, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
), | |
], | |
), | |
), | |
), | |
const Flexible( | |
flex: 3, | |
child: Center(), | |
), | |
Flexible( | |
flex: 6, | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
IconButton( | |
onPressed: isRunning ? onPausePressed : onStartPressed, | |
iconSize: 100, | |
color: Theme.of(context).cardColor, | |
icon: Icon( | |
isRunning | |
? Icons.pause_circle_outline | |
: Icons.play_circle_outline, | |
), | |
), | |
TextButton( | |
onPressed: onResetPressed, | |
child: Text( | |
'Reset', | |
style: TextStyle( | |
color: Theme.of(context).cardColor, | |
fontSize: 20, | |
fontWeight: FontWeight.w400), | |
), | |
), | |
], | |
), | |
), | |
), | |
Flexible( | |
flex: 2, | |
child: Row( | |
children: [ | |
ResultBoard( | |
totalPomodoros: totalPomodoros, | |
name: 'ROUND', | |
endNumber: 4, | |
), | |
ResultBoard( | |
totalPomodoros: totalPomodoros, | |
name: 'GOAL', | |
endNumber: 12, | |
), | |
], | |
), | |
) | |
], | |
), | |
); | |
} | |
} | |
class ResultBoard extends StatelessWidget { | |
final String name; | |
final int endNumber; | |
const ResultBoard({ | |
super.key, | |
required this.totalPomodoros, | |
required this.name, | |
required this.endNumber, | |
}); | |
final int totalPomodoros; | |
@override | |
Widget build(BuildContext context) { | |
return Expanded( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text( | |
'$totalPomodoros/$endNumber', | |
style: const TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w600, | |
color: Colors.white30, | |
), | |
), | |
Text( | |
name, | |
style: const TextStyle( | |
fontSize: 12, | |
fontWeight: FontWeight.w600, | |
color: Colors.white, | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:pomodoro/screens/home_screen.dart'; | |
void main() { | |
runApp(const App()); | |
} | |
class App extends StatefulWidget { | |
const App({Key? key}) : super(key: key); | |
@override | |
State<App> createState() => _AppState(); | |
} | |
class _AppState extends State<App> { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData( | |
dialogBackgroundColor: const Color(0xFFE7626C), | |
textTheme: const TextTheme( | |
displayLarge: TextStyle( | |
color: Color(0xFF232B55), | |
), | |
), | |
cardColor: const Color(0xFFF4EDDB), | |
), | |
home: const HomeScreen(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
업무로 늦게 시작해서 너무 부족한 작품을 남겼네요. ㅠㅠ
혹시 예시로 보여주신 작품의 링크가 있다면 부탁드립니다.
조금더 반복해서 익숙해져야 할것 같습니다.
그리고 제가 git 사용법을 잘 몰라서 폴더 그대로 올리는걸 못했습니다.