import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper_view/flutter_swiper_view.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/data/store_info.dart'; import 'package:huixiang/utils/flutter_utils.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:huixiang/view_widget/round_button.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../utils/location.dart'; class StoreInfos extends StatefulWidget { final StoreInfo? storeInfo; StoreInfos(this.storeInfo); @override State createState() { return _StoreInfos(); } } class _StoreInfos extends State { @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.fromLTRB(17, 20, 15, 8), padding: EdgeInsets.fromLTRB(10, 20, 10, 14), width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), boxShadow: [ BoxShadow( color: Colors.black.withAlpha(25), offset: Offset(0, 1), blurRadius: 12, spreadRadius: 0, ), ], ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( flex: 1, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.storeInfo?.storeName ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 18.sp, color: Colors.black, fontWeight: MyFontWeight.medium, ), ), SizedBox( height: 8.h, ), Row( children: [ Text( S .of(context) .ren(widget.storeInfo!.perCapitaConsumption ?? ""), overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF353535), ), ), SizedBox( width: 22.w, ), Row( children: itemServer(widget.storeInfo?.businessService ?? ""), ), ], ), SizedBox( height: 12.h, ), Text( widget.storeInfo?.address ?? "", maxLines: 2, textAlign: TextAlign.justify, style: TextStyle( color: Color(0xFF353535), fontWeight: MyFontWeight.regular, fontSize: 12.sp, ), ), SizedBox( height: 6.h, ), Text( S.of(context).yingyeshijian(widget.storeInfo == null ? "" : ((widget.storeInfo!.openStartTime?.isEmpty ?? true) && widget.storeInfo?.openEndTime == null) ? S.of(context).quantian : "${widget.storeInfo?.openStartTime?.substring(0, widget.storeInfo?.openStartTime?.lastIndexOf(":"))} " "- ${widget.storeInfo?.openEndTime?.substring(0, widget.storeInfo?.openEndTime?.lastIndexOf(":"))}"), style: TextStyle( color: Color(0xFF353535), fontWeight: MyFontWeight.regular, fontSize: 12.sp, ), ), ], )), Column( children: [ MImage( widget.storeInfo!.logo ?? "", width: 69, height: 69, fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox( height: 21.h, ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.end, children: [ InkWell( onTap: () { if (widget.storeInfo == null || widget.storeInfo?.latitude == null || widget.storeInfo?.longitude == null || widget.storeInfo?.latitude == "" || widget.storeInfo?.longitude == "") return; showMapSelect(); }, child: Image.asset( "assets/image/icon_union_location.webp", width: 24.w, height: 24.h, ), ), SizedBox( width: 16.w, ), InkWell( onTap: () { showCallMobile(); }, child: Image.asset( "assets/image/icon_union_call.webp", width: 24, height: 24, ), ), ], ), ], ), ], ), ); // return AspectRatio( // aspectRatio: 1, // child: Container( // margin: EdgeInsets.fromLTRB(16, 20, 16, 8), // padding: EdgeInsets.fromLTRB(10, 20, 10, 14), // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(8), // boxShadow: [ // BoxShadow( // color: Colors.black.withAlpha(25), // offset: Offset(0, 1), // blurRadius: 12, // spreadRadius: 0, // ), // ], // ), // child: Column( // mainAxisAlignment: MainAxisAlignment.spaceAround, // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // AspectRatio( // aspectRatio: 1.8, // child: buildSwiper(), // ), // Expanded( // child: Container( // margin: EdgeInsets.only( // left: 10.w, // right: 10.w, // top: 16.h, // ), // child: Column( // mainAxisAlignment: // MainAxisAlignment.spaceBetween, // crossAxisAlignment: // CrossAxisAlignment.start, // children: [ // Row( // children: [ // Expanded( // child: Container( // alignment: // Alignment.centerLeft, // child: Text( // widget.storeInfo != null // ? widget.storeInfo.storeName // : "", // overflow: TextOverflow.ellipsis, // style: TextStyle( // fontSize: 16.sp, // color: Colors.black, // fontWeight: MyFontWeight.medium, // ), // ), // ), // ), // Text( // S.of(context).ren( // widget.storeInfo != null // ? widget.storeInfo // .perCapitaConsumption // : "", // ), // overflow: TextOverflow.ellipsis, // style: TextStyle( // fontSize: 14.sp, // fontWeight: MyFontWeight.regular, // color: Color(0xFF353535), // ), // ), // ], // ), // Text( // widget.storeInfo != null // ? widget.storeInfo.address // : "", // maxLines: 2, // textAlign: TextAlign.justify, // style: TextStyle( // color: Color(0xFF353535), // fontWeight: MyFontWeight.regular, // fontSize: 12.sp, // ), // ), // Row( // children: itemServer( // widget.storeInfo != null // ? widget.storeInfo.businessService // : "", // ), // ), // Row( // mainAxisAlignment: MainAxisAlignment.spaceBetween, // crossAxisAlignment: CrossAxisAlignment.end, // children: [ // Expanded( // child: Text( // S.of(context).yingyeshijian(widget.storeInfo == // null // ? "" // : (widget.storeInfo.openStartTime == // null && // widget.storeInfo // .openEndTime == // null) // ? S.of(context).quantian // : "${widget.storeInfo.openStartTime.substring(0, widget.storeInfo.openStartTime.lastIndexOf(":"))} " // "- ${widget.storeInfo.openEndTime.substring(0, widget.storeInfo.openEndTime.lastIndexOf(":"))}"), // style: TextStyle( // color: Color(0xFF353535), // fontWeight: MyFontWeight.regular, // fontSize: 12.sp, // ), // ), // ), // SizedBox( // width: 16.w, // ), // InkWell( // onTap: () { // if (widget.storeInfo == null || // widget.storeInfo.latitude == // null || // widget.storeInfo.longitude == // null || // widget.storeInfo.latitude == "" || // widget.storeInfo.longitude == "") // return; // Navigator.of(context).pushNamed( // '/router/location_map', // arguments: { // "lat": widget.storeInfo.latitude, // "lng": // widget.storeInfo.longitude, // "storeName": // widget.storeInfo.storeName, // }); // }, // child: Image.asset( // "assets/image/icon_union_location.webp", // width: 24.w, // height: 24.h, // ), // ), // SizedBox( // width: 16.w, // ), // InkWell( // onTap: () { // showCallMobile(); // }, // child: Image.asset( // "assets/image/icon_union_call.webp", // width: 24, // height: 24, // ), // ), // ], // ), // ], // ), // ), // flex: 1, // ), // ], // ), // ), // ); } Widget buildSwiper() { return Container( child: Swiper( pagination: SwiperPagination( alignment: Alignment.bottomCenter, builder: DotSwiperPaginationBuilder( size: 8.w, activeSize: 8.w, space: 5.w, activeColor: Colors.white, color: Colors.white.withAlpha(76), ), ), itemBuilder: (context, position) { return Container( margin: EdgeInsets.only(left: 10.w, right: 10.w), child: MImage( (position < (widget.storeInfo!.bannerList?.length ?? 0)) ? (widget.storeInfo!.bannerList![position].imgUrl ?? "") : "", fit: BoxFit.cover, radius: BorderRadius.circular(4), errorSrc: "assets/image/default_2_1.webp", fadeSrc: "assets/image/default_2_1.webp", ), ); }, itemCount: widget.storeInfo?.bannerList?.length ?? 1, )); } List itemServer(String businessService) { if (businessService == "") return []; var list = businessService.split(","); return list .map((e) => Container( margin: EdgeInsets.only(right: 8.w), child: RoundButton( height: 14.h * AppUtils.textScale(context), text: "$e", backgroup: Color(0xFFFF7A1A), padding: EdgeInsets.only( left: 2.w, right: 2.w, ), fontSize: 10.sp, textColor: Colors.white, ), )) .toList(); } showCallMobile() { showCupertinoModalPopup( context: context, builder: (context) { return CupertinoActionSheet( title: Text(S.of(context).bodadianhua), actions: [ if (widget.storeInfo?.tel?.isNotEmpty ?? false) CupertinoActionSheetAction( child: Text(widget.storeInfo!.tel ?? ""), onPressed: () { callMobile(widget.storeInfo!.tel); Navigator.of(context).pop(); }, isDefaultAction: true, isDestructiveAction: false, ), ], cancelButton: CupertinoActionSheetAction( onPressed: () { Navigator.of(context).pop(); }, child: Text(S.of(context).quxiao), isDestructiveAction: true, ), ); }, ); } callMobile(mobile) async { String url = "tel:$mobile"; if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } } showMapSelect() { showCupertinoModalPopup( context: context, builder: (context) { return CupertinoActionSheet( actions: [ CupertinoActionSheetAction( child: Text( "使用高德地图导航", style: TextStyle( fontWeight: MyFontWeight.regular, ), ), onPressed: () { onOpenBaiduMap(); Navigator.of(context).pop(); }, isDefaultAction: true, isDestructiveAction: false, ), ], cancelButton: CupertinoActionSheetAction( onPressed: () { Navigator.of(context).pop(); }, child: Text( S.of(context).quxiao, style: TextStyle( color: Colors.blue, ), ), isDestructiveAction: true, ), ); }); } void onOpenBaiduMap() async { LocationInstance.getInstance().startLocation(context, (locationData) { String url = "${Platform.isIOS ? 'ios' : 'android'}amap://path?sourceApplication=haixia&sid=" "&slat=${locationData?.latitude.toStringAsFixed(8)}&slon=${locationData?.longitude.toStringAsFixed(8)}&sname=&did=&dlat=${widget.storeInfo?.latitude}&dlon=${widget.storeInfo?.longitude}&dname=&dev=0&t=0"; launch(url).then((value) { if (!value) { SmartDialog.showToast( "未检测到安装高德地图", alignment: Alignment.center, ); } }); }); } }