Flutter CupertinoPicker์ Gradient
์ฌ์ฉ์ค์ด๋ ์ฟ ํผํฐ๋ ธ ํผ์ปค๊ฐ ์์๋ก ์ง์ ๋์ด ์์ด ์์ดํจ๋ ๋ฑ ์์๋ ๋ค์ ์๊ฒ ๋๊ปด์ ธ ๋ฏธ๋์ด์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๊ธฐ๊ธฐ ๋์ด์ %๋ก ์์ฑ๋๋๋ก ๋ณ๊ฒฝํ์๋ค.
ํผ์ปค๋ ๊ทธ๋ผ๋์ธํธ ํจ๊ณผ๋ฅผ ์ฃผ๊ธฐ ์ํด ์๋์ ๊ฐ์ ๊ทธ๋ผ๋์ธํธ ์์ ฏ์ ๋ง๋ค์ด ์คํ์ผ๋ก ์์์ ์ฌ์ฉ์ค์ด์๋๋ฐ ์ด ๊ทธ๋ผ๋์ธํธ ์์ ฏ ๋ํ ๋์ด๊ฐ ๊ณ ์ ๊ฐ์ด๊ธฐ ๋๋ฌธ์ ๋ณ๊ฒฝ์ด ํ์ํ๋ค.
- ๊ทธ๋ผ๋์ธํธ ๋์ด๋ ํผ์ปค์ ๋์ด์ ๋ง์ถฐ ๋ณ๊ฒฝ๋์ด์ผ ํจ
- ๋์์ธ์ฒ๋ผ ํผ์ปค์ ์ผ์ ๋น์จ์ด ๊ทธ๋ผ๋ฐ์ด์ ๋์ด์ผ ํจ
- ํ์ฌ๋ ๋๊ฐ์ ์์ ฏ์ ์, ์๋๋ก ๋ถ์ด๋ฏ๋ก ๊ฐ๋ณ ๊ฐ ํ์
- โ ํผ์ปค ํ ์นธ์ ๋์ด๋ฅผ ๊ตฌํ๋๊ฑด ๋ถํ์ํ ๋น์ฉ์ด ๋ค๊ณ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง ๊ฒ ๊ฐ์
class _PickerGradient extends StatelessWidget {
@override
Widget build(BuildContext context) {
final color = Colors.white;
final gradientColors = [color, color.withOpacity(0.30)];
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(
2,
(i) => Container(
height: 40,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: i == 0 ? gradientColors : gradientColors.reversed.toList(),
),
),
),
),
);
}
}
๊ทธ๋ฌ๋ ์ค CupertinoPicker์ ๊ทธ๋ผ๋ฐ์ด์ ์ด ์ด๋ ์์ด์ก๋ค๋ ์ด์๊ธ์ ๋ณด๊ฒ๋๋ค.
์๋ ์๋๊ฒ ์๋๋ผ ์์ด์ง๊ฑฐ์์ด?
ํด๋น ์ด์๋ ํ์ฌ Engineer reviewed
๋จ๊ณ์ ์๊ณ ,
๊ฐ๊น๊ฑฐ๋ ๋จผ ๋ฏธ๋์ ํด๊ฒฐ๋ ๋ ๊น์ง ์ญ์ ๋ ์ฝ๋๋ฅผ ๊ฐ์ ธ๋ค๊ฐ ์ฐ๊ธฐ๋ก ํ์๋ค.
class _PickerGradient extends StatelessWidget {
@override
Widget build(BuildContext context) {
final gradientColor = Colors.white;
return Positioned.fill(
child: IgnorePointer(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
gradientColor,
gradientColor.withAlpha(0xF2),
gradientColor.withAlpha(0xDD),
gradientColor.withAlpha(0),
gradientColor.withAlpha(0),
gradientColor.withAlpha(0xDD),
gradientColor.withAlpha(0xF2),
gradientColor,
],
stops: const <double>[0.0, 0.05, 0.09, 0.22, 0.78, 0.91, 0.95, 1.0],
),
),
),
),
);
}
}
์๋ํ๋ฉด ํด๋น ์ฝ๋๋
- ๋๊ฐ์ ๊ทธ๋ผ๋ฐ์ด์
์ ํฉ์น๊ฒ ์๋
Positioned.fill
์์ฑ์ผ๋ก ์ ์ฒด๋ฅผ ์ฑ์ฐ๋ ๋ฐฉ์- โ ๋น์จ์ ์ฌ์ฉํ์ฌ ์กฐ์ ํ ์ ์์
- ๊ทธ๋ผ๋ฐ์ด์ ๋จ๊ณ๊ฐ ๋ ์ธ๋ถํ ๋์ด์์
์ ์ด์ ๋ก ๊ธฐ์กด ๋ฌธ์ ๊ฐ ํด๊ฒฐ ๋ฐ ๊ฐ์ ๋๊ธฐ ๋๋ฌธ์ด๋ค.
๊ธฐ์กด ์ฝ๋๋ ์, ์๋๋ก ์์ ฏ ๋๊ฐ๊ฐ ํฉ์ณ์ ธ์๊ณ ๊ฐ์ด๋ฐ๋ ๋น์ด์๋ ์ํ์์ง๋ง ๋ณ๊ฒฝ ์ฝ๋๋ ์ ์ฒด๋ฅผ ์ฑ์ฐ๋ ์์ ฏ์ด๊ธฐ ๋๋ฌธ์ ๊ผญ IgnorePointer
๋ฅผ ์ฌ์ฉํ์ฌ ํฌ์ธํฐ ์ด๋ฒคํธ์์ ์ ์ธ์์ผ์ผ ํ๋ค.
์ฐธ๊ณ ๋งํฌ
์๋งคํ AbsorbPointer class