Skip to content

Commit

Permalink
商品详情页初次布局
Browse files Browse the repository at this point in the history
  • Loading branch information
王刚 committed Aug 6, 2019
1 parent 6c199cc commit 5fe9bbe
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Shop/flutter_shop_center/lib/config/service_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ const servicePath = {
'getCategory':serviceUrl+'wxmini/getCategory',
//商品分类的商品列表
'getMallGoods':serviceUrl+'wxmini/getMallGoods',
//商品分类的商品列表
'getGoodDetailById':serviceUrl+'wxmini/getGoodDetailById',
};
4 changes: 4 additions & 0 deletions Shop/flutter_shop_center/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Counter>.value(counter))
..provide(Provider<ChildCategory>.value(childCategory))
..provide(Provider<DetailsInfoProvide>.value(detailsInfoProvide))
..provide(Provider<ChildCategoryGoodsListProvide>.value(childCategoryGoodsListProvide));

runApp(ProviderNode(child: MyApp(), providers: provides));
Expand Down
181 changes: 181 additions & 0 deletions Shop/flutter_shop_center/lib/model/detail.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
class DetailsModel {
String code;
String message;
DetailsGoodsData data;

DetailsModel({this.code, this.message, this.data});

DetailsModel.fromJson(Map<String, dynamic> json) {
code = json['code'];
message = json['message'];
data = json['data'] != null ? new DetailsGoodsData.fromJson(json['data']) : null;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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> goodComments;
AdvertesPicture advertesPicture;

DetailsGoodsData({this.goodInfo, this.goodComments, this.advertesPicture});

DetailsGoodsData.fromJson(Map<String, dynamic> json) {
goodInfo = json['goodInfo'] != null
? new GoodInfo.fromJson(json['goodInfo'])
: null;
if (json['goodComments'] != null) {
goodComments = new List<GoodComments>();
json['goodComments'].forEach((v) {
goodComments.add(new GoodComments.fromJson(v));
});
}
advertesPicture = json['advertesPicture'] != null
? new AdvertesPicture.fromJson(json['advertesPicture'])
: null;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
sCORE = json['SCORE'];
comments = json['comments'];
userName = json['userName'];
discussTime = json['discussTime'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
pICTUREADDRESS = json['PICTURE_ADDRESS'];
tOPLACE = json['TO_PLACE'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['PICTURE_ADDRESS'] = this.pICTUREADDRESS;
data['TO_PLACE'] = this.tOPLACE;
return data;
}
}
34 changes: 32 additions & 2 deletions Shop/flutter_shop_center/lib/pages/detail_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import 'package:flutter/material.dart';
import '../provide/details_info.dart';
import 'package:provide/provide.dart';

class DetailsPage extends StatelessWidget {
final String goodsId;
DetailsPage(this.goodsId);

@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<DetailsInfoProvide>(context).getGoodsInfo(goodsId);
return '请求完成';
}
}
44 changes: 27 additions & 17 deletions Shop/flutter_shop_center/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
),
Expand All @@ -389,7 +397,7 @@ class Recommend extends StatelessWidget {
child: Column(
children: <Widget>[
_titleWidget(),
_listView()
_listView(context)
],
),
);
Expand Down Expand Up @@ -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: <Widget>[
_floorGoodsItem(floorContent[0]),
_floorGoodsItem(context,floorContent[0]),
Column(
children: <Widget>[
_floorGoodsItem(floorContent[1]),
_floorGoodsItem(floorContent[2]),
_floorGoodsItem(context,floorContent[1]),
_floorGoodsItem(context,floorContent[2]),
],
)
],
);
}

Widget _secondRow(){
Widget _secondRow(context){
return Row(
children: <Widget>[
_floorGoodsItem(floorContent[3]),
_floorGoodsItem(floorContent[4]),
_floorGoodsItem(context,floorContent[3]),
_floorGoodsItem(context,floorContent[4]),
],
);
}
Expand All @@ -456,8 +466,8 @@ class FloorContent extends StatelessWidget {
return Container(
child: Column(
children: <Widget>[
_firstRow(),
_secondRow()
_firstRow(context),
_secondRow(context)
],
),
);
Expand Down
22 changes: 22 additions & 0 deletions Shop/flutter_shop_center/lib/provide/details_info.dart
Original file line number Diff line number Diff line change
@@ -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();
});
}

}

0 comments on commit 5fe9bbe

Please sign in to comment.