|
|
|
@ -21,13 +21,15 @@ class SearchPage extends StatefulWidget {
|
|
|
|
|
final Map<String, dynamic> arguments; |
|
|
|
|
|
|
|
|
|
SearchPage({this.arguments}); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
|
return _SearchPage(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin, WidgetsBindingObserver { |
|
|
|
|
class _SearchPage extends State<SearchPage> |
|
|
|
|
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver { |
|
|
|
|
ApiService apiService; |
|
|
|
|
MinApiService minService; |
|
|
|
|
final TextEditingController editingController = TextEditingController(); |
|
|
|
@ -92,8 +94,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
getHistorySearch() async { |
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
var str = value.getString("historySearch"); |
|
|
|
|
if(str == null ) |
|
|
|
|
return; |
|
|
|
|
if (str == null) return; |
|
|
|
|
var strArr = str.split("&"); |
|
|
|
|
strArr.removeAt(strArr.length - 1); |
|
|
|
|
setState(() { |
|
|
|
@ -104,15 +105,13 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
|
|
|
|
|
///保存列表 |
|
|
|
|
setHistorySearch(String text) async { |
|
|
|
|
if(text == null || text.trim() == "") |
|
|
|
|
return; |
|
|
|
|
if (text == null || text.trim() == "") return; |
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
var str = value.getString("historySearch"); |
|
|
|
|
if(str == null ) |
|
|
|
|
str = ""; |
|
|
|
|
if (str == null) str = ""; |
|
|
|
|
var strArr = str.split("&"); |
|
|
|
|
if(strArr.length >30){ |
|
|
|
|
str = strArr.getRange(0, 29).join("&"); |
|
|
|
|
if (strArr.length > 60) { |
|
|
|
|
str = strArr.getRange(0, 59).join("&"); |
|
|
|
|
} else { |
|
|
|
|
str = strArr.join("&"); |
|
|
|
|
} |
|
|
|
@ -142,14 +141,23 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
storeId: widget.arguments["storeId"], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
BaseData<List<FindMiNiGroupList>> baseData = |
|
|
|
|
await minService.findMiNiGroupList({ |
|
|
|
|
BaseData<List<FindMiNiGroupList>> baseData = await minService |
|
|
|
|
.findMiNiGroupList({ |
|
|
|
|
"id": widget.arguments["storeId"], |
|
|
|
|
"searchKey": text, |
|
|
|
|
"sortType":optionIndex == 0 ? "" : (optionIndex == 1) ? productListBeans[0].sellCount : productListBeans[0].price, |
|
|
|
|
"asc":optionIndex == 0 ? "" :(priceOrder == 2) ? true:"" |
|
|
|
|
}).catchError((error) { |
|
|
|
|
}).catchError((error) { |
|
|
|
|
"sortType": optionIndex == 0 |
|
|
|
|
? "" |
|
|
|
|
: (optionIndex == 1) |
|
|
|
|
? productListBeans[0].sellCount |
|
|
|
|
: productListBeans[0].price, |
|
|
|
|
"asc": optionIndex == 0 |
|
|
|
|
? "" |
|
|
|
|
: (priceOrder == 2) |
|
|
|
|
? true |
|
|
|
|
: "" |
|
|
|
|
}) |
|
|
|
|
.catchError((error) {}) |
|
|
|
|
.catchError((error) { |
|
|
|
|
refreshController.refreshFailed(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -226,8 +234,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: |
|
|
|
|
Container( |
|
|
|
|
child: Container( |
|
|
|
|
height: 36.h, |
|
|
|
|
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0), |
|
|
|
|
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h), |
|
|
|
@ -278,15 +285,15 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
border: InputBorder.none, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
), |
|
|
|
|
)), |
|
|
|
|
Container( |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
if (editingController.text.trim() == "") { |
|
|
|
|
SmartDialog.showToast("请输入搜索内容", alignment: Alignment.center); |
|
|
|
|
SmartDialog.showToast("请输入搜索内容", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
appletGoods(editingController.text); |
|
|
|
@ -329,7 +336,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
builder: (context, mode) { |
|
|
|
|
return MyFooter(mode); |
|
|
|
|
}, |
|
|
|
|
),onRefresh: () { |
|
|
|
|
), |
|
|
|
|
onRefresh: () { |
|
|
|
|
setState(() { |
|
|
|
|
_onRefresh(); |
|
|
|
|
}); |
|
|
|
@ -340,12 +348,9 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
builder: (context, snapshot) { |
|
|
|
|
return Column( |
|
|
|
|
children: [ |
|
|
|
|
if(hasFocus) |
|
|
|
|
hotSearchWords(), |
|
|
|
|
if(hasFocus) |
|
|
|
|
historySearchWords(), |
|
|
|
|
if(!hasFocus) |
|
|
|
|
searchList() |
|
|
|
|
if (hasFocus) hotSearchWords(), |
|
|
|
|
if (hasFocus) historySearchWords(), |
|
|
|
|
if (!hasFocus) searchList() |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
@ -365,7 +370,6 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
///热门搜索 |
|
|
|
|
Widget hotSearchWords() { |
|
|
|
|
return Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
@ -415,6 +419,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
|
|
|
|
|
Widget hotSearchItem(String hotSearch) { |
|
|
|
|
return Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
@ -437,7 +442,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
///历史搜索 |
|
|
|
|
Widget historySearchWords() { |
|
|
|
|
return Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
// width: double.infinity, |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
@ -516,18 +521,25 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Expanded(child: |
|
|
|
|
RoundButton( |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
padding: EdgeInsets.only(left: 4, right: 4), |
|
|
|
|
height: 29.h, |
|
|
|
|
text:historySearch, |
|
|
|
|
textColor: Color(0xFF181818), |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
radius: 4, |
|
|
|
|
backgroup: Color(0xFFF5F5F5), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(4), |
|
|
|
|
color: Color(0xFFF5F5F5)), |
|
|
|
|
child: Text( |
|
|
|
|
historySearch, |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
maxLines: 1, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
),) |
|
|
|
|
|
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Color(0xFF181818), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -589,8 +601,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
optionIndex = 2; |
|
|
|
|
priceOrder = 1; |
|
|
|
|
appletGoods(widget.arguments["searchKey"]); |
|
|
|
|
// priceOrder = 1; |
|
|
|
|
// appletGoods(widget.arguments["searchKey"]); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Row( |
|
|
|
@ -616,7 +628,9 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
}, |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.arrow_drop_up, |
|
|
|
|
color: (optionIndex == 2 && priceOrder == 1) ? Color(0xFF33A061) : Color(0xFF4D4D4D), |
|
|
|
|
color: (optionIndex == 2 && priceOrder == 1) |
|
|
|
|
? Color(0xFF33A061) |
|
|
|
|
: Color(0xFF4D4D4D), |
|
|
|
|
size: 16, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
@ -627,7 +641,9 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
}, |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.arrow_drop_down, |
|
|
|
|
color: (optionIndex == 2 && priceOrder == 2) ? Color(0xFF33A061) : Color(0xFF4D4D4D), |
|
|
|
|
color: (optionIndex == 2 && priceOrder == 2) |
|
|
|
|
? Color(0xFF33A061) |
|
|
|
|
: Color(0xFF4D4D4D), |
|
|
|
|
size: 16, |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
@ -670,8 +686,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
text: "该关键词未搜索到相关商品~", |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w), |
|
|
|
|
): |
|
|
|
|
GridView.builder( |
|
|
|
|
) |
|
|
|
|
: GridView.builder( |
|
|
|
|
itemCount: productListBeans?.length ?? 0, |
|
|
|
|
shrinkWrap: true, |
|
|
|
|
physics: NeverScrollableScrollPhysics(), |
|
|
|
@ -683,8 +699,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
//垂直子Widget之间间距 |
|
|
|
|
mainAxisSpacing: 16.w, |
|
|
|
|
//子Widget宽高比例 0.59 |
|
|
|
|
childAspectRatio: |
|
|
|
|
185 / (281 / 2 + (281 / 2) * AppUtils.textScale(context)), |
|
|
|
|
childAspectRatio: 185 / |
|
|
|
|
(281 / 2 + (281 / 2) * AppUtils.textScale(context)), |
|
|
|
|
), |
|
|
|
|
itemBuilder: (context, index) { |
|
|
|
|
return GestureDetector( |
|
|
|
@ -739,8 +755,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
child: |
|
|
|
|
MImage( |
|
|
|
|
child: MImage( |
|
|
|
|
productListBeans?.imgPath ?? "", |
|
|
|
|
width: double.infinity, |
|
|
|
|
height: 166, |
|
|
|
@ -760,7 +775,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end, |
|
|
|
|
children: [ |
|
|
|
|
Expanded(child:Container( |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
margin: EdgeInsets.only(top: 8, right: 8), |
|
|
|
|
padding: EdgeInsets.only(left: 2, right: 2), |
|
|
|
|
height: 17.h, |
|
|
|
@ -779,16 +795,20 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
|
|
|
|
|
color: Colors.white, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
Expanded(child: |
|
|
|
|
Container(child: Text( |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
child: Text( |
|
|
|
|
"已售${productListBeans?.sellCount ?? 0}件", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Color(0xFF5D5D5D), |
|
|
|
|
), |
|
|
|
|
),alignment: Alignment.topRight,)), |
|
|
|
|
), |
|
|
|
|
alignment: Alignment.topRight, |
|
|
|
|
)), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|