Skip to content

Commit

Permalink
Merge pull request #37 from Alpha-Damyo/Feature/#26-FilterScreen
Browse files Browse the repository at this point in the history
#26 state update
  • Loading branch information
choichangyeon authored Mar 27, 2024
2 parents 8a70a67 + 5a15a44 commit f769516
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/provider/filterlist_provider.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import 'package:flutter/material.dart';

class FilterList extends ChangeNotifier{
List<Map<String, dynamic> > _filterList = [{'개방여부': false},{'실내여부':false},{'환풍여부':false},{'청결함여부':false},{'크기':false},{'혼잡도':false}];
List<List<String> > _filterItem = [['개방형', '폐쇄형'], ['실내', '실외'], ['환풍 o', '환풍 x'], ['청결함', '더러움'], ['대형', '소형'], ['혼잡함', '한적함']];
List<Map<String, dynamic>> _filterList = [{'개방여부': false},{'실내여부':false},{'환풍여부':false},{'청결함여부':false},{'크기':false},{'혼잡도':false}];
List<List<String>> _filterItem = [['개방형', '폐쇄형'], ['실내', '실외'], ['환풍 o', '환풍 x'], ['청결함', '더러움'], ['대형', '소형'], ['혼잡함', '한적함']];

List<Map<String, dynamic> > get filterList => _filterList;
List<Map<String, dynamic>> get filterList => _filterList;
List<List<String>> get filterItem => _filterItem;

void changeFilterList(String filterKey, int filterVal){
int index = _filterList.indexWhere((filter) => filter.containsKey(filterKey));

// print(index);
// print(filterKey);

if (index != -1) {
_filterList.removeAt(index);
_filterList.insert(index,{filterKey: _filterItem[index][filterVal]});
// print(_filterItem[index][filterVal]);
notifyListeners(); // 상태 변경 알림
}
}
Expand Down
22 changes: 15 additions & 7 deletions lib/screens/home/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class _MapScreenState extends State<MapScreen>
// 필터 목록을 구독
final List<Map<String, dynamic>> filters = Provider.of<FilterList>(context, listen: true).filterList;
// 필터 버튼 상태
final List<List<String>> filtersItem = Provider.of<FilterList>(context, listen: false).filterItem;
final List<bool> _isPressedFilter = List.generate(12, (index) => false);

return Scaffold(
Expand Down Expand Up @@ -158,15 +159,22 @@ class _MapScreenState extends State<MapScreen>
itemCount: _isPressedFilter.length, // 필터의 개수만큼 아이템 생성
itemBuilder: (context, index) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: _isPressedFilter[index] ? Colors.red : Colors.white,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>((states){
if(_isPressedFilter[index]){
return Colors.red;
}
return Colors.white;
})
),
child: Text('Filter $index'), // 각 버튼에 대한 텍스트
onPressed: () {
setState(() {
_isPressedFilter[index] = !_isPressedFilter[index]; // 상태 토글
});
onPressed: (){
print(_isPressedFilter[index]);
_isPressedFilter[index] = !_isPressedFilter[index];
Provider.of<FilterList>(context, listen: false).changeFilterList(filters[index~/2].keys.first, index%2);
print(_isPressedFilter[index]);
// print(filters[index~/2].values.first);
},
child: Text(filtersItem[index~/2][index%2]),
);
},
),
Expand Down

0 comments on commit f769516

Please sign in to comment.