Skip to content

Commit

Permalink
Merge pull request #48 from Alpha-Damyo/Feature/#26-FilterScreen
Browse files Browse the repository at this point in the history
Feature/#26 filter screen
  • Loading branch information
choichangyeon authored Mar 30, 2024
2 parents e0b63d7 + 7ee6a87 commit 7e3f208
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
9 changes: 6 additions & 3 deletions lib/provider/filterlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(); // 상태 변경 알림
}

}
55 changes: 38 additions & 17 deletions lib/screens/home/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ class _MapScreenState extends State<MapScreen>
}
}

// 필터 눌렸는지 여부
final List<bool> 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 = '';
Expand All @@ -78,8 +96,6 @@ class _MapScreenState extends State<MapScreen>
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);
// commit test 3

return Scaffold(
body: Stack(
Expand Down Expand Up @@ -188,27 +204,32 @@ class _MapScreenState extends State<MapScreen>
width: searchWidth,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _isPressedFilter.length, // 필터의 개수만큼 아이템 생성
itemCount: isPressedFilter.length, // 필터의 개수만큼 아이템 생성
itemBuilder: (context, index) {
return ElevatedButton(
style: ButtonStyle(backgroundColor:
MaterialStateProperty.resolveWith<Color>(
(states) {
if (_isPressedFilter[index]) {
return Colors.red;
}
return Colors.white;
})),
onPressed: () {
print(_isPressedFilter[index]);
_isPressedFilter[index] = !_isPressedFilter[index];
Provider.of<FilterList>(context, listen: false)
setState(() {
isPressedFilter[index] = !isPressedFilter[index];
changeColor(isPressedFilter[index], index);
});
if (isPressedFilter[index]){
Provider.of<FilterList>(context, listen: false)
.changeFilterList(
filters[index ~/ 2].keys.first,
index % 2);
print(_isPressedFilter[index]);
index % 2);
}
else{
Provider.of<FilterList>(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]),
);
},
Expand Down Expand Up @@ -355,4 +376,4 @@ class _MapScreenState extends State<MapScreen>
onCameraChangeStreamSubscription = null;
super.dispose();
}
}
}

0 comments on commit 7e3f208

Please sign in to comment.