forked from wanggang1128/WGFlutterDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
王刚
committed
Aug 6, 2019
1 parent
6c199cc
commit 5fe9bbe
Showing
6 changed files
with
268 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '请求完成'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
|
||
} |