-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aa36ba
commit 8f95fe5
Showing
6 changed files
with
150 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,144 @@ | ||
import 'package:flappy_search_bar/flappy_search_bar.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:gogrocy/core/enums/viewstate.dart'; | ||
import 'package:gogrocy/core/models/ProductsByCity.dart'; | ||
import 'package:gogrocy/core/services/navigation_service.dart'; | ||
import 'package:gogrocy/core/viewModels/search_view_model.dart'; | ||
import 'package:gogrocy/service_locator.dart'; | ||
import 'package:gogrocy/ui/views/base_view.dart'; | ||
import 'package:gogrocy/ui/views/category/product_list.dart'; | ||
import 'package:gogrocy/ui/views/home/category_list.dart'; | ||
import 'package:gogrocy/ui/views/home/grid_list.dart'; | ||
import 'package:simple_search_bar/simple_search_bar.dart'; | ||
import 'package:gogrocy/ui/shared/colors.dart' as colors; | ||
import 'package:gogrocy/ui/shared/constants.dart' as constants; | ||
|
||
class SearchView extends StatelessWidget { | ||
|
||
final AppBarController appBarController = AppBarController(); | ||
|
||
var focusNode = FocusNode(); | ||
final SearchBarController<Result> _searchBarController = | ||
SearchBarController(); | ||
final TextEditingController _textEditingController = | ||
new TextEditingController(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SafeArea(child: Scaffold( | ||
appBar: SearchAppBar( | ||
primary: Theme.of(context).primaryColor, | ||
appBarController: appBarController, | ||
// You could load the bar with search already active | ||
autoSelected: true, | ||
searchHint: "Pesquise aqui...", | ||
mainTextColor: Colors.white, | ||
onChange: (String value) { | ||
//Your function to filter list. It should interact with | ||
//the Stream that generate the final list | ||
}, | ||
//Will show when SEARCH MODE wasn't active | ||
mainAppBar: AppBar( | ||
title: Text("Yout Bar Title"), | ||
actions: <Widget>[ | ||
InkWell( | ||
child: Icon( | ||
Icons.search, | ||
), | ||
onTap: () { | ||
//This is where You change to SEARCH MODE. To hide, just | ||
//add FALSE as value on the stream | ||
appBarController.stream.add(true); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
)); | ||
return BaseView<SearchViewModel>( | ||
onModelReady: (model) { | ||
model.getAllProducts(""); | ||
}, | ||
builder: (context, model, child) { | ||
return SafeArea( | ||
child: Scaffold( | ||
resizeToAvoidBottomPadding: false, | ||
body: Stack( | ||
children: <Widget>[ | ||
(model.state == ViewState.Idle) | ||
? ((!model.isSearchNull) | ||
? (!model.searchResults.empty) | ||
? (Center( | ||
child: Column( | ||
children: <Widget>[ | ||
Container( | ||
height: constants.screenHeight * 0.13, | ||
), | ||
CategoryProductList( | ||
model.searchResults.result), | ||
], | ||
), | ||
)) | ||
: Center( | ||
child: (Column( | ||
children: <Widget>[ | ||
Container( | ||
height: 80, | ||
child: Image( | ||
image: AssetImage( | ||
'assets/images/no_products.png'), | ||
)), | ||
Text( | ||
"We don't have that product right now", | ||
style: TextStyle( | ||
fontSize: 18.0, | ||
fontFamily: 'Gilroy', | ||
fontWeight: FontWeight.bold), | ||
) | ||
], | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
mainAxisSize: MainAxisSize.min, | ||
)), | ||
) | ||
: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Icon( | ||
Icons.search, | ||
size: 60, | ||
color: Colors.black12, | ||
), | ||
Text( | ||
"Search for your favourite products", | ||
style: TextStyle( | ||
fontSize: 18.0, | ||
fontFamily: 'Gilroy', | ||
fontWeight: FontWeight.bold), | ||
), | ||
], | ||
))) | ||
: Center(child: CircularProgressIndicator()), | ||
Align( | ||
alignment: Alignment(0, -0.95), | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Container( | ||
color: Colors.transparent, | ||
child: Material( | ||
elevation: 8, | ||
child: Theme( | ||
data: ThemeData( | ||
primaryColor: Colors.white, | ||
primaryColorDark: Colors.white), | ||
child: TextField( | ||
autofocus: true, | ||
textInputAction: TextInputAction.search, | ||
focusNode: focusNode, | ||
controller: _textEditingController, | ||
cursorColor: colors.PRIMARY_COLOR, | ||
decoration: new InputDecoration( | ||
border: InputBorder.none, | ||
focusedBorder: InputBorder.none, | ||
enabledBorder: InputBorder.none, | ||
errorBorder: InputBorder.none, | ||
disabledBorder: InputBorder.none, | ||
suffixIcon: (_textEditingController | ||
.text.length != | ||
0) | ||
? GestureDetector( | ||
onTap: () { | ||
_textEditingController.clear(); | ||
FocusScope.of(context) | ||
.requestFocus(focusNode); | ||
}, | ||
child: Icon(Icons.cancel)) | ||
: Container( | ||
width: 0, | ||
height: 0, | ||
), | ||
contentPadding: EdgeInsets.all(15), | ||
hintText: "Search"), | ||
onSubmitted: (value) { | ||
model.getAllProducts(value); | ||
}, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
))); | ||
}, | ||
); | ||
} | ||
} |
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