๋ธ๋ก๊ทธ ๋ด์ ๊ฒ์๋ฌผ์ PC ๋ฒ์ ์ ์ต์ ํ ๋์ด ์์ต๋๋ค.
์ค๋์ ModalBttomSheet๋ฅผ ์ฌ์ฉํ๋ฉด์ ๋ฐ์ํ๋ ๋ฌธ์ ์ ๋ํด ์ ์ด๋ณด๋ ค๊ณ ํฉ๋๋ค.
ModalBottomSheet์ TextField๋ฅผ ์ฌ์ฉํ์ฌ ํค๋ณด๋๋ก ์ฌ์ฉ์์ ์ ๋ ฅ์ ๋ฐ์ผ๋ ค๊ณ ํ์ต๋๋ค. ํ์ง๋ง ModalBottomSheet๊ฐ ํ์ ๋ ํค๋ณด๋์ ๋์ด๋งํผ ์ฌ๋ผ๊ฐ์ง ์์์ ModalBottomSheet๊ฐ ํค๋ณด๋์ ๊ฐ๋ ค์ง๋ ํ์์ด ๋ฐ์ํ์ต๋๋ค.
์๋์ ๊ฐ์ ์ํฉ์ ๋๋ค.
ํค๋ณด๋๊ฐ ํ์ ๋๋ฉด์ ModalBottomSheet๋ฅผ ๊ฐ๋ ค ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ํ ์คํธ๋ฅผ ํ์ธํ ์ ์๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
ModalBottomSheet๊ฐ ํค๋ณด๋์ ์ํด ๊ฐ๋ ค์ง๋ ํ์
์ฐ์ ModalBottomSheet์ ์์ฑ์ ๋ํด ๋ถ์ํ์ต๋๋ค.
๊ทธ๋ฌ๋ ์ค isScrollControlled๋ฅผ ๋ฐ๊ฒฌํ๊ณ Default๋ก false๋ก ๋์ด ์๋ ๊ฒ์ ๋ฐ๊ฒฌํ๊ณ ์ด๋ฅผ true๋ก ์์ ํ์ต๋๋ค. ํ์ง๋ง ์ฌ์ ํ ๋ฌธ์ ๋ ํด๊ฒฐ๋์ง ์์์ต๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๊ณ ๋ฏผํ๋ ์ค ๋ฌธ๋ ์ด๋ฐ ์๊ฐ์ด ๋ ์ฌ๋์ต๋๋ค. ํค๋ณด๋์ ์ํด ๊ฐ๋ ค์ง ํฌ๊ธฐ๋งํผ margin์ด๋ padding์ ์ฃผ๋ฉด ๋์ง ์์๊นํ๋ ์๊ฐ์ด ๋ค์๊ณ ์ด๋ฅผ ์ ์ฉํ์ต๋๋ค. ์ฐ์ margin์ ์ด๋ฏธ ์ฌ์ฉ ์ค์ด์๊ธฐ์ padding์ผ๋ก ์ ๊ทผํ์ต๋๋ค.
showModalBottomSheet<void>(
isScrollControlled: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
builder: (context) {
return Container(
height: 130,
margin: const EdgeInsets.all(16),
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text("์ง์ญ๋ช
๋ง ๊ฐ๋จํ๊ฒ ์
๋ ฅํด์ฃผ์ธ์.\n'ํ๊ต๋'์ ๋ฑ๋กํ๊ณ ์ถ๋ค๋ฉด 'ํ๊ต'๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."),
const SizedBox(height: 8),
const TextField(
decoration: InputDecoration(
hintText: "๊ด์ฌ ์ง์ญ์ ์
๋ ฅํด์ฃผ์ธ์.",
),
),
const SizedBox(height: 16),
InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
height: 50,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.blue,
),
child: const Text(
"์
๋ ฅ ์๋ฃ",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
)),
],
),
);
});
ํค๋ณด๋์ ์ํด ๊ฐ๋ ค์ง ํฌ๊ธฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด์ MediaQuery.of(context).viewInsets.bottom์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. ์ดํด๋ฅผ ๋๊ธฐ ์ํด ํค๋ณด๋๊ฐ ์ฌ๋ผ์ค๊ธฐ ์ , ํ์ MediaQuery.of(context).viewInsets.bottom๋ฅผ ์ถ๋ ฅํ์ต๋๋ค.
I/flutter (13569): 0.0 (ํค๋ณด๋๊ฐ ์ฌ๋ผ์ค๊ธฐ ์ ์ ์ถ๋ ฅ ๊ฒฐ๊ณผ)
I/flutter (13569): 250.9090909090909 (ํค๋ณด๋๊ฐ ์ฌ๋ผ์จ ํ์ ์ถ๋ ฅ ๊ฒฐ๊ณผ)
์ด๋ ๊ฒ ํด๊ฒฐ๋ ์ค ์์์ง๋ง ๋ฌธ์ ๋ ํด๊ฒฐ๋์ง ์์๊ณ , ํค๋ณด๋์ ์ํด ๊ฐ๋ ค์ง ํฌ๊ธฐ๋ณด๋ค ์์ Container์๊ธฐ์ Padding์ ์ฃผ๋ฉด Container ์์ญ์ ๋ฒ์ด๋๋ ๊ฒ์ด์์ต๋๋ค. ๊ทธ๋์ Container ํฌ๊ธฐ๋ฅผ ํค๋ณด๋์ ํฌ๊ธฐ๋ณด๋ค ํฌ๊ฒ ์์ ํ๊ณ (๊ธฐ์กด 130์์ 400) ๊ทธ ๊ฒฐ๊ณผ ModalBottomSheet๊ฐ ํค๋ณด๋์ ๊ฐ๋ ค์ง๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์์ต๋๋ค.
ํ์ง๋ง ์ฌ์ ํ ๋ฌธ์ ๊ฐ ํ๋ ๋จ์์์ต๋๋ค. Container์ height๋ฅผ 400์ผ๋ก ์ค ํ์ ์ฌ๋ฐฑ์ด ๋๋ฌด ๋ง์์ต๋๋ค. ๊ทธ๋ ๋ค๊ณ height๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ์ต๋ ํฌ๊ธฐ๋ก ์ค์ ๋์ด ModalBottomSheet๊ฐ ํ๋ฉด ์ ์ฒด๋ฅผ ๋ฎ์ด๋ฒ๋ฆฌ๋ ์ํฉ์ด ๋ฐ์ํ์ต๋๋ค.
Container์ height๋ฅผ ๋ช ์์ ์ผ๋ก ์ง์ ํ์ง ์๊ณ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ฐพ๋ ๋์ค Column์ mainAxisSize ์์ฑ์ ์๊ฒ๋์ต๋๋ค. Container์ height ๋์ Column.mainAxisSize๋ฅผ mainAxisSize.min์ ์ง์ ํจ์ผ๋ก์จ Container๊ฐ ์ต๋ ํฌ๊ธฐ๋ฅผ ๊ฐ๋ ๊ฒ์ ๋ฐฉ์งํ๊ณ viewInsets.bottom์ ์ํด ํ๋ฉด์ด ์๋ก ๋ฐ๋ ค๋ฌ์ ๋๋ Column.mainAxisSize + Padding๋งํผ์ height๋ฅผ ๊ฐ์ง๋๋ก ํ์ต๋๋ค.
์ต์ข ์ฝ๋๋ ์๋์ ๊ฐ์ต๋๋ค.
showModalBottomSheet<void>(
isScrollControlled: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
builder: (context) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
margin: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text("์ง์ญ๋ช
๋ง ๊ฐ๋จํ๊ฒ ์
๋ ฅํด์ฃผ์ธ์.\n'ํ๊ต๋'์ ๋ฑ๋กํ๊ณ ์ถ๋ค๋ฉด 'ํ๊ต'๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."),
const SizedBox(height: 8),
const TextField(
decoration: InputDecoration(
hintText: "๊ด์ฌ ์ง์ญ์ ์
๋ ฅํด์ฃผ์ธ์.",
),
),
const SizedBox(height: 16),
InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
height: 50,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.blue,
),
child: const Text(
"์
๋ ฅ ์๋ฃ",
style:
TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
],
),
);
});
์ด๋ก์จ ModalBottomSheet๊ฐ ํค๋ณด๋์ ๊ฐ๋ ค์ง๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. ํค๋ณด๋์ ์ํด ๋ค๋ฅธ UI๊ฐ ๊ฐ๋ ค์ง๋ ํ์์ ๊ฐ๋ฐ์ ์งํํจ์ ์์ด์ ์์ฃผ ์ ํ๊ฒ ๋ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
'๐ป ๊ฐ๋ฐ > Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Flutter / Dart] What is Equatable? (0) | 2022.08.06 |
---|---|
[Flutter] BLoC ํจํด์ผ๋ก ์๋ ๋ก๊ทธ์ธ, Splash Screen ๊ตฌํํ๊ธฐ - 1 (0) | 2022.07.26 |
[Flutter / Dart] What is Singleton? (0) | 2022.07.21 |
[Flutter] SingleChildScrollView, ListView, ListView.bulider (1) | 2021.08.18 |
4. Column, Row, Expanded (0) | 2021.08.18 |