Skip to content

Commit

Permalink
Merge pull request #30 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 27, 2024
2 parents 46cf69d + 2c1ce11 commit 5943c29
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 82 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
10 changes: 9 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:damyo/provider/filterlist_provider.dart';
import 'package:damyo/screens/home/inform/inform_screen.dart';
import 'package:damyo/screens/home/filter/filter_screen.dart';
import 'package:damyo/screens/login/login_screen.dart';
Expand All @@ -13,6 +14,8 @@ import 'package:go_router/go_router.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';

import 'package:provider/provider.dart';

// 지도 초기화
Future<void> _initializeMap() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -94,7 +97,12 @@ void main() async {
// await _getCurrentLocation();
// Kakao sdk 초기화
_initializeKakao();
runApp(const App());
runApp(
ChangeNotifierProvider(
create: (context) => FilterList(),
child: const App(),
)
);
}

final GoRouter router = GoRouter(
Expand Down
21 changes: 21 additions & 0 deletions lib/provider/filterlist_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +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> > get filterList => _filterList;

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

// print(index);

if (index != -1) {
_filterList.removeAt(index);
_filterList.insert(index,{filterKey: _filterItem[index][filterVal]});
notifyListeners(); // 상태 변경 알림
}
}

}
64 changes: 45 additions & 19 deletions lib/screens/home/filter/filter_screen.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:io';

import 'package:damyo/http.dart';
import 'package:damyo/main.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_rating_stars/flutter_rating_stars.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
import 'package:damyo/provider/filterlist_provider.dart';
import 'package:http/http.dart';
import 'package:provider/provider.dart';



const List<Widget> inout = <Widget>[
Text('실내'),
Expand All @@ -24,6 +23,17 @@ const List<Widget> ox = <Widget>[
Text('X'),
];

const List<Widget> bigsmall = <Widget>[
Text('크다'),
Text('작다'),
];

const List<Widget> density = <Widget>[
Text('혼잡'),
Text('한산'),
];


class FilterScreen extends StatefulWidget {
const FilterScreen({
super.key,
Expand All @@ -38,10 +48,13 @@ class _FilterScreenState extends State<FilterScreen> {
final List<bool> _selectedOpenClose = <bool>[false, false];
final List<bool> _selectedVentilation = <bool>[false, false];
final List<bool> _selectedCleanliness = <bool>[false, false];
final List<bool> _toggleIsSelected = <bool>[false, false, false, false];

final List<bool> _selectedBigSmall = <bool>[false, false];
final List<bool> _selectedDenisty = <bool>[false, false];
final List<bool> _toggleIsSelected = <bool>[false, false, false, false, false, false];
bool activateInformBtn = false;

final List<List<bool> > _isSelectedFilter = List.generate(6, (index) => List.generate(2, (index) => false));

@override
Widget build(BuildContext context) {
// 화면을 동적으로 빌드하기 위한 사이즈
Expand All @@ -67,10 +80,12 @@ class _FilterScreenState extends State<FilterScreen> {
fit: FlexFit.tight,
child: Column(
children: [
informToggle('실내 여부', inout, _selectedInOut, 0),
informToggle('개방 여부', openclose, _selectedOpenClose, 1),
informToggle('환풍 여부', ox, _selectedVentilation, 2),
informToggle('청결도', ox, _selectedCleanliness, 3),
informToggle('개방여부', openclose, _isSelectedFilter[0], 0),
informToggle('실내여부', inout, _isSelectedFilter[1], 1),
informToggle('환풍여부', ox, _isSelectedFilter[2], 2),
informToggle('청결함여부', ox, _isSelectedFilter[3], 3),
informToggle('크기', bigsmall, _isSelectedFilter[4], 4),
informToggle('혼잡도', density, _isSelectedFilter[5], 5),
],
) ,
),
Expand All @@ -79,7 +94,20 @@ class _FilterScreenState extends State<FilterScreen> {
fit: FlexFit.tight,
child: InkWell(
onTap: () {
// activateInformBtn ? null : null;
List<Map<String, dynamic>> filters = Provider.of<FilterList>(context, listen: false).filterList;
for (int i = 0; i < _toggleIsSelected.length; i++){
if(_toggleIsSelected[i]){
String type = filters[i].keys.first;
if(_isSelectedFilter[i][0]){
Provider.of<FilterList>(context, listen: false).changeFilterList(type, 0);
}
else{
Provider.of<FilterList>(context, listen: false).changeFilterList(type, 1);
}
}
}

context.pop('/filter');
},
child: Ink(
decoration: BoxDecoration(
Expand All @@ -104,9 +132,7 @@ class _FilterScreenState extends State<FilterScreen> {
),
],
),
),


),
);
}

Expand Down Expand Up @@ -149,12 +175,12 @@ class _FilterScreenState extends State<FilterScreen> {
// 설정하기 버튼 활성화여부를 판단하는 함수
void checkCanInform() {
for (int i = 0; i < _toggleIsSelected.length; i++) {
if (!_toggleIsSelected[i]) {
activateInformBtn = false;
if (_toggleIsSelected[i]) {
activateInformBtn = true;
return;
}
}
activateInformBtn = true;
activateInformBtn = false;
}
}

Expand Down
83 changes: 26 additions & 57 deletions lib/screens/home/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_naver_map/flutter_naver_map.dart';
import 'package:go_router/go_router.dart';

import 'package:provider/provider.dart';
import 'package:damyo/provider/filterlist_provider.dart';
import 'package:damyo/screens/home/filter/filter_screen.dart';

class MapScreen extends StatefulWidget {
const MapScreen({super.key});

Expand Down Expand Up @@ -68,6 +72,11 @@ class _MapScreenState extends State<MapScreen>

// NaverMapController 객체의 비동기 작업 완료를 나타내는 Completer 생성
final Completer<NaverMapController> mapControllerCompleter = Completer();

// 필터 목록을 구독
final List<Map<String, dynamic>> filters = Provider.of<FilterList>(context, listen: true).filterList;
// 필터 버튼 상태
final List<bool> _isPressedFilter = List.generate(12, (index) => false);

return Scaffold(
body: Stack(
Expand Down Expand Up @@ -144,65 +153,24 @@ class _MapScreenState extends State<MapScreen>
Container(
height: 50,
width: 350,
child: ListView(
child: ListView.builder(
scrollDirection: Axis.horizontal,
children: <Widget>[
OutlinedButton(
child:Text('a'),
onPressed:(){
print('a');
} ,
),
OutlinedButton(
child: Text('b'),
onPressed:(){
print('b');
} ,
),
OutlinedButton(
child: Text('c'),
onPressed:(){
print('c');
} ,
),
OutlinedButton(
child: Text('d'),
onPressed:(){
print('d');
} ,
),OutlinedButton(
child: Text('e'),
onPressed:(){
print('e');
} ,
),
OutlinedButton(
child: Text('f'),
onPressed:(){
print('f');
} ,
),
OutlinedButton(
child: Text('g'),
onPressed:(){
print('g');
} ,
),
OutlinedButton(
child: Text('h'),
onPressed:(){
print('h');
} ,
),
OutlinedButton(
child: Text('i'),
onPressed:(){
print('i');
} ,
),
],
itemCount: _isPressedFilter.length, // 필터의 개수만큼 아이템 생성
itemBuilder: (context, index) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: _isPressedFilter[index] ? Colors.red : Colors.white,
),
child: Text('Filter $index'), // 각 버튼에 대한 텍스트
onPressed: () {
setState(() {
_isPressedFilter[index] = !_isPressedFilter[index]; // 상태 토글
});
},
);
},
),
),
),
],
),

Expand All @@ -227,6 +195,7 @@ class _MapScreenState extends State<MapScreen>
// 필터 설정 화면
setState(() {
context.push('/filter');

});
},
child: Icon(
Expand Down
13 changes: 9 additions & 4 deletions lib/screens/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ class _LoginScreenState extends State<LoginScreen> {
NaverAccessToken naverToken = await FlutterNaverLogin.currentAccessToken;

// print(naverUser.accessToken);
print('name = ${naverUser.account.name}');
print('email = ${naverUser.account.email}');
print('id = ${naverUser.account.id}');
if(naverUser != null){
print('name = ${naverUser.account.name}');
print('email = ${naverUser.account.email}');
print('id = ${naverUser.account.id}');
await storage.write(key: 'userID', value: naverUser.account.email);
await storage.write(key: 'sns', value: "naver");
}
setState(() {});
}


void signOutWithNaver() async {
FlutterNaverLogin.logOut();
}
Expand Down Expand Up @@ -125,7 +130,7 @@ class _LoginScreenState extends State<LoginScreen> {
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
height: double.infinity,
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies:
flutter_secure_storage: ^4.2.1
balloon_widget: ^0.0.1+1
bottom_drawer: ^0.0.5
flutter_provider: ^2.1.0
provider: ^6.1.2


dev_dependencies:
Expand Down

0 comments on commit 5943c29

Please sign in to comment.