You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
317 lines
10 KiB
317 lines
10 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/store.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:shimmer/shimmer.dart'; |
|
|
|
import '../retrofit/data/base_data.dart'; |
|
import '../retrofit/retrofit_api.dart'; |
|
import '../utils/flutter_utils.dart'; |
|
import '../view_widget/classic_header.dart'; |
|
import '../view_widget/no_data_view.dart'; |
|
|
|
class UnionList extends StatefulWidget { |
|
final String serviceType; |
|
final BMFCoordinate latLng; |
|
final String searchKey; |
|
final String city; |
|
|
|
UnionList(Key key, this.serviceType, this.latLng, this.searchKey, this.city) |
|
: super(key: key); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _UnionList(); |
|
} |
|
} |
|
|
|
class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin { |
|
ApiService apiService; |
|
List<Store> storeList; |
|
final RefreshController _refreshController = RefreshController(); |
|
|
|
@override |
|
bool get wantKeepAlive => true; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
queryStore(); |
|
} |
|
|
|
queryStore() async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData<List<Store>> baseData = await apiService.queryStore({ |
|
"city": widget.city ?? "", |
|
// "district": district, |
|
// "province": province, |
|
"latitude": (widget.latLng?.latitude ?? "").toString(), |
|
"longitude": (widget.latLng?.longitude ?? "").toString(), |
|
if (widget.searchKey != "") "searchKey": widget.searchKey, |
|
"serviceType": widget.serviceType, |
|
"exchange": false, |
|
}).catchError((error) { |
|
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type), |
|
alignment: Alignment.center); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
storeList = baseData.data; |
|
} |
|
_refreshController.refreshCompleted(); |
|
EasyLoading.dismiss(); |
|
setState(() {}); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return SmartRefresher( |
|
controller: _refreshController, |
|
enablePullDown: true, |
|
enablePullUp: false, |
|
header: MyHeader(color: Colors.white,), |
|
physics: BouncingScrollPhysics(), |
|
onRefresh: queryStore, |
|
child: (storeList == null || storeList.length == 0) |
|
? NoDataView( |
|
src: "assets/image/di_zhi.webp", |
|
isShowBtn: false, |
|
text: "暂无店铺列表~", |
|
fontSize: 16.sp, |
|
margin: EdgeInsets.only(top: 120.h), |
|
) |
|
: ListView.builder( |
|
itemCount: storeList.length, |
|
padding: EdgeInsets.only( |
|
top: 8.h, |
|
bottom: 100.h, |
|
), |
|
itemBuilder: (context, position) { |
|
return InkWell( |
|
onTap: () { |
|
{ |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": storeList[position].id, |
|
"tenant": storeList[position].tenantCode, |
|
"storeName": storeList[position].storeName, |
|
"distance": storeList[position].distance |
|
}, |
|
); |
|
} |
|
}, |
|
child: buildStoreItem(storeList[position], position), |
|
); |
|
}, |
|
), |
|
); |
|
} |
|
|
|
Widget sm() { |
|
return Container( |
|
margin: EdgeInsets.symmetric(horizontal: 14.w, vertical: 8.h), |
|
width: double.infinity, |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
borderRadius: BorderRadius.circular(6), |
|
), |
|
height: 223.h, |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
color: Color(0XFFD8D8D8), |
|
width: double.infinity, |
|
height: 140.h, |
|
), |
|
), |
|
Padding( |
|
padding: EdgeInsets.only(left: 6.w, bottom: 5.h, top: 12.h), |
|
child: Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 108.w, |
|
height: 20.h, |
|
), |
|
), |
|
), |
|
Padding( |
|
padding: EdgeInsets.only( |
|
left: 6.w, |
|
), |
|
child: Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 260.w, |
|
height: 20.h, |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget buildStoreItem(Store store, position) { |
|
return Container( |
|
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 12.h), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
borderRadius: BorderRadius.all(Radius.circular(8)), |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(25), |
|
offset: Offset(0, 1), |
|
blurRadius: 12, |
|
spreadRadius: 0, |
|
) |
|
]), |
|
width: double.infinity, |
|
height: 235.h, |
|
child: Stack( |
|
children: [ |
|
Positioned( |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
child: ClipRRect( |
|
child: MImage( |
|
store.facade, |
|
width: double.infinity, |
|
height: 140.h, |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
borderRadius: BorderRadius.vertical( |
|
top: Radius.circular(4), |
|
), |
|
), |
|
), |
|
Positioned( |
|
bottom: 0, |
|
left: 0, |
|
right: 0, |
|
child: Container(), |
|
), |
|
Positioned( |
|
bottom: 16.h, |
|
left: 12.w, |
|
right: 12.w, |
|
child: Container( |
|
height: 107.h, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
MImage( |
|
store.logo, |
|
width: 57, |
|
height: 57, |
|
fit: BoxFit.cover, |
|
isCircle: true, |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
SizedBox( |
|
width: 6.w, |
|
), |
|
Expanded( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
SizedBox( |
|
height: 40.h, |
|
), |
|
Text( |
|
store?.storeName ?? "", |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
color: Color(0xFF0D0D0D), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.bold, |
|
), |
|
), |
|
SizedBox( |
|
height: 5.h, |
|
), |
|
Expanded( |
|
child: Text( |
|
"${S.of(context).dizhi}:${store.address}", |
|
maxLines: 2, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
color: Color(0xFF4D4D4D), |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
) |
|
], |
|
)), |
|
if (store.distance != null) |
|
Container( |
|
width: 59.w, |
|
height: 18.h, |
|
alignment: Alignment.center, |
|
margin: EdgeInsets.only(top: 20.h), |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(2), |
|
color: Color(0xFF32A060), |
|
), |
|
child: Visibility( |
|
child: Text( |
|
(store.distance ?? 0) > 1000 |
|
? S.of(context).gongli( |
|
((store.distance ?? 0) / 1000 * 100).toInt() / |
|
100.0) |
|
: S.of(context).mi( |
|
((store.distance ?? 0) * 100).toInt() / |
|
100.0), |
|
style: TextStyle( |
|
color: Color(0xFFFFFFFF), |
|
fontSize: 10.sp, |
|
), |
|
), |
|
visible: store.distance != null, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|