diff --git a/lib/provider/filterlist_provider.dart b/lib/provider/filterlist_provider.dart index 3eba1f3..50007b7 100644 --- a/lib/provider/filterlist_provider.dart +++ b/lib/provider/filterlist_provider.dart @@ -11,13 +11,16 @@ class FilterList extends ChangeNotifier{ int index = _filterList.indexWhere((filter) => filter.containsKey(filterKey)); // print(filterKey); - - if (index != -1) { + if(filterVal == -1){ + _filterList.removeAt(index); + _filterList.insert(index,{filterKey: false}); + } + else{ _filterList.removeAt(index); _filterList.insert(index,{filterKey: _filterItem[index][filterVal]}); // print(_filterItem[index][filterVal]); - notifyListeners(); // 상태 변경 알림 } + notifyListeners(); // 상태 변경 알림 } } diff --git a/lib/screens/home/map/map_screen.dart b/lib/screens/home/map/map_screen.dart index b5307e1..9500028 100644 --- a/lib/screens/home/map/map_screen.dart +++ b/lib/screens/home/map/map_screen.dart @@ -54,6 +54,24 @@ class _MapScreenState extends State } } + // 필터 눌렸는지 여부 + final List isPressedFilter = List.generate(12, (index) => false); + // 필터 색깔 지정 + Color _colors = Colors.white; + + Color changeColor(bool _state, int index){ + if(_state){ + // print(_state); + _colors = Colors.red; + return _colors; + } + else{ + // print(_state); + _colors = Colors.white; + return _colors; + } + } + bool smokingAreaSelected = false; BottomDrawerController bottomDrawerController = BottomDrawerController(); String smokingAreaId = ''; @@ -78,8 +96,6 @@ class _MapScreenState extends State Provider.of(context, listen: true).filterList; // 필터 버튼 상태 final List> filtersItem = Provider.of(context, listen: false).filterItem; - final List _isPressedFilter = List.generate(12, (index) => false); - // commit test 3 return Scaffold( body: Stack( @@ -188,27 +204,32 @@ class _MapScreenState extends State width: searchWidth, child: ListView.builder( scrollDirection: Axis.horizontal, - itemCount: _isPressedFilter.length, // 필터의 개수만큼 아이템 생성 + itemCount: isPressedFilter.length, // 필터의 개수만큼 아이템 생성 itemBuilder: (context, index) { return ElevatedButton( - style: ButtonStyle(backgroundColor: - MaterialStateProperty.resolveWith( - (states) { - if (_isPressedFilter[index]) { - return Colors.red; - } - return Colors.white; - })), onPressed: () { - print(_isPressedFilter[index]); - _isPressedFilter[index] = !_isPressedFilter[index]; - Provider.of(context, listen: false) + setState(() { + isPressedFilter[index] = !isPressedFilter[index]; + changeColor(isPressedFilter[index], index); + }); + if (isPressedFilter[index]){ + Provider.of(context, listen: false) .changeFilterList( filters[index ~/ 2].keys.first, - index % 2); - print(_isPressedFilter[index]); + index % 2); + } + else{ + Provider.of(context, listen: false) + .changeFilterList( + filters[index ~/ 2].keys.first, + -1); + } // print(filters[index~/2].values.first); + // print(filters); }, + style: ElevatedButton.styleFrom( + backgroundColor: _colors = changeColor(isPressedFilter[index], index) + ), child: Text(filtersItem[index ~/ 2][index % 2]), ); }, @@ -355,4 +376,4 @@ class _MapScreenState extends State onCameraChangeStreamSubscription = null; super.dispose(); } -} +} \ No newline at end of file