123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- import 'dart:math';
- import 'package:flustars/flustars.dart' as FlutterStars;
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- import 'package:liftmanager/common/common.dart';
- import 'package:liftmanager/internal/account/account_router.dart';
- import 'package:liftmanager/internal/bbs/model/shop_detail.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/iconfont.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/utils/url.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:liftmanager/widgets/load_image.dart';
- import 'package:url_launcher/url_launcher.dart';
- import 'package:liftmanager/widgets/preview_images.dart';
- import '../../recommend_ask.dart';
- class ProductDetail extends StatefulWidget {
- ProductDetail(this.id);
- final String id;
- @override
- State<StatefulWidget> createState() {
- return ProductDetailState();
- }
- }
- class ProductDetailState extends State<ProductDetail> {
- @override
- void initState() {
- super.initState();
- getShopDetail();
- }
- bool _hasData = false;
- ShopDetailModel detailObj;
- Future getShopDetail() async {
- await NewApiService().getShopDetail(int.parse(widget.id), 1,
- onSuccess: (res) {
- if (res != null) {
- _hasData = true;
- detailObj = res;
- setState(() {});
- }
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- showAlertEvent() {
- showAlert(
- context,
- "提示",
- "确定登录?",
- "确定",
- () {
- NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- },
- );
- }
- Future changeFav(type) async {
- await NewApiService().shopFav(detailObj.id, type, 1, onSuccess: (res) {
- toasts("收藏成功");
- initCollect();
- getShopDetail();
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- Future cancelFav() async {
- await NewApiService().shopFavCancel(detailObj.favoriteId, onSuccess: (res) {
- toasts("取消收藏成功");
- initCollect();
- getShopDetail();
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- _launchPhone(url) async {
- if (await canLaunch(url)) {
- await launch(url);
- } else {
- throw 'Could not launch $url';
- }
- }
- initCollect() {
- String collectInit = randomInt(1111, 9999).toString() +
- DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("collectAction", collectInit);
- }
- randomInt(int min, int max) {
- return new Random().nextInt(max) % (max - min + 1) + min;
- }
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- return Scaffold(
- resizeToAvoidBottomPadding: false, //不让键盘弹上去
- appBar: MyAppBar(
- centerTitle: "商品详情",
- ),
- body: _hasData
- ? Stack(
- children: <Widget>[
- Container(
- child: ListView(children: <Widget>[
- Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Container(
- padding: EdgeInsets.symmetric(horizontal: 10),
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(width: 0.5, color: Colours.line),
- ),
- ),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Container(
- width: width,
- height: ScreenUtil().setWidth(220),
- padding: EdgeInsets.only(bottom: 10),
- child: Container(
- child: Swiper(
- itemBuilder: (BuildContext context, index) {
- return Container(
- width: width,
- height: ScreenUtil().setWidth(220),
- key: Key(
- detailObj.imgs.split(",")[index]),
- child: LoadNetworkImage(
- detailObj.imgs.split(",")[index],
- width: width,
- height: ScreenUtil().setWidth(220),
- fit: BoxFit.fill,
- isWater: true,
- ),
- );
- },
- pagination: SwiperPagination(
- builder: DotSwiperPaginationBuilder(
- color: Colors.grey,
- activeColor: Colors.white,
- size: 6,
- activeSize: 6)),
- itemCount: detailObj.imgs.split(",").length,
- scrollDirection: Axis.horizontal,
- autoplay: false,
- onTap: (index) {
- Navigator.of(context).push(
- FadeRoute(
- page: PhotoViewGalleryScreen(
- images: detailObj.imgs
- .split(","), //传入图片list
- index: index, //传入当前点击的图片的index
- // heroTag: img,//传入当前点击的图片的hero tag (可选)
- ),
- ),
- );
- // print(index);
- },
- ),
- ),
- ),
- SizedBox(height: 5),
- Text(
- detailObj.name ?? "",
- style:
- TextStyle(fontSize: ScreenUtil().setSp(16)),
- textAlign: TextAlign.start,
- ),
- SizedBox(
- height: 10,
- ),
- if (detailObj.brandName != null)
- Container(
- padding: EdgeInsets.all(3),
- decoration: BoxDecoration(
- color: Color(0x33448EFA),
- ),
- child: Text(
- detailObj.brandName ?? "",
- style: TextStyle(
- color: Color(0xff5888FF),
- fontSize: 11,
- fontWeight: FontWeight.w500,
- ),
- textAlign: TextAlign.start,
- ),
- ),
- SizedBox(
- height: 10,
- ),
- Row(
- crossAxisAlignment: CrossAxisAlignment.baseline,
- children: <Widget>[
- if (detailObj.discountPrice != null)
- Text(
- '¥${detailObj.discountPrice.toInt()}',
- style: TextStyle(
- color: Color(0xffFF5C00),
- fontSize: 16,
- ),
- ),
- if (detailObj.discountPrice == null)
- Text(
- '¥${detailObj.price?.toInt() ?? '暂无'}',
- style: TextStyle(
- color: Color(0xffFF5C00),
- fontSize: 16,
- ),
- ),
- if (detailObj.discountPrice != null)
- Text(
- '¥${detailObj.price.toInt()}',
- style: TextStyle(
- color: Color(0xff999999),
- fontSize: 11,
- decoration: TextDecoration.lineThrough,
- ),
- ),
- // Text(
- // '¥${detailObj?.price?.toInt() ?? ""}',
- // style: TextStyle(
- // color: Color(0xffFF5B00),
- // fontSize: 16,
- // ),
- // textAlign: TextAlign.start,
- // ),
- ],
- ),
- SizedBox(height: 15),
- ]),
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- SizedBox(
- height: 10,
- ),
- Container(
- padding: EdgeInsets.only(left: 10),
- decoration: BoxDecoration(
- border: Border(
- left: BorderSide(
- width: 2,
- color: Color(0xff568AFF),
- ),
- ),
- ),
- child: Text(
- "商品简介",
- style: TextStyle(
- fontSize: 15,
- color: Color(0xff333333),
- ),
- textAlign: TextAlign.left,
- ),
- ),
- SizedBox(
- height: 10,
- ),
- Container(
- padding: EdgeInsets.symmetric(horizontal: 10),
- child: Text(
- detailObj.descr,
- style: TextStyle(
- color: Color(0xff333333), fontSize: 13),
- textAlign: TextAlign.left,
- ),
- ),
- ],
- ),
- SizedBox(
- height: 10,
- ),
- Container(
- height: 1,
- color: ThemeUtils.getDialogTextFieldColor(context)),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- SizedBox(
- height: 10,
- ),
- Container(
- padding: EdgeInsets.only(left: 10),
- decoration: BoxDecoration(
- border: Border(
- left: BorderSide(
- width: 2,
- color: Color(0xff568AFF),
- ),
- ),
- ),
- child: Text(
- "商家信息",
- style: TextStyle(
- color: Color(0xff333333),
- fontSize: 15,
- ),
- textAlign: TextAlign.left,
- ),
- ),
- SizedBox(
- height: 10,
- ),
- Container(
- padding: EdgeInsets.symmetric(
- horizontal: 10,
- ),
- child: Column(children: [
- Row(
- children: [
- Icon(
- Iconfont.shangjia,
- color: Colors.orange,
- size: 13,
- ),
- SizedBox(
- width: 10,
- ),
- Text(
- "${detailObj.manufacturer}",
- style: TextStyle(
- color: Color(0xff666666),
- fontSize: 11,
- ),
- textAlign: TextAlign.left,
- ),
- ],
- ),
- SizedBox(
- height: 10,
- ),
- Row(
- children: [
- Icon(
- Iconfont.lianxi,
- color: Colors.orange,
- size: 13,
- ),
- SizedBox(
- width: 10,
- ),
- Text(
- "${detailObj.telephone} (${detailObj.contactPerson})",
- style: TextStyle(
- color: Color(0xff666666),
- fontSize: 11,
- ),
- textAlign: TextAlign.left,
- ),
- ],
- ),
- ]),
- ),
- ],
- ),
- SizedBox(height: ScreenUtil().setWidth(70))
- ],
- ),
- ])),
- Positioned(
- bottom: 0,
- left: 0,
- child: Container(
- width: width,
- color: Colors.white,
- padding: EdgeInsets.all(10),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- GestureDetector(
- onTap: () {
- if (FlutterStars.SpUtil.getString(
- Constant.userId) ==
- "-1") {
- showAlertEvent();
- } else {
- String initThis =
- randomInt(1111, 9999).toString() +
- DateTime.now()
- .millisecondsSinceEpoch
- .toString();
- fluwx
- .shareToWeChat(
- fluwx.WeChatShareWebPageModel(
- scene: fluwx.WeChatScene.SESSION,
- webPage:
- "$jumpUrl/h5/index.html?num=$initThis&page=/bbs/productDetail&id=${widget.id}",
- title: detailObj.name,
- description: detailObj.descr,
- thumbnail: detailObj.imgs.split(",")[0],
- ))
- .then((result) {}, onError: (msg) {
- // print(msg);
- });
- }
- },
- child: Container(
- // padding: EdgeInsets.only(left:25,right:30),
- child: Column(children: <Widget>[
- Icon(
- Iconfont.fenxiang,
- size: 20.0,
- color: Color(0xff333333),
- ),
- Text(
- "分享",
- style: TextStyle(
- color: Color(0xff555A64),
- fontSize: 12,
- ),
- textAlign: TextAlign.start,
- ),
- ])),
- ),
- GestureDetector(
- onTap: () {
- if (FlutterStars.SpUtil.getString(
- Constant.userId) ==
- "-1") {
- showAlertEvent();
- } else {
- if (detailObj.isFavorite == 1) {
- cancelFav();
- } else {
- changeFav(3);
- }
- }
- },
- child: Container(
- child: Column(children: <Widget>[
- Icon(
- // : 0xe604,
- detailObj.isFavorite == 1
- ? Iconfont.shoucang1
- : Iconfont.shoucang,
- size: 20.0,
- color: Color(detailObj.isFavorite == 1
- ? 0xff5589FF
- : 0xff555A64),
- ),
- Text(
- detailObj.isFavorite == 1 ? "已收藏" : "收藏",
- style: TextStyle(
- color: Color(detailObj.isFavorite == 1
- ? 0xff5589FF
- : 0xff555A64),
- fontSize: 12,
- ),
- textAlign: TextAlign.start,
- ),
- ])),
- ),
- ],
- ),
- ),
- Container(
- height: 45,
- width: 240,
- decoration: BoxDecoration(
- color: Color(0xff5589FF),
- borderRadius: BorderRadius.circular(30),
- ),
- child: FlatButton(
- // padding: EdgeInsets.all(15.0),
- child: Text(
- "联系商家",
- style: TextStyle(
- fontSize: 16,
- ),
- ),
- textColor: Colors.white,
- onPressed: () {
- if (FlutterStars.SpUtil.getString(
- Constant.userId) ==
- "-1") {
- showAlertEvent();
- } else {
- _launchPhone("tel:" + detailObj.telephone);
- }
- },
- ),
- ),
- ],
- ),
- ),
- )
- ],
- )
- : Center(
- child: Text("正在加载..."),
- ),
- );
- }
- }
|