diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 0000000..7e7e7f6 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1 @@ +extensions: diff --git a/lib/main.dart b/lib/main.dart index 329fa32..491f511 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; @@ -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 _initializeMap() async { WidgetsFlutterBinding.ensureInitialized(); @@ -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( diff --git a/lib/provider/filterlist_provider.dart b/lib/provider/filterlist_provider.dart new file mode 100644 index 0000000..39d4c9f --- /dev/null +++ b/lib/provider/filterlist_provider.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; + +class FilterList extends ChangeNotifier{ + List > _filterList = [{'개방여부': false},{'실내여부':false},{'환풍여부':false},{'청결함여부':false},{'크기':false},{'혼잡도':false}]; + List > _filterItem = [['개방형', '폐쇄형'], ['실내', '실외'], ['환풍 o', '환풍 x'], ['청결함', '더러움'], ['대형', '소형'], ['혼잡함', '한적함']]; + + List > 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(); // 상태 변경 알림 + } + } + +} diff --git a/lib/screens/home/filter/filter_screen.dart b/lib/screens/home/filter/filter_screen.dart index a86cb73..3871ffa 100644 --- a/lib/screens/home/filter/filter_screen.dart +++ b/lib/screens/home/filter/filter_screen.dart @@ -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 inout = [ Text('실내'), @@ -24,6 +23,17 @@ const List ox = [ Text('X'), ]; +const List bigsmall = [ + Text('크다'), + Text('작다'), +]; + +const List density = [ + Text('혼잡'), + Text('한산'), +]; + + class FilterScreen extends StatefulWidget { const FilterScreen({ super.key, @@ -38,10 +48,13 @@ class _FilterScreenState extends State { final List _selectedOpenClose = [false, false]; final List _selectedVentilation = [false, false]; final List _selectedCleanliness = [false, false]; - final List _toggleIsSelected = [false, false, false, false]; - + final List _selectedBigSmall = [false, false]; + final List _selectedDenisty = [false, false]; + final List _toggleIsSelected = [false, false, false, false, false, false]; bool activateInformBtn = false; + final List > _isSelectedFilter = List.generate(6, (index) => List.generate(2, (index) => false)); + @override Widget build(BuildContext context) { // 화면을 동적으로 빌드하기 위한 사이즈 @@ -67,10 +80,12 @@ class _FilterScreenState extends State { 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), ], ) , ), @@ -79,7 +94,20 @@ class _FilterScreenState extends State { fit: FlexFit.tight, child: InkWell( onTap: () { - // activateInformBtn ? null : null; + List> filters = Provider.of(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(context, listen: false).changeFilterList(type, 0); + } + else{ + Provider.of(context, listen: false).changeFilterList(type, 1); + } + } + } + + context.pop('/filter'); }, child: Ink( decoration: BoxDecoration( @@ -104,9 +132,7 @@ class _FilterScreenState extends State { ), ], ), - ), - - + ), ); } @@ -149,12 +175,12 @@ class _FilterScreenState extends State { // 설정하기 버튼 활성화여부를 판단하는 함수 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; } } diff --git a/lib/screens/home/map/map_screen.dart b/lib/screens/home/map/map_screen.dart index 866cacf..6773830 100644 --- a/lib/screens/home/map/map_screen.dart +++ b/lib/screens/home/map/map_screen.dart @@ -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}); @@ -68,6 +72,11 @@ class _MapScreenState extends State // NaverMapController 객체의 비동기 작업 완료를 나타내는 Completer 생성 final Completer mapControllerCompleter = Completer(); + + // 필터 목록을 구독 + final List> filters = Provider.of(context, listen: true).filterList; + // 필터 버튼 상태 + final List _isPressedFilter = List.generate(12, (index) => false); return Scaffold( body: Stack( @@ -144,65 +153,24 @@ class _MapScreenState extends State Container( height: 50, width: 350, - child: ListView( + child: ListView.builder( scrollDirection: Axis.horizontal, - children: [ - 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]; // 상태 토글 + }); + }, + ); + }, + ), ), - ), ], ), @@ -227,6 +195,7 @@ class _MapScreenState extends State // 필터 설정 화면 setState(() { context.push('/filter'); + }); }, child: Icon( diff --git a/lib/screens/login/login_screen.dart b/lib/screens/login/login_screen.dart index e4a0910..c06f10e 100644 --- a/lib/screens/login/login_screen.dart +++ b/lib/screens/login/login_screen.dart @@ -53,12 +53,17 @@ class _LoginScreenState extends State { 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(); } @@ -125,7 +130,7 @@ class _LoginScreenState extends State { return Scaffold( body: Container( width: double.infinity, - height: double.infinity, + height: double.infinity, color: Colors.white, child: Column( crossAxisAlignment: CrossAxisAlignment.center, diff --git a/pubspec.yaml b/pubspec.yaml index 1ea1494..da32950 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: