Skip to content

Commit

Permalink
Merge pull request #33 from Jeon-jisu/search_page
Browse files Browse the repository at this point in the history
Search_page link to detail_page
  • Loading branch information
Pjunn authored Sep 28, 2022
2 parents d149459 + 89ae976 commit 67dca0e
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 56 deletions.
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=/Users/jisu/Library/Android/sdk
flutter.sdk=/Users/jisu/flutter
sdk.dir=/Users/parkjunseo/Library/Android/sdk
flutter.sdk=/Users/parkjunseo/Developer/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
Expand Down
3 changes: 1 addition & 2 deletions lib/page/detail_page/detailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import 'package:cafegation/models/cafe.dart';

class detailPage extends StatefulWidget {
const detailPage(
{Key? key, required this.cafeName, required this.likedStatus})
{Key? key, required this.cafeName})
: super(key: key);

final String cafeName;
final bool likedStatus;
@override
_detailPageState createState() => _detailPageState();
}
Expand Down
1 change: 0 additions & 1 deletion lib/page/favorites_page/favorite_cafe_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class _FavoriteCafeItemState extends State<FavoriteCafeItem> {
MaterialPageRoute(
builder: (context) => detailPage(
cafeName: widget.cafe.id,
likedStatus: true,
)),
);
},
Expand Down
1 change: 0 additions & 1 deletion lib/page/list_page/CafeItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class _CafeItemState extends State<CafeItem> {
MaterialPageRoute(
builder: (context) => detailPage(
cafeName: widget.cafe.id,
likedStatus: state,
)),
);
},
Expand Down
50 changes: 38 additions & 12 deletions lib/page/search_page/searchPage.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cafegation/constants/colors.dart';
import 'package:cafegation/page/favorites_page/favoritesPage.dart';
import 'package:cafegation/page/map_page/mapPage.dart';
import 'package:cafegation/page/search_page/search_screen.dart';
import 'package:cafegation/page/search_page/searchbar.dart';
import 'package:cafegation/page/tag_page/tagPage.dart';
import 'package:flutter/material.dart';
Expand All @@ -24,7 +25,7 @@ class _searchPageState extends State<searchPage> {
appBar: AppBar(
backgroundColor: Colors.blue[200],
shadowColor: Colors.blue[300],
title: Text('Search Page'),
title: Text('Main Page'),
automaticallyImplyLeading: false,
leading: const SizedBox(
width: 100,
Expand All @@ -46,7 +47,7 @@ class _searchPageState extends State<searchPage> {
child: Column(
children: <Widget>[
SearchBar(),
SizedBox(height: 30),
SizedBox(height: 1),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.09,
Expand All @@ -58,7 +59,10 @@ class _searchPageState extends State<searchPage> {
primary: Color(0xFF2C2E43),
onPrimary: Colors.black),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => KakaoMapTest()));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => KakaoMapTest()));
// _openKakaoMapScreen(context);
},
child: Row(children: <Widget>[
Expand All @@ -71,7 +75,11 @@ class _searchPageState extends State<searchPage> {
),
Text(
'내 주변 카페 찾기',
style: TextStyle(color: Colors.white, fontSize: 23.0, letterSpacing: 5.0, fontWeight: FontWeight.normal),
style: TextStyle(
color: Colors.white,
fontSize: 23.0,
letterSpacing: 5.0,
fontWeight: FontWeight.normal),
),
]),
),
Expand All @@ -88,7 +96,10 @@ class _searchPageState extends State<searchPage> {
primary: Color(0xFF2C2E43),
onPrimary: Colors.black),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => tagPage()));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => tagPage()));
},
child: Row(children: <Widget>[
Icon(
Expand All @@ -100,7 +111,11 @@ class _searchPageState extends State<searchPage> {
),
Text(
'카테고리별 카페 찾기',
style: TextStyle(color: Colors.white, fontSize: 23.0, letterSpacing: 5.0, fontWeight: FontWeight.normal),
style: TextStyle(
color: Colors.white,
fontSize: 23.0,
letterSpacing: 5.0,
fontWeight: FontWeight.normal),
),
]),
),
Expand All @@ -117,7 +132,10 @@ class _searchPageState extends State<searchPage> {
primary: Color(0xFF2C2E43),
onPrimary: Colors.black),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => favoritesPage()));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => favoritesPage()));
},
child: Row(children: <Widget>[
Icon(
Expand All @@ -129,7 +147,11 @@ class _searchPageState extends State<searchPage> {
),
Text(
'즐겨찾는 카페 찾기',
style: TextStyle(color: Colors.white, fontSize: 23.0, letterSpacing: 5.0, fontWeight: FontWeight.normal),
style: TextStyle(
color: Colors.white,
fontSize: 23.0,
letterSpacing: 5.0,
fontWeight: FontWeight.normal),
),
]),
),
Expand All @@ -152,14 +174,17 @@ Future<void> _openKakaoMapScreen(BuildContext context) async {
// util.getKakaoMapURL(37.402056, 127.108212, name: 'Kakao 본사'));

/// This is short form of the above comment
String url = await util.getMapScreenURL(37.5515814, 126.9227864, name: '홍익대학교');
String url =
await util.getMapScreenURL(37.5515814, 126.9227864, name: '홍익대학교');

debugPrint('url : $url');

Navigator.push(context, MaterialPageRoute(builder: (_) => KakaoMapScreen(url: url)));
Navigator.push(
context, MaterialPageRoute(builder: (_) => KakaoMapScreen(url: url)));
}

Widget _testingCustomScript({required Size size, required BuildContext context}) {
Widget _testingCustomScript(
{required Size size, required BuildContext context}) {
return KakaoMapView(
width: size.width,
height: 400,
Expand Down Expand Up @@ -194,6 +219,7 @@ Widget _testingCustomScript({required Size size, required BuildContext context})
''',
onTapMarker: (message) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message.message)));
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message.message)));
});
}
162 changes: 162 additions & 0 deletions lib/page/search_page/search_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import 'package:cafegation/models/cafe.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:cafegation/page/detail_page/detailPage.dart';
import 'package:cafegation/services/database.dart';
import 'package:cafegation/page/list_page/CafeItem.dart';
import 'package:cafegation/services/auth.dart';

class SearchScreen extends StatefulWidget {
_SearchScreenState createState() => _SearchScreenState();
}

class _SearchScreenState extends State<SearchScreen> {
final TextEditingController _filter = TextEditingController();
FocusNode focusNode = FocusNode();
String _searchText = "";

_SearchScreenState() {
_filter.addListener(() {
setState(() {
_searchText = _filter.text;
});
});
}

Widget _buildBody(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('cae').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data!.docs);
},
);
}

Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
List<DocumentSnapshot> searchResults = [];
for (DocumentSnapshot d in snapshot) {
final cafe = DataBaseService.instance.cafeBuilder(d);
if (cafe.name.toString().contains(_searchText)) {
searchResults.add(d);
}
}
return Expanded(
child: GridView.count(
crossAxisCount: 3,
childAspectRatio: 1 / 1.5,
padding: EdgeInsets.all(3),
children: searchResults
.map((data) => _buildListItem(context, data))
.toList()),
);
}

Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final cafe = DataBaseService.instance.cafeBuilder(data);

return InkWell(
child: Image.network(cafe.images),
// onTap: () {
// Navigator.of(context).push(MaterialPageRoute<Null>(
// fullscreenDialog: true,
// builder: (BuildContext context) {
// return detailPage(cafe: cafe);
// }));
// },
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => detailPage(
cafeName: cafe.id,
)),
);
},
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(30),
),
Container(
color: Colors.black,
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
child: Row(
children: <Widget>[
Expanded(
flex: 6,
child: TextField(
focusNode: focusNode,
style: TextStyle(
fontSize: 15,
),
autofocus: true,
controller: _filter,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(
Icons.search,
color: Colors.black,
size: 20,
),
suffixIcon: focusNode.hasFocus
? IconButton(
icon: Icon(
Icons.cancel,
size: 20,
),
onPressed: () {
setState(() {
_filter.clear();
_searchText = "";
});
},
)
: Container(),
hintText: '검색',
labelStyle: TextStyle(color: Colors.white),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(10))),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(10))),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(10))),
),
),
),
focusNode.hasFocus
? Expanded(
child: TextButton(
child: Text('취소'),
onPressed: () {
setState(() {
_filter.clear();
_searchText = "";
focusNode.unfocus();
});
},
),
)
: Expanded(
flex: 0,
child: Container(),
)
],
),
),
_buildBody(context)
],
),
);
}
}
39 changes: 29 additions & 10 deletions lib/page/search_page/searchbar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cafegation/page/search_page/search_screen.dart';

class SearchBar extends StatelessWidget {
const SearchBar({
Expand All @@ -8,21 +9,39 @@ class SearchBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 20, horizontal: 10),
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 5),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.symmetric(vertical: 30, horizontal: 20),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 6),
decoration: BoxDecoration(
boxShadow: [BoxShadow(color: Colors.grey.withOpacity(0.5),
offset: Offset(0, 3))],
boxShadow: [
BoxShadow(color: Colors.grey.withOpacity(0.5), offset: Offset(0, 3))
],
color: Colors.white24,
borderRadius: BorderRadius.circular(20),
),
child: TextField(
decoration: InputDecoration(
hintText: "카페 검색하기",
border: InputBorder.none,
icon: Icon(Icons.search),
iconColor: Colors.black
// child: TextField(
// decoration: InputDecoration(
// hintText: "카페 검색하기",
// border: InputBorder.none,
// icon: Icon(Icons.search),
// iconColor: Colors.black
// ),
// ),
// child: Scaffold(body: TabBarView(children: <Widget> [SearchScreen(),]))
child: TextButton.icon(
label: Text(
'카페 검색하기',
style: TextStyle(fontSize: 19),
),
icon: Icon(Icons.search, size: 22),
style: TextButton.styleFrom(
primary: Colors.black54,
alignment: Alignment.centerLeft,
),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SearchScreen()));
},
),
);
}
Expand Down
Loading

0 comments on commit 67dca0e

Please sign in to comment.