Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 도커설치하는법
- vm도커설치하는법
- 스프링부트api
- 우분투도커설치
- 출처 따배도
- 서버에도커설치
- 스프링부트사진올리기
- 스프링부트팔로잉
- 스프링부트
- 스프링사진
- 스프링부트서버에사진전송
- 멀티폼
- dockerinstall
- 스프링부트중복예외처리
- 인스타클론
- centos도커설치
- WAS웹서버
- 파이썬sort
- 출처 문어박사
- 스프링이미지업로드
- 스프링부트팔로우취소
- ssh도커설치
- 출처 코딩셰프
- springboot_exception_handler
- 스프링부트구독취소
- 출처 메타코딩
- 스프링구독
- 출처 노마드코더
- 스프링사진업로드
- 스프링익셉션처리
Archives
- Today
- Total
MakerHyeon
[Flutter] 뽀모도로앱 본문
● main.dart
import 'package:flutter/material.dart';
import 'package:toonflix/screens/home_screen.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
// backgroundColor
colorScheme: ColorScheme.fromSwatch(
backgroundColor: const Color(0xFFE7626c),
),
textTheme: const TextTheme(
displayLarge: TextStyle(
color: Color(0xFF232B55),
),
),
cardColor: const Color(0xFFF4EDDB),
),
home: const HomeScreen(),
);
}
}
● home_screen.dart
import 'package:flutter/material.dart';
import 'dart:async';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.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 ; property를 당장 초기화 하지 않아도 됨을 뜻함
late Timer timer;
void onTick(Timer timer) {
if (totalSeconds == 0) {
totalPomodoros = totalPomodoros + 1;
isRunning = false;
totalSeconds = twentyFiveMinutes;
} else {
setState(() {
totalSeconds = totalSeconds - 1;
});
}
setState(() {
totalSeconds -= 1;
});
timer.cancel();
}
void onStartPressed() {
// Timer ; 정해진 간격에 한번씩 함수를 실행
// 매초마다 onTick 실행
timer = Timer.periodic(
const Duration(seconds: 1),
onTick,
);
setState(() {
isRunning = true;
});
}
void onPausePressed() {
timer.cancel();
setState(() {
isRunning = false;
});
}
void onStopPressed() {
timer.cancel();
setState(() {
totalSeconds = twentyFiveMinutes;
totalPomodoros = 0;
isRunning = false;
});
}
String format(int seconds) {
var duration = Duration(seconds: seconds);
//print(duration.toString().split(".").first.substring(2, 7));
return duration.toString().split(".").first.substring(2, 7);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
body: Column(
children: [
// * Flexible은 하드코딩 되는 값을 만들게 해준다.
// 하나의 박스가 얼마나 공간을 차지할 지 비율을 정할 수 있다.
// UI를 비율에 기반해서 더 유연하게 만들 수 있게 해준다.
Flexible(
flex: 1,
child: Container(
// 시계간격 맨위에서 조금아래로
alignment: Alignment.bottomCenter,
child: Text(
format(totalSeconds),
style: TextStyle(
color: Theme.of(context).cardColor,
fontSize: 89,
fontWeight: FontWeight.w600,
),
),
),
),
Flexible(
flex: 3,
child: Column(
children: [
IconButton(
iconSize: 120,
color: Theme.of(context).cardColor,
onPressed: isRunning ? onPausePressed : onStartPressed,
icon: Icon(isRunning
? Icons.pause_circle_outline
: Icons.play_circle_outline),
),
IconButton(
onPressed: onStopPressed,
icon: const Icon(Icons.restart_alt),
iconSize: 90,
color: Theme.of(context).cardColor,
),
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
// 끝까지 확장
Expanded(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(50),
topRight: Radius.circular(50),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Pomodoros',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color:
Theme.of(context).textTheme.displayLarge!.color,
),
),
Text(
'$totalPomodoros',
style: TextStyle(
fontSize: 58,
fontWeight: FontWeight.w600,
color:
Theme.of(context).textTheme.displayLarge!.color,
),
)
],
),
),
),
],
),
),
],
),
);
}
}
'Flutter' 카테고리의 다른 글
[Flutter] App bar icon button (0) | 2023.04.03 |
---|---|
[Flutter] 간단한 화면 구성 연습 # 1 (0) | 2023.04.03 |
[Flutter] 기본 구조 template (0) | 2023.03.28 |
[Flutter] WebtoonCards (0) | 2023.03.25 |
[Flutter] Scaffold,생성자 (0) | 2023.02.27 |
Comments