|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
|
|
import 'package:huixiang/data/base_list_data.dart';
|
|
|
|
import 'package:huixiang/data/farmers.dart';
|
|
|
|
import 'package:huixiang/data/good_list.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/home/help_farmers/farmers_tab.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:shimmer/shimmer.dart';
|
|
|
|
|
|
|
|
import '../../utils/flutter_utils.dart';
|
|
|
|
import '../../utils/font_weight.dart';
|
|
|
|
import '../../view_widget/custom_image.dart';
|
|
|
|
import '../../view_widget/my_tab.dart';
|
|
|
|
import '../../view_widget/no_data_view.dart';
|
|
|
|
|
|
|
|
class HelpFarmersPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _HelpFarmersPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HelpFarmersPage extends State<HelpFarmersPage> {
|
|
|
|
ApiService? apiService;
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
List<Farmers> farmersList = [];
|
|
|
|
int tabIndex = 0;
|
|
|
|
int farmersListData = 0;
|
|
|
|
int networkStatus = 0;
|
|
|
|
String dataErrorText = "";
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
SharedPreferences.getInstance().then((value) => {
|
|
|
|
apiService = ApiService(Dio(),
|
|
|
|
context: context,
|
|
|
|
token: value.getString('token'),
|
|
|
|
showLoading: true),
|
|
|
|
queryConfig(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
///助农列表
|
|
|
|
queryConfig() async {
|
|
|
|
try {
|
|
|
|
BaseListData<Farmers>? baseData =
|
|
|
|
await apiService?.getConfig().catchError((error) {
|
|
|
|
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
|
|
|
|
alignment: Alignment.center);
|
|
|
|
networkStatus = -1;
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
return BaseListData<Farmers>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
farmersList.clear();
|
|
|
|
farmersList.addAll(baseData?.data ?? []);
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
networkStatus = 1;
|
|
|
|
} else {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
farmersListData = 1;
|
|
|
|
dataErrorText = baseData?.msg ?? "";
|
|
|
|
networkStatus = 2;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
setState(() {});
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
body: networkStatus == 0
|
|
|
|
? recommendSm()
|
|
|
|
: (networkStatus == 2
|
|
|
|
? Container(
|
|
|
|
color: Colors.white,
|
|
|
|
child: NoDataView(
|
|
|
|
src: "assets/image/xiao_fei.webp",
|
|
|
|
isShowBtn: false,
|
|
|
|
text: dataErrorText,
|
|
|
|
fontSize: 16.sp,
|
|
|
|
margin:
|
|
|
|
EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w),
|
|
|
|
))
|
|
|
|
: NestedScrollView(
|
|
|
|
headerSliverBuilder: (context, inner) {
|
|
|
|
return [
|
|
|
|
SliverAppBar(
|
|
|
|
pinned: true,
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
elevation: 0,
|
|
|
|
leading: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
margin: EdgeInsets.only(left: 10.w),
|
|
|
|
padding: EdgeInsets.all(6),
|
|
|
|
child: Icon(
|
|
|
|
Icons.arrow_back_ios,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
///去掉返回按钮
|
|
|
|
// automaticallyImplyLeading: false,
|
|
|
|
centerTitle: true,
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
background: MImage(
|
|
|
|
farmersList.isEmpty
|
|
|
|
? ""
|
|
|
|
: (farmersList[tabIndex].agriculturaListImg ??
|
|
|
|
""),
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
width: double.infinity,
|
|
|
|
height: 354.h,
|
|
|
|
errorSrc: "assets/image/default_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_1.webp",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expandedHeight: 354.h,
|
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: Size(double.infinity, 0),
|
|
|
|
child: DefaultTabController(
|
|
|
|
length: farmersList.length,
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
top: Radius.circular(16),
|
|
|
|
),
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.only(top: 7.h, bottom: 7.h),
|
|
|
|
child: TabBar(
|
|
|
|
isScrollable: true,
|
|
|
|
//可滚动
|
|
|
|
indicatorColor: Colors.white,
|
|
|
|
//tab排放方向
|
|
|
|
tabAlignment: TabAlignment.start,
|
|
|
|
//去掉底部线条
|
|
|
|
dividerHeight: 0,
|
|
|
|
labelColor: Colors.white,
|
|
|
|
labelStyle: TextStyle(
|
|
|
|
fontSize: 16.sp,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
unselectedLabelStyle: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
),
|
|
|
|
indicator: FarmersTab(),
|
|
|
|
// controller: tabController,
|
|
|
|
//未选中文字颜色
|
|
|
|
unselectedLabelColor: Colors.white,
|
|
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
|
|
//指示器与文字等宽
|
|
|
|
tabs: farmersList
|
|
|
|
.map((e) => MyTab(text: "${e.typeName}"))
|
|
|
|
.toList(),
|
|
|
|
onTap: (index) {
|
|
|
|
// queryConfig("AgriculturalList");
|
|
|
|
tabIndex = index;
|
|
|
|
queryConfig();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
body: recommend(),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
///为你推荐
|
|
|
|
Widget recommend() {
|
|
|
|
return Container(
|
|
|
|
color: Colors.white,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10.w),
|
|
|
|
child: (farmersList.isEmpty ||
|
|
|
|
(farmersList[tabIndex].goodList ?? []).isEmpty)
|
|
|
|
? NoDataView(
|
|
|
|
src: "assets/image/xiao_fei.webp",
|
|
|
|
isShowBtn: false,
|
|
|
|
text: "当前分类暂无商品",
|
|
|
|
fontSize: 16.sp,
|
|
|
|
margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w),
|
|
|
|
)
|
|
|
|
: StaggeredGrid.count(
|
|
|
|
crossAxisCount: 2,
|
|
|
|
mainAxisSpacing: 10,
|
|
|
|
crossAxisSpacing: 10,
|
|
|
|
children: farmersList[tabIndex].goodList?.map((e) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
'/router/shop_details_page',
|
|
|
|
arguments: {
|
|
|
|
"id": e.id,
|
|
|
|
"storeId": e.storeId,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: recommendItem(e),
|
|
|
|
);
|
|
|
|
}).toList() ??
|
|
|
|
[],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget recommendItem(GoodList goodList) {
|
|
|
|
return Container(
|
|
|
|
width: 173,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Color(0x1A213303),
|
|
|
|
offset: Offset(0, 2),
|
|
|
|
blurRadius: 4,
|
|
|
|
spreadRadius: 0,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
MImage(
|
|
|
|
goodList.productImg ?? "",
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
width: double.infinity,
|
|
|
|
height: 174,
|
|
|
|
radius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(6),
|
|
|
|
topRight: Radius.circular(6),
|
|
|
|
),
|
|
|
|
errorSrc: "assets/image/default_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_1.webp",
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: 7.h,
|
|
|
|
left: 10.w,
|
|
|
|
bottom: 8.h,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
goodList.productName ?? "",
|
|
|
|
maxLines: 2,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
height: 1.3.h,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFF0D0D0D),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 10.w, bottom: 12.h),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
AppUtils.calculateDouble(
|
|
|
|
double.tryParse("${goodList.price}") ?? 0),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24.sp,
|
|
|
|
fontFamily: 'APPHT',
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(left: 8.w),
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 3.h, horizontal: 9.w),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(100),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Color(0x1A213303),
|
|
|
|
offset: Offset(0, 2),
|
|
|
|
blurRadius: 4,
|
|
|
|
spreadRadius: 0,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
S.of(context).zhunongjifen,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget recommendSm() {
|
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(6)),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.black.withAlpha(25),
|
|
|
|
offset: Offset(0, 1),
|
|
|
|
blurRadius: 12,
|
|
|
|
spreadRadius: 0,
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Shimmer.fromColors(
|
|
|
|
baseColor: Color(0XFFD8D8D8),
|
|
|
|
highlightColor: Color(0XFFD8D8D8),
|
|
|
|
child: Container(
|
|
|
|
color: Color(0XFFD8D8D8),
|
|
|
|
width: double.infinity,
|
|
|
|
height: 289.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
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: 64.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 12.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: 64.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 12.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: 64.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 12.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: 64.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: 10,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Shimmer.fromColors(
|
|
|
|
baseColor: Color(0XFFD8D8D8),
|
|
|
|
highlightColor: Color(0XFFD8D8D8),
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 6.w),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0XFFD8D8D8),
|
|
|
|
borderRadius: BorderRadius.circular(2),
|
|
|
|
),
|
|
|
|
height: 174.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(top: 7.h, left: 10.w, bottom: 8.h),
|
|
|
|
child: Shimmer.fromColors(
|
|
|
|
baseColor: Color(0XFFD8D8D8),
|
|
|
|
highlightColor: Color(0XFFD8D8D8),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0XFFD8D8D8),
|
|
|
|
borderRadius: BorderRadius.circular(2),
|
|
|
|
),
|
|
|
|
width: 106.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 10.w, bottom: 12.h),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Shimmer.fromColors(
|
|
|
|
baseColor: Color(0XFFD8D8D8),
|
|
|
|
highlightColor: Color(0XFFD8D8D8),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0XFFD8D8D8),
|
|
|
|
borderRadius: BorderRadius.circular(2),
|
|
|
|
),
|
|
|
|
width: 166.w,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Spacer(),
|
|
|
|
Shimmer.fromColors(
|
|
|
|
baseColor: Color(0XFFD8D8D8),
|
|
|
|
highlightColor: Color(0XFFD8D8D8),
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(right: 10.w),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0XFFD8D8D8),
|
|
|
|
borderRadius: BorderRadius.circular(100),
|
|
|
|
),
|
|
|
|
width: 86.w,
|
|
|
|
height: 25.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|