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.

220 lines
6.9 KiB

3 years ago
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/store.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/icon_text.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
3 years ago
import 'package:huixiang/view_widget/request_permission.dart';
4 years ago
import 'package:permission_handler/permission_handler.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import '../view_widget/no_data_view.dart';
4 years ago
class StoreSelectorPage extends StatefulWidget {
final Map<String, dynamic> arguments;
///兑换订单
StoreSelectorPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _StoreSelectorPage();
}
}
class _StoreSelectorPage extends State<StoreSelectorPage> {
4 years ago
ApiService apiService;
List<Store> exchangeStoreList;
4 years ago
4 years ago
@override
void initState() {
super.initState();
exchangeShop(widget.arguments["creditGoodsId"]);
3 years ago
}
///兑换门店列表
exchangeShop(creditGoodsId) async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
3 years ago
context: context,
showLoading: true,
token: value.getString("token"),
);
}
BaseData<List<Store>> baseData = await apiService
.storeListByCreditId(creditGoodsId)
.catchError((error) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
setState((){
exchangeStoreList = baseData.data;
});
4 years ago
}
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).mendianxuanzhe,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFAFAFA),
leadingColor: Colors.black,
4 years ago
),
body: Container(
4 years ago
margin: EdgeInsets.only(top: 18.h),
4 years ago
child: Column(
children: [
4 years ago
Expanded(
child: (exchangeStoreList == null || exchangeStoreList.length == 0)
? 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),
)
: ListView.builder(
itemCount: exchangeStoreList != null ? exchangeStoreList.length : 0,
4 years ago
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {
setState(() {
4 years ago
groupValue = position;
4 years ago
});
},
child: buildStoreItem(exchangeStoreList[position], position),
4 years ago
);
}),
),
InkWell(
onTap: () {
4 years ago
if (groupValue == null) {
3 years ago
SmartDialog.showToast(S.of(context).qingxuanzeyigemendian,
alignment: Alignment.center);
4 years ago
return;
}
Store store = exchangeStoreList[groupValue];
4 years ago
Navigator.of(context).pop({
4 years ago
"id": store.id,
"address": store.address,
4 years ago
});
4 years ago
},
child: Container(
4 years ago
padding: EdgeInsets.only(top: 16.h, bottom: 16.h),
4 years ago
decoration: BoxDecoration(
4 years ago
color: Color(0xFF32A060),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4),
),
),
4 years ago
alignment: Alignment.center,
child: Text(
S.of(context).queren,
style: TextStyle(
4 years ago
fontSize: 16.sp,
color: Color(0xFFFFFFFF),
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
),
4 years ago
),
4 years ago
),
),
],
),
),
);
}
4 years ago
Widget buildStoreItem(Store store, position) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 8.h, bottom: 8.h),
4 years ago
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
4 years ago
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.circular(8),
),
4 years ago
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
4 years ago
store.storeName,
4 years ago
style: TextStyle(
4 years ago
fontSize: 16.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Color(0xFF353535),
),
),
4 years ago
SizedBox(
4 years ago
height: 12.h,
4 years ago
),
4 years ago
IconText(
4 years ago
store.address,
isMax: true,
4 years ago
textAxisAlignment: CrossAxisAlignment.start,
4 years ago
textStyle: TextStyle(
color: Color(0xFF353535),
fontSize: 14.sp,
),
4 years ago
leftIcon: Icons.location_on,
iconColor: Color(0xFF32A060),
iconSize: 16,
),
4 years ago
SizedBox(
4 years ago
height: 4.h,
4 years ago
),
4 years ago
IconText(
4 years ago
(store.openStartTime == null && store.openEndTime == null)
4 years ago
? S.of(context).quantian
4 years ago
: "${store.openStartTime}-${store.openEndTime}",
4 years ago
textStyle: TextStyle(
color: Color(0xFF353535),
fontSize: 14.sp,
),
4 years ago
leftIcon: Icons.access_time,
iconColor: Color(0xFF32A060),
iconSize: 16,
),
],
),
),
Radio(
4 years ago
value: position,
groupValue: groupValue,
activeColor: Colors.green,
onChanged: (value) {
setState(() {
groupValue = value;
});
},
)
4 years ago
],
),
);
}
4 years ago
int groupValue = 0;
4 years ago
}