728x90
๋ฐ์ํ
Demo
ํธ์งํ๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ฆฌ์คํธ ์์ ์ฒดํฌ๋ฐ์ค๊ฐ ๋ํ๋๋ฉด์ ๋ฐ๋ก ์ ํํ ์ ์๊ฒ ๋ ์ด์์์ ๊ตฌํํด์ผํ๋ค.
๋ ์ด์์ ๊ตฌ์ฑ
- 'ํธ์งํ๊ธฐ' ์ '์ญ์ ํ๊ธฐ' ๋ฒํผ์ boolean ๊ฐ์ผ๋ก ๊ตฌ๋ถํด์ ๋ง๋ค๊ธฐ
- Listview๋ก checkbox์ text๋ฅผ ํ ์ค๋ก ๋ฃ์ด์ ๋ง๋ค์ด์ค๋ค
- boolean๊ฐ์ผ๋ก checkbox๊ฐ ๋์ฌ๋์ ์ ๋์ฌ ๋๋ฅผ ๊ตฌ๋ถํ๋ค
๋ฐ๋ณต๋์ ๋ค์ด๊ฐ checkboxmodal widget์ ๋ง๋ค์ด์ค๋๋ค
Listview ์์ ๋ค์ด๊ฐ checkboxmodal์ ๋ง๋ค์ด์ค๋๋ค. title๊ณผ time์ ํ์๋ผ์ required๋ฅผ ๋ถ์ฌ์ค๋๋ค.
class CheckBoxModal {
String title;
bool value;
String time;
String purpose;
CheckBoxModal(
{required this.title,
this.value = false,
required this.time,
required this.purpose});
}
_isChecked์ _isEdit๋ ํธ์งํ๊ธฐ / ์ญ์ ํ๊ธฐ ๋ฒํผ ๊ตฌ๋ถ๊ณผ ๋ฉํฐ ์ ํ์ ์ํ boolean๊ฐ์ ๋ํ๋ ๋๋ค
checkBoxList๋ฅผ map์ผ๋ก ๋๋ฆด ์ ์๊ฒ ๊ทธ ์์ ํ์ํ checkboxmodal์ ๋ฃ์ด์ค๋๋ค
class _myNotificationState extends State<myNotification> {
bool _isChecked = false;
bool _isEdit = false;
final allChecked =
CheckBoxModal(title: 'all Checked', time: '11:00', purpose: 'chat');
final checkBoxList = [
CheckBoxModal(
title: '์งฑ๊ตฌ ๋์๊ฒ ์น๊ตฌ ์ ์ฒญ์ด ์์ต๋๋ค', time: '12:30', purpose: 'help'),
CheckBoxModal(
title: '์ฝ๋ ๋์ผ๋ก ๋ถํฐ ๋ํ ์ ์ฒญ์ด ์์ต๋๋ค', time: '12:30', purpose: 'chat'),
CheckBoxModal(
title: '๋จ๋์ผ ๋์ผ๋ก ๋ถํฐ ๋์ ์ ์ฒญ์ด ์์ต๋๋ค', time: '12:30', purpose: 'help'),
];
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
margin: EdgeInsets.only(top: 20),
child: Column(
children: [
........
Column(
children: [
//ํธ์งํ๊ธฐ,์ญ์ ํ๊ธฐ ๋ฒํผ
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 80.0,
height: 24.0,
margin: EdgeInsets.only(left: 16, right: 16),
child: ElevatedButton(
child: Text(
_isEdit ? "์ญ์ ํ๊ธฐ" : "ํธ์งํ๊ธฐ",
style: TextStyle(fontSize: 12),
),
onPressed: () {
setState(() {
if (!_isEdit) {
_isEdit = true;
} else {
_isEdit = false;
}
});
},
style: ElevatedButton.styleFrom(
primary: Colors.purple,
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
).copyWith(
elevation: ButtonStyleButton.allOrNull(0.0)),
),
),
],
),
ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
Divider(),
...checkBoxList
.map(
(item) => ListTile(
title: SizedBox(
child: Column(
children: [
Row(
//mainAxisAlignment: MainAxisAlignment.start,
children: [
_isEdit
? SizedBox(
width: 30,
height: 20,
child: Transform.scale(
scale: 0.7,
child: Checkbox(
value: item.value,
onChanged: (value) {
onAllClicked(item);
},
activeColor: Colors.purple,
),
),
)
: SizedBox(width: 0),
SizedBox(
width: _isEdit
? MediaQuery.of(context)
.size
.width -
130
: MediaQuery.of(context)
.size
.width -
110,
child: Text(item.title,
textAlign: TextAlign.left,
style: TextStyle(
color: Color(0xff47505F),
fontSize: 12,
fontWeight: FontWeight.w700,
)),
),
if (!_isEdit)
Container(
child: Text(
item.time,
style: TextStyle(fontSize: 14),
),
),
],
),
SizedBox(height: 5),
Divider(),
],
),
)),
)
.toList(),
],
),
],
),
],
),
),
],
);
}
onAllClicked(CheckBoxModal ckbItem) {
setState(() {
ckbItem.value = !ckbItem.value;
});
}
}
728x90
'๊ฐ๋ฐ > Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ฌํฐ] ๋ผ์ฐํ ์์ GetX controller ์์ ๊ธฐ (0) | 2022.10.10 |
---|---|
[ํ๋ฌํฐ] Listview ์ ์๊ธฐ๋ ๊ณต๋ฐฑ (0) | 2022.08.15 |
[ํ๋ฌํฐ/firebase] signup ๊ธฐ๋ฅ ๊ตฌํํ๊ธฐ (0) | 2022.06.21 |
[Flutter] ์๋ก์ด ํ๋ฉด์ผ๋ก ์ด๋ํ๊ณ , ๋๋์๊ฐ๊ธฐ - ํ์ด์ง ์ด๋ (0) | 2022.05.16 |
[Flutter] ListView.builder๋ก ๋ฐ๋ณต๋๋ ๋ถ๋ถ ๋ง๋ค๊ธฐ (0) | 2022.04.17 |