Flutter/์ผ๋ฐ˜

1. Provider ํ”Œ๋Ÿฌํ„ฐ์—๋Š” Stateless์™€ Stateful ์œ„์ ฏ์ด ์กด์žฌํ•˜๋Š”๋ฐ Stateful์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒํƒœ๊ฐ€ ๋ณ€๊ฒฝ๋œ๋‹ค๋ฉด, ์ด๋ฅผ ํ™”๋ฉด์— ๋ฐ˜์˜์„ ํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ ์ด๋•Œ setstate(){}๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ€๊ฒฝ๋œ ํ™”๋ฉด์„ ์—…๋ฐ์ดํŠธ๋ฅผ ์‹œ์ผœ์ค„ ์ˆ˜๊ฐ€ ์žˆ๋‹ค. 1. Stateless๋Š” Constructor์ด ์ƒ์„ฑ๋˜๊ณ  ์ƒ์„ฑ๋˜์ž๋งˆ์ž build ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ผ์ดํ”„ ์‚ฌ์ดํด๋™์•ˆ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋œ๋‹ค -> ๊ทธ ํ›„ ๋ณ€๊ฒฝ์ด ๋ถˆ๊ฐ€๋Šฅ 2. Stateful ์œ„์ ฏ์€ Constructor์ด ์‹คํ–‰๋˜๊ณ  ๋‚œ ํ›„ createState๊ฐ€ ๋ถˆ๋ฆฌ๊ฒŒ ๋œ๋‹ค. ๋งŒ์•ฝ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ์ด ๋œ๋‹ค๋ฉด ํ˜ธ์ถœ์ˆœ์„œ๋Š” 1 -> didUpdateWidget -> 5 -> 6 -> 7 ํ•˜์ง€๋งŒ setState๋Š” state๋‚ด๋ถ€์—์„œ ์ง„ํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜ธ์ถœ์ˆœ์„œ๋Š” setSt..
์ฝ”๋”ฉ์„ ํ•˜๋‹ค๋ณด๋ฉด ์—๋ฎฌ ํ•ธ๋“œํฐ ์ƒ๋‹จ์˜ ๊ธ€์”จ ์ƒ‰๊น”์ด ํฐ์ƒ‰์ด๋ผ ์ž˜ ์•ˆ๋ณด์ผ๋•Œ๊ฐ€ ์žˆ๋‹ค. build ๋ถ€๋ถ„ ๋ฐ‘์— SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark); ์œ„ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๊ฒ€์€์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ ํ•  ์ˆ˜ ์žˆ๋‹ค.
๋‚˜๋Š” ์•„๋ฌด ์ƒ๊ฐ์—†์ด ์ฝ”๋”ฉํ• ๋•Œ ์ฃผ๋กœ asset์„ ์ด์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณค ํ•œ๋‹ค. ๊ทธ๋Ÿด๋•Œ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์œ„์™€ ๊ฐ™์€ ์‹์œผ๋กœ ์ˆซ์ž๋งŒ ๋ฐ”๋€Œ๊ณ  ๋˜‘๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ค‘๋ณตํ•ด์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ์œ„ ์ฝ”๋“œ์™€ ๊ฐ™์ด Mapํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋งค์šฐ ๊น”๋”ํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋งŒ ์ฃผ์˜ํ•ด์•ผํ•  ์ ์œผ๋กœ๋Š” ๋ฐ˜๋“œ์‹œ ํƒ€์ž…์„ .toList()๋กœ ๋งŒ๋“ค์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ๊ทธ ์ด์œ ๋กœ๋Š” children์˜ ๋ฐ˜ํ™˜ํƒ€์ž…์€ List์ด๋‹ค. Map์€ Iterableํƒ€์ž…์ด๋ฏ€๋กœ .toList()๋ฅผ ํ†ตํ•ด Listํ˜•์‹์œผ๋กœ ๋ฐ”๊พธ์–ด ์ฃผ์–ด์•ผ๋งŒ ์—๋Ÿฌ์—†์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
๋‚˜๋Š” ํ”Œ๋Ÿฌํ„ฐ๋ฅผ ๋ฐฐ์šธ๋•Œ Navigator.of(context).push()๋ฅผ ํ†ตํ•ด ๋‹จ์ˆœ ํŽ˜์ด์ง€ ์ „ํ™˜๋งŒ ๋˜๋Š”์ค„ ์•Œ์•˜๋‹ค. ํ•˜์ง€๋งŒ ๊ณต์‹๋ฌธ์„œ๋ฅผ ๋ณด๋˜์ค‘ PageRouteBuilder๋ฅผ ํ†ตํ•ด ์ „ํ™˜์„ ์ข€๋” ๋…ํŠนํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š”๊ฒƒ์„ ์•Œ์•˜๋‹ค. ์‚ฌ์šฉ๋ฒ•์€ ๋งค์šฐ ๊ฐ„๋‹จํ•˜๋‹ค. Route _createRoute() { return PageRouteBuilder( pageBuilder: (context, animation, secondaryAnimation) => const Page2(), transitionsBuilder: (context, animation, secondaryAnimation, child) { const begin = Offset(0.0, 1.0); const end = Offset.zero; final twee..
์ œ์Šค์ฒ˜๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ์œ„์ ฏ์ž…๋‹ˆ๋‹ค. NULL์ด ์•„๋‹Œ ์ฝœ๋ฐฑ์— ํ•ด๋‹นํ•˜๋Š” ์ œ์Šค์ฒ˜๋ฅผ ์ธ์‹ํ•ฉ๋‹ˆ๋‹ค. ์ด ์œ„์ ฏ์— ์ž์‹์ด ์žˆ์œผ๋ฉด ํฌ๊ธฐ๋Š” ํ•ด๋‹น ์ž์‹์„ ๋”ฐ๋ฅด๊ณ  ๋งŒ์•ฝ ์ž์‹์ด ์—†์„๊ฒฝ์šฐ ๋ถ€๋ชจ์— ๋งž์ถฐ์„œ ํฌ๊ธฐ๊ฐ€ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค. https://api.flutter.dev/flutter/widgets/GestureDetector-class.html ์‚ฌ์šฉ๋ฒ•์€ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉํ•˜๋ ค๋Š” Gesture ์†์„ฑ์„ ์„ ํƒํ•˜๊ณ  ์–ด๋–ค ๋™์ž‘์„ ํ• ์ง€ ์„ ์–ธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. import 'package:flutter/material.dart'; void main() => runApp( MaterialApp( home: HomeScreen(), ), ); class HomeScreen extends StatefulWidget { const HomeScreen({super.k..
Hac. Dog ๐ŸŒญ
'Flutter/์ผ๋ฐ˜' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)