From 6976a9b66397bc5ba8881dd62b98c3b3fc2215ab Mon Sep 17 00:00:00 2001 From: boroboro01 Date: Wed, 16 Oct 2024 21:34:58 +0900 Subject: [PATCH] feat: add restriction to checking term --- lib/screens/selling/term_screen.dart | 47 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/lib/screens/selling/term_screen.dart b/lib/screens/selling/term_screen.dart index e8f97e3..3ad830f 100644 --- a/lib/screens/selling/term_screen.dart +++ b/lib/screens/selling/term_screen.dart @@ -12,6 +12,16 @@ class TermScreen extends StatefulWidget { } class _TermScreenState extends State { + final List _terms = [false, false, false, false]; + + bool get _allTermsAccepted => _terms.every((element) => element); + + void _updateTermState(int index, bool value) { + setState(() { + _terms[index] = value; + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -41,34 +51,42 @@ class _TermScreenState extends State { ), ), ), - const Term( + Term( content: '사용자는 판매하려는 제품에 대한 정확하고 정직한 정보를 제공해야 합니다.', initial: false, + onChanged: (value) => _updateTermState(0, value), ), - const Term( + Term( content: '사진에 타인의 얼굴이나 개인정보가 포함되지 않도록 주의해야 합니다.', initial: false, + onChanged: (value) => _updateTermState(1, value), ), - const Term( + Term( content: '금지된 품목을 사진에 포함하거나 게시하는 것은 엄격히 금지됩니다.', initial: false, + onChanged: (value) => _updateTermState(2, value), ), - const Term( + Term( content: '사진은 선명하고 제품의 상태를 명확히 보여줄 수 있어야 합니다. 흐리거나 제품의 상태를 왜곡하는 사진은 삭제될 수 있습니다.', initial: false, + onChanged: (value) => _updateTermState(3, value), ), const SizedBox(height: 100.0), Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: NormalButton( title: '확인했어요', - bgColor: black, + bgColor: _allTermsAccepted ? black : gray400, txtColor: white, onTap: () { - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => const ProcessScreen(), - )); + _allTermsAccepted + ? { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => const ProcessScreen(), + )) + } + : null; }, flag: true, ), @@ -89,10 +107,12 @@ class Term extends StatefulWidget { super.key, required this.content, required this.initial, + required this.onChanged, }); final String content; final bool initial; + final ValueChanged onChanged; @override State createState() => _TermState(); @@ -128,10 +148,13 @@ class _TermState extends State { ), Checkbox( value: approve, - onChanged: (value) { - setState(() { - approve = value!; - }); + onChanged: (bool? value) { + if (value != null) { + setState(() { + approve = value; + }); + widget.onChanged(value); + } }, ), ],