티스토리 뷰
들어가며
본 게시글은 노마드코더의 Flutter로 웹툰 만들기를 보고 정리한 글입니다.
POMODORO APP
POMODORO는 25분 일하고 5분 쉬는 생산성 기술을 의미한다. 이와 관련된 앱을 Omar Sharif의 디자인으로 만들어보는 실습을 한다.
작성하다 코드 날라가서 다시 쓰기엔 시간 아까우니 코드와 완성 화면만 첨부한다.
// lib/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(
colorScheme: ColorScheme.fromSwatch(
backgroundColor: const Color(0xFFE7626C),
),
textTheme: const TextTheme(
displayLarge: TextStyle(
color: Color(0xFF232B55),
),
),
cardColor: const Color(0xFFF4EDDB),
),
home: const HomeScreen(),
);
}
}
// lib/screens/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 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 onRestartPressed() {
setState(() {
totalSeconds = twentyFiveMinutes;
if (isRunning == true) {
timer.cancel();
isRunning = false;
}
});
}
String format(int seconds) {
var duration = Duration(seconds: seconds);
return duration.toString().split(".").first.substring(2);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
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: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
iconSize: 98,
color: Theme.of(context).cardColor,
onPressed: isRunning ? onPausePressed : onStartPressed,
icon: Icon(isRunning
? Icons.pause_circle_outline
: Icons.play_circle_outline),
),
IconButton(
iconSize: 45,
color: Theme.of(context).cardColor,
onPressed: onRestartPressed,
icon: const Icon(Icons.restart_alt_rounded),
),
],
),
),
),
Flexible(
flex: 1,
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.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: 60,
fontWeight: FontWeight.w600,
color:
Theme.of(context).textTheme.displayLarge!.color,
),
),
],
),
),
),
],
),
),
],
),
);
}
}
'공부한 내용 정리 > Flutter' 카테고리의 다른 글
Flutter 기초 공부 5: Toonflix (0) | 2024.07.25 |
---|---|
Flutter 기초 공부 3: 반응형 앱 (0) | 2024.07.17 |
Flutter 생산성 올리는 팁 (0) | 2024.07.05 |
Flutter 기초 공부 2: UI 만들어보기 (0) | 2024.06.23 |
Flutter 기초 공부 1: 작동방식 개요 (0) | 2024.01.14 |
댓글