-
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.
Merge branch 'products_v5' into development
# Conflicts: # gogrocy/lib/core/services/api.dart
- Loading branch information
Showing
10 changed files
with
225 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:gogrocy/core/enums/viewstate.dart'; | ||
import 'package:gogrocy/core/models/ProductsByCity.dart'; | ||
import 'package:gogrocy/core/models/product.dart'; | ||
import 'package:gogrocy/core/services/api.dart'; | ||
import 'package:gogrocy/core/viewModels/base_model.dart'; | ||
import 'package:gogrocy/service_locator.dart'; | ||
|
||
class SearchViewModel extends BaseModel{ | ||
Apis _apis=locator<Apis>(); | ||
|
||
ProductsByCity searchResults; | ||
bool isSearchNull; | ||
|
||
Future getAllProducts(String query) async{ | ||
|
||
if(query!="") { | ||
setState(ViewState.Busy); | ||
searchResults = await _apis.searchProductByCity(query); | ||
//allProducts.result.shuffle(); | ||
setState(ViewState.Idle); | ||
isSearchNull=false; | ||
} | ||
else isSearchNull=true; | ||
} | ||
|
||
|
||
} |
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,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 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
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