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