diff --git a/Shop/flutter_shop_center/lib/config/service_url.dart b/Shop/flutter_shop_center/lib/config/service_url.dart index b666523..011468f 100644 --- a/Shop/flutter_shop_center/lib/config/service_url.dart +++ b/Shop/flutter_shop_center/lib/config/service_url.dart @@ -8,4 +8,6 @@ const servicePath = { 'getCategory':serviceUrl+'wxmini/getCategory', //商品分类的商品列表 'getMallGoods':serviceUrl+'wxmini/getMallGoods', + //商品分类的商品列表 + 'getGoodDetailById':serviceUrl+'wxmini/getGoodDetailById', }; \ No newline at end of file diff --git a/Shop/flutter_shop_center/lib/main.dart b/Shop/flutter_shop_center/lib/main.dart index b44bb0a..b4edc01 100644 --- a/Shop/flutter_shop_center/lib/main.dart +++ b/Shop/flutter_shop_center/lib/main.dart @@ -6,19 +6,23 @@ import 'package:provide/provide.dart'; import './provide/counter.dart'; import './provide/child_category.dart'; import './provide/child_category_goods_list.dart'; +import './provide/details_info.dart'; import 'package:fluro/fluro.dart'; import './routers/router.dart'; import './routers/application.dart'; void main(){ + //状态管理配置 var counter = Counter(); var childCategory = ChildCategory(); var childCategoryGoodsListProvide = ChildCategoryGoodsListProvide(); + var detailsInfoProvide = DetailsInfoProvide(); var provides = Providers(); provides ..provide(Provider.value(counter)) ..provide(Provider.value(childCategory)) + ..provide(Provider.value(detailsInfoProvide)) ..provide(Provider.value(childCategoryGoodsListProvide)); runApp(ProviderNode(child: MyApp(), providers: provides)); diff --git a/Shop/flutter_shop_center/lib/model/detail.dart b/Shop/flutter_shop_center/lib/model/detail.dart new file mode 100644 index 0000000..6625d62 --- /dev/null +++ b/Shop/flutter_shop_center/lib/model/detail.dart @@ -0,0 +1,181 @@ +class DetailsModel { + String code; + String message; + DetailsGoodsData data; + + DetailsModel({this.code, this.message, this.data}); + + DetailsModel.fromJson(Map json) { + code = json['code']; + message = json['message']; + data = json['data'] != null ? new DetailsGoodsData.fromJson(json['data']) : null; + } + + Map toJson() { + final Map data = new Map(); + data['code'] = this.code; + data['message'] = this.message; + if (this.data != null) { + data['data'] = this.data.toJson(); + } + return data; + } +} + +class DetailsGoodsData { + GoodInfo goodInfo; + List goodComments; + AdvertesPicture advertesPicture; + + DetailsGoodsData({this.goodInfo, this.goodComments, this.advertesPicture}); + + DetailsGoodsData.fromJson(Map json) { + goodInfo = json['goodInfo'] != null + ? new GoodInfo.fromJson(json['goodInfo']) + : null; + if (json['goodComments'] != null) { + goodComments = new List(); + json['goodComments'].forEach((v) { + goodComments.add(new GoodComments.fromJson(v)); + }); + } + advertesPicture = json['advertesPicture'] != null + ? new AdvertesPicture.fromJson(json['advertesPicture']) + : null; + } + + Map toJson() { + final Map data = new Map(); + if (this.goodInfo != null) { + data['goodInfo'] = this.goodInfo.toJson(); + } + if (this.goodComments != null) { + data['goodComments'] = this.goodComments.map((v) => v.toJson()).toList(); + } + if (this.advertesPicture != null) { + data['advertesPicture'] = this.advertesPicture.toJson(); + } + return data; + } +} + +class GoodInfo { + String image5; + int amount; + String image3; + String image4; + String goodsId; + String isOnline; + String image1; + String image2; + String goodsSerialNumber; + double oriPrice; + double presentPrice; + String comPic; + int state; + String shopId; + String goodsName; + String goodsDetail; + + GoodInfo( + {this.image5, + this.amount, + this.image3, + this.image4, + this.goodsId, + this.isOnline, + this.image1, + this.image2, + this.goodsSerialNumber, + this.oriPrice, + this.presentPrice, + this.comPic, + this.state, + this.shopId, + this.goodsName, + this.goodsDetail}); + + GoodInfo.fromJson(Map json) { + image5 = json['image5']; + amount = json['amount']; + image3 = json['image3']; + image4 = json['image4']; + goodsId = json['goodsId']; + isOnline = json['isOnline']; + image1 = json['image1']; + image2 = json['image2']; + goodsSerialNumber = json['goodsSerialNumber']; + oriPrice = json['oriPrice']; + presentPrice = json['presentPrice']; + comPic = json['comPic']; + state = json['state']; + shopId = json['shopId']; + goodsName = json['goodsName']; + goodsDetail = json['goodsDetail']; + } + + Map toJson() { + final Map data = new Map(); + data['image5'] = this.image5; + data['amount'] = this.amount; + data['image3'] = this.image3; + data['image4'] = this.image4; + data['goodsId'] = this.goodsId; + data['isOnline'] = this.isOnline; + data['image1'] = this.image1; + data['image2'] = this.image2; + data['goodsSerialNumber'] = this.goodsSerialNumber; + data['oriPrice'] = this.oriPrice; + data['presentPrice'] = this.presentPrice; + data['comPic'] = this.comPic; + data['state'] = this.state; + data['shopId'] = this.shopId; + data['goodsName'] = this.goodsName; + data['goodsDetail'] = this.goodsDetail; + return data; + } +} + +class GoodComments { + int sCORE; + String comments; + String userName; + int discussTime; + + GoodComments({this.sCORE, this.comments, this.userName, this.discussTime}); + + GoodComments.fromJson(Map json) { + sCORE = json['SCORE']; + comments = json['comments']; + userName = json['userName']; + discussTime = json['discussTime']; + } + + Map toJson() { + final Map data = new Map(); + data['SCORE'] = this.sCORE; + data['comments'] = this.comments; + data['userName'] = this.userName; + data['discussTime'] = this.discussTime; + return data; + } +} + +class AdvertesPicture { + String pICTUREADDRESS; + String tOPLACE; + + AdvertesPicture({this.pICTUREADDRESS, this.tOPLACE}); + + AdvertesPicture.fromJson(Map json) { + pICTUREADDRESS = json['PICTURE_ADDRESS']; + tOPLACE = json['TO_PLACE']; + } + + Map toJson() { + final Map data = new Map(); + data['PICTURE_ADDRESS'] = this.pICTUREADDRESS; + data['TO_PLACE'] = this.tOPLACE; + return data; + } +} \ No newline at end of file diff --git a/Shop/flutter_shop_center/lib/pages/detail_page.dart b/Shop/flutter_shop_center/lib/pages/detail_page.dart index 46e75d9..d8c9ac0 100644 --- a/Shop/flutter_shop_center/lib/pages/detail_page.dart +++ b/Shop/flutter_shop_center/lib/pages/detail_page.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import '../provide/details_info.dart'; +import 'package:provide/provide.dart'; class DetailsPage extends StatelessWidget { final String goodsId; @@ -6,9 +8,37 @@ class DetailsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - child:Text('商品ID为:${goodsId}') + return Scaffold( + appBar: AppBar( + title: Text('商品详情'), + leading: IconButton( + icon: Icon(Icons.arrow_back), + onPressed: (){ + Navigator.pop(context); + } + ), + ), + body: FutureBuilder( + //异步处理数据 + future: getGoodsInfo(context), + builder: (context, snapShot){ + if(snapShot.hasData){ + return Container( + child: Center( + child: Text('${goodsId}'), + ), + ); + }else{ + return Text('暂无数据'); + } + }, + ), ); } + + Future getGoodsInfo(BuildContext context) async { + await Provide.value(context).getGoodsInfo(goodsId); + return '请求完成'; + } } \ No newline at end of file diff --git a/Shop/flutter_shop_center/lib/pages/home_page.dart b/Shop/flutter_shop_center/lib/pages/home_page.dart index 40bb0b3..b16eaa9 100644 --- a/Shop/flutter_shop_center/lib/pages/home_page.dart +++ b/Shop/flutter_shop_center/lib/pages/home_page.dart @@ -212,7 +212,13 @@ class SwiperDiy extends StatelessWidget { child: Swiper( itemCount: swiperDataList.length, itemBuilder: (context, index){ - return Image.network('${swiperDataList[index]['image']}',fit: BoxFit.fill,); + return InkWell( + onTap: () { + + Application.router.navigateTo(context, '/detail?id=${swiperDataList[index]['goodsId']}'); + }, + child: Image.network('${swiperDataList[index]['image']}',fit: BoxFit.fill,) + ); }, pagination: SwiperPagination(), autoplay: true, @@ -330,9 +336,11 @@ class Recommend extends StatelessWidget { } //每一个商品item - Widget _item(int index){ + Widget _item(context, int index){ return InkWell( - onTap: (){}, + onTap: (){ + Application.router.navigateTo(context, '/detail?id=${recommendList[index]['goodsId']}'); + }, child: Container( height: ScreenUtil().setHeight(330), width: ScreenUtil().setWidth(250), @@ -361,13 +369,13 @@ class Recommend extends StatelessWidget { } //横向排列item - Widget _listView(){ + Widget _listView(context){ return Container( height: ScreenUtil().setHeight(300), child: ListView.builder( scrollDirection: Axis.horizontal, itemBuilder: (context, index){ - return _item(index); + return _item(context,index); }, itemCount: recommendList.length, ), @@ -389,7 +397,7 @@ class Recommend extends StatelessWidget { child: Column( children: [ _titleWidget(), - _listView() + _listView(context) ], ), ); @@ -418,35 +426,37 @@ class FloorContent extends StatelessWidget { FloorContent({this.floorContent}); //商品item - Widget _floorGoodsItem(goods){ + Widget _floorGoodsItem(context,goods){ return Container( width: ScreenUtil().setWidth(375.0), child: InkWell( - onTap: (){}, + onTap: (){ + Application.router.navigateTo(context, '/detail?id=${goods['goodsId']}'); + }, child: Image.network(goods['image']), ), ); } - Widget _firstRow(){ + Widget _firstRow(context){ return Row( children: [ - _floorGoodsItem(floorContent[0]), + _floorGoodsItem(context,floorContent[0]), Column( children: [ - _floorGoodsItem(floorContent[1]), - _floorGoodsItem(floorContent[2]), + _floorGoodsItem(context,floorContent[1]), + _floorGoodsItem(context,floorContent[2]), ], ) ], ); } - Widget _secondRow(){ + Widget _secondRow(context){ return Row( children: [ - _floorGoodsItem(floorContent[3]), - _floorGoodsItem(floorContent[4]), + _floorGoodsItem(context,floorContent[3]), + _floorGoodsItem(context,floorContent[4]), ], ); } @@ -456,8 +466,8 @@ class FloorContent extends StatelessWidget { return Container( child: Column( children: [ - _firstRow(), - _secondRow() + _firstRow(context), + _secondRow(context) ], ), ); diff --git a/Shop/flutter_shop_center/lib/provide/details_info.dart b/Shop/flutter_shop_center/lib/provide/details_info.dart new file mode 100644 index 0000000..24b6551 --- /dev/null +++ b/Shop/flutter_shop_center/lib/provide/details_info.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'dart:convert'; +import '../model/detail.dart'; +import '../service/service_method.dart'; + +class DetailsInfoProvide with ChangeNotifier { + + DetailsModel detailsModel; + + //请求商品信息 + getGoodsInfo(String id){ + + var formData = {'goodId':id}; + requestPost('getGoodDetailById', formData: formData).then((val){ + + var resData = json.decode(val.toString()); + detailsModel = DetailsModel.fromJson(resData); + notifyListeners(); + }); + } + +}