-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Jeon-jisu/search_page
Search_page link to detail_page
- Loading branch information
Showing
8 changed files
with
288 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.