Skip to content

Commit

Permalink
Search is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinmay-KB committed Apr 29, 2020
1 parent 2aa36ba commit 8f95fe5
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 39 deletions.
14 changes: 10 additions & 4 deletions gogrocy/lib/core/viewModels/search_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ class SearchViewModel extends BaseModel{
Apis _apis=locator<Apis>();

ProductsByCity searchResults;
bool isSearchNull;

Future getAllProducts(String query) async{
setState(ViewState.Busy);
searchResults=await _apis.searchProductByCity(query);
//allProducts.result.shuffle();
setState(ViewState.Idle);

if(query!="") {
setState(ViewState.Busy);
searchResults = await _apis.searchProductByCity(query);
//allProducts.result.shuffle();
setState(ViewState.Idle);
isSearchNull=false;
}
else isSearchNull=true;
}


Expand Down
3 changes: 3 additions & 0 deletions gogrocy/lib/ui/shared/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ double scaleRatio = mediaQueryData.devicePixelRatio/2.002;
double screenHeight = mediaQueryData.size.height;
double screenWidth = mediaQueryData.size.width;

final String imageBaseUrl="https://res.cloudinary.com/gogrocy/image/upload/c_scale,w_120/v1";


class LoginConfig {
static double loginTextFieldWidth = 280 * scaleRatio;
static double titleTextSize = 22 * scaleRatio;
Expand Down
2 changes: 1 addition & 1 deletion gogrocy/lib/ui/views/cart/cart_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:gogrocy/ui/widgets/cart_counter.dart';

class CartList extends StatelessWidget {
final String baseImgUrl =
"https://res.cloudinary.com/gogrocy/image/upload/v1/";
constants.imageBaseUrl;
CartViewModel model;
cart_list cartList;

Expand Down
4 changes: 2 additions & 2 deletions gogrocy/lib/ui/views/home/grid_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class GridList extends StatelessWidget {

GridList(this.resultList);
final ScrollController _scrollController = ScrollController();
final String baseImgUrl =
"https://res.cloudinary.com/gogrocy/image/upload/v1/";
final String baseImgUrl =constants.imageBaseUrl;

final NavigationService _navigationService = locator<NavigationService>();

@override
Expand Down
164 changes: 132 additions & 32 deletions gogrocy/lib/ui/views/search_view.dart
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);
},
),
),
),
),
),
),
],
)));
},
);
}
}
2 changes: 2 additions & 0 deletions gogrocy/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies:
smooth_page_indicator: ^0.1.5
flushbar: 1.9.1
simple_search_bar: ^0.1.7
flappy_search_bar: ^1.7.2




Expand Down

0 comments on commit 8f95fe5

Please sign in to comment.