Commit 2c292f66 authored by 朱璇's avatar 朱璇

对比详情

parent bec8036f
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zx * @Author: zx
* @Date: 2020-06-30 17:43:13 * @Date: 2020-06-30 17:43:13
* @Last Modified by: zx * @Last Modified by: zx
* @Last Modified time: 2020-07-01 20:04:23 * @Last Modified time: 2020-07-02 13:50:15
*/ */
import 'package:flutter_common/commonModel/live/BaseModel.dart'; import 'package:flutter_common/commonModel/live/BaseModel.dart';
import 'package:flutter_common/commonModel/live/LiveData.dart'; import 'package:flutter_common/commonModel/live/LiveData.dart';
...@@ -10,25 +10,43 @@ import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart'; ...@@ -10,25 +10,43 @@ import 'package:gm_flutter/ClueModel/server/api/ClueApi.serv.dart';
import 'package:gm_flutter/ClueModel/server/entity/PlanCompareDetail.dart'; import 'package:gm_flutter/ClueModel/server/entity/PlanCompareDetail.dart';
import 'package:gm_flutter/commonModel/GMBase.dart'; import 'package:gm_flutter/commonModel/GMBase.dart';
import 'package:gm_flutter/commonModel/rx/RxDispose.dart'; import 'package:gm_flutter/commonModel/rx/RxDispose.dart';
import 'package:flutter_common/commonModel/toast/NativeToast.dart';
import 'package:gm_flutter/commonModel/util/PrintUtil.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
class PlanCompareDetailModel extends BaseModel { class PlanCompareDetailModel extends BaseModel {
LiveData<PlanCompareDetail> detailLive = LiveData(); LiveData<Pair<int, List<Groups>>> detailLive = LiveData();
LiveData<Pair<int, List<PlansInfo>>> headerLive = LiveData();
RxDispose rxDispose = RxDispose(); RxDispose rxDispose = RxDispose();
void init() { void init(List<int> planIds) {
ClueApiImpl.getInstance() ClueApiImpl.getInstance()
.getPlanCompareDetail(DioUtil.getInstance().getDio(), [1,2]) .getPlanCompareDetail(DioUtil.getInstance().getDio(), planIds)
.listen((event) { .listen((event) {
if (event.error == 0) { if (event.error == 0) {
detailLive.notifyView(event); if (event.data.plansInfo == null || event.data.groups.isEmpty) {
headerLive.notifyView(Pair(ENDLOADING, []));
detailLive.notifyView(Pair(ENDLOADING, []));
} else {
detailLive.notifyView(Pair(ENDLOADING, event.data.groups));
}
} else {
NativeToast.showNativeToast(event.message);
headerLive.notifyView(Pair(FAIL, null));
detailLive.notifyView(Pair(FAIL, null));
} }
}) })
.addToDispose(rxDispose) .addToDispose(rxDispose)
.onError((err) {}); .onError((err) {
headerLive.notifyView(Pair(FAIL, null));
detailLive.notifyView(Pair(FAIL, null));
NativeToast.showNativeToast(err.message);
});
} }
@override @override
void dispose() { void dispose() {
detailLive.dispost(); detailLive.dispost();
} }
}
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zx * @Author: zx
* @Date: 2020-06-30 17:40:43 * @Date: 2020-06-30 17:40:43
* @Last Modified by: zx * @Last Modified by: zx
* @Last Modified time: 2020-07-02 10:20:25 * @Last Modified time: 2020-07-02 18:44:20
*/ */
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
...@@ -14,34 +14,26 @@ import 'package:gm_flutter/ClueModel/server/entity/PlanCompareDetail.dart'; ...@@ -14,34 +14,26 @@ import 'package:gm_flutter/ClueModel/server/entity/PlanCompareDetail.dart';
import 'package:gm_flutter/ClueModel/view/FiveStarView.dart'; import 'package:gm_flutter/ClueModel/view/FiveStarView.dart';
import 'package:gm_flutter/commonModel/base/BaseComponent.dart'; import 'package:gm_flutter/commonModel/base/BaseComponent.dart';
import 'package:gm_flutter/commonModel/base/BaseState.dart'; import 'package:gm_flutter/commonModel/base/BaseState.dart';
import 'package:gm_flutter/commonModel/bean/Pair.dart';
class PlanCompareDetailPage extends StatefulWidget { class PlanCompareDetailPage extends StatefulWidget {
@override @override
State<StatefulWidget> createState() => PlanCompareDetailPageState(); State<StatefulWidget> createState() => PlanCompareDetailPageState();
} }
class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
PlanCompareDetailModel _model = new PlanCompareDetailModel(); PlanCompareDetailModel _model = new PlanCompareDetailModel();
PageController pageController = new PageController(); double screenWidth;
double screenWidth;
List<Widget> viewList = new List(); List<Widget> viewList = new List();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
pageController.addListener(() { _model.init([1, 2]);
});
Groups groups;
viewList.add(planNormalEffectiveAttrsView(groups));
viewList.add(planNormalEffectiveAttrsView(groups));
viewList.add(planNormalEffectiveAttrsView(groups));
} }
@override @override
void dispose() { void dispose() {
_model.dispose(); _model.dispose();
pageController.dispose();
pageController.dispose();
super.dispose(); super.dispose();
} }
...@@ -49,85 +41,88 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -49,85 +41,88 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
Widget buildItem(BuildContext context) { Widget buildItem(BuildContext context) {
screenWidth = MediaQuery.of(context).size.width; screenWidth = MediaQuery.of(context).size.width;
return Scaffold( return Scaffold(
appBar: baseAppBar( appBar: baseAppBar(
title: "对比详情", title: "对比详情",
centerTitle: true, centerTitle: true,
backClick: () { backClick: () {
Navigator.pop(context); Navigator.pop(context);
}), }),
body: Container( body: Container(
child: head(), child:
// head(),
// planPopularityView()
// planNormalEffectiveAttrsView() // planPopularityView()
// setupHome([], []), // planNormalEffectiveAttrsView()
// reloadPage(), // setupHome([], []),
reloadPage(),
) ));
);
} }
Widget reloadPage () { Widget reloadPage() {
return StreamBuilder( return StreamBuilder(
stream: _model.detailLive.stream, stream: _model.detailLive.stream,
initialData: PlanCompareDetail(), initialData: _model.detailLive.data ?? Pair(LOADING, null),
builder: (c, data) { builder: (c, data) {
PlanCompareDetail detail = data.data; if (data.data.first == FAIL) {
if (detail == null || detail.data == null || detail.data.groups == null) { return errorItem(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height, () {
_model.init([1, 2]);
});
}
if (data.data.first == LOADING || _model.detailLive == null) {
return loadingItem(); return loadingItem();
} }
return setupHome(detail.data.plansInfo, detail.data.groups); if (data.data.second.length == 0) {
return emptyItem(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height);
}
return setupHome([], data.data.second);
}, },
); );
} }
Widget setupHome(List<PlansInfo> plansInfo, List<Groups> groups) { Widget setupHome(List<PlansInfo> plansInfo, List<Groups> groups) {
return Column( return Column(
children: <Widget>[ children: <Widget>[
head(),
Expanded( Expanded(
child: Stack( child: Container(
children: <Widget>[ margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
head(), color: Colors.green,
Expanded ( child: ListView.builder(
child: Container( itemBuilder: (BuildContext context, int index) {
margin: EdgeInsets.fromLTRB(15, 105, 15, 0), Groups group = groups[index];
child: switch (group.groupType) {
// ListView.builder( case 'hot':
// itemBuilder: (BuildContext context, int index) { // return planPopularityView(plansInfo);
// Groups group = groups[index]; // return planNormalEffectiveAttrsView(group);
// switch (group.groupType) { return Container(
// case 'hot': height: 100,
// return planPopularityView(group); color: Colors.red,
// break; );
// case 'normal_attrs': break;
// return planNormalEffectiveAttrsView(group); case 'normal_attrs':
// break; return Container(
// case 'effective_attrs': // height: double.maxFinite,
// return planNormalEffectiveAttrsView(group); color: Colors.yellow,
// break; child: planNormalEffectiveAttrsView(group),
// default: );
// return planNormalEffectiveAttrsView(group); // return planNormalEffectiveAttrsView(group);
// } break;
// }, case 'effective_attrs':
// itemCount: groups.length, return Container(
// ) // height: double.maxFinite,
CustomScrollView( color: Colors.blue,
slivers: <Widget>[ child: planNormalEffectiveAttrsView(group),
SliverList( );
delegate: SliverChildBuilderDelegate( // return planNormalEffectiveAttrsView(group);
(BuildContext context, int index) { break;
return viewList[index]; default:
}, return planNormalEffectiveAttrsView(group);
childCount: viewList.length, }
), },
), itemCount: groups.length,
], )),
),
)
),
],
),
) )
], ],
); );
...@@ -144,55 +139,39 @@ Widget reloadPage () { ...@@ -144,55 +139,39 @@ Widget reloadPage () {
margin: EdgeInsets.fromLTRB(9.5, 0, 9.5, 0), margin: EdgeInsets.fromLTRB(9.5, 0, 9.5, 0),
child: Row(children: <Widget>[ child: Row(children: <Widget>[
// 根据 flex系数,分配剩余空间 // 根据 flex系数,分配剩余空间
Expanded( Expanded(flex: 1, child: headItem(plan)),
flex:1, Expanded(flex: 1, child: headItem(plan))
child: headItem(plan) ]),
), );
Expanded(
flex: 1,
child: headItem(plan)
)
]
),
);
} }
Widget headItem(PlansInfo plan) { Widget headItem(PlansInfo plan) {
return Container( return Container(
child: Stack( child: Stack(children: <Widget>[
children: <Widget>[ Positioned(
Positioned( child: Container(
child: ClipRRect ( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),
child: Container( ),
alignment: Alignment.center, alignment: Alignment.center,
color: Colors.cyan, margin: EdgeInsets.fromLTRB(5.5, 15, 5.5, 15),
margin: EdgeInsets.fromLTRB(5.5, 15, 5.5, 15), child: Image.asset('assets/plan_compare_detail_info_bg.png',
child: Image.asset('plan_compare_detail_info_bg'), fit: BoxFit.cover),
), )),
) Positioned(
), left: 17.5,
Positioned( top: 31,
left: 17.5, child: baseText('11111', 15, Color(0xff333333), bold: true),
top: 31, ),
child: baseText('11111', 15, Color(0xff333333), Positioned(
bold: true), left: 17.5,
), bottom: 31,
child: baseText('¥¥¥¥¥¥¥¥¥¥', 14, Colors.red, bold: true),
Positioned( ),
left: 17.5, ]));
bottom: 31, }
child: baseText('¥¥¥¥¥¥¥¥¥¥', 14, Colors.red,
bold: true),
),
] Widget titleView(String title) {
)
);
}
Widget titleView() {
return Container( return Container(
height: 81, height: 81,
width: screenWidth, width: screenWidth,
...@@ -200,259 +179,190 @@ Widget titleView() { ...@@ -200,259 +179,190 @@ Widget titleView() {
margin: EdgeInsets.fromLTRB(0, 30, 0, 13), margin: EdgeInsets.fromLTRB(0, 30, 0, 13),
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: Container( child: Container(
child: baseText('基础属性', 21, Colors.black, bold: true), child: baseText(title, 21, Colors.black, bold: true),
), ),
); );
} }
Widget planPopularityView() { Widget planPopularityView(List<PlansInfo> planInfo) {
return Container( return Container(
color: Colors.green, color: Colors.green,
height: 265, height: 265,
child: Container ( child: Container(
child: Column( child: Column(children: <Widget>[
children: <Widget>[ titleView('111111'),
titleView(), Row(children: <Widget>[
Row( Expanded(flex: 1, child: planPopularityLeftItem(planInfo[0])),
children: <Widget>[ Expanded(flex: 1, child: planPopularityRightItem(planInfo[1]))
Expanded( ])
flex:1, ])),
child: planPopularityLeftItem()
),
Expanded(
flex: 1,
child: planPopularityRightItem()
)
]
)
]
)
),
); );
} }
Widget planPopularityLeftItem() { Widget planPopularityLeftItem(PlansInfo plan) {
return Container( return Container(
color: Colors.red, color: Colors.red,
// height: 80, // height: 80,
child: child: Expanded(
Expanded( child: Stack(children: <Widget>[
child: Stack( Positioned(
children: <Widget>[ right: 20,
Positioned( top: 12,
right: 20, child: baseText('99%', 21, Color(0xffF25874), bold: true)),
top: 12, Positioned(
child: baseText('99%', 21, Color(0xffF25874), right: 20,
bold: true) top: 33,
), // bottom: 12,
child: baseText('好评率', 12, Color(0xff666666), bold: false),
Positioned( ),
right: 20, Positioned(
top: 33, right: 20,
// bottom: 12, top: 55,
child: baseText('好评率', 12, Color(0xff666666), // bottom: 12,
bold: false), child: FiveStarView(3, 5),
), ),
Positioned(
Positioned( right: 20,
right: 20, top: 98,
top: 55, bottom: 12,
// bottom: 12, child: baseText('13679个', 21, Color(0xffF25874), bold: true),
child: FiveStarView(3,5), ),
), Positioned(
right: 20,
Positioned( top: 112,
right: 20, bottom: 12,
top: 98, child: baseText('销量', 12, Color(0xff666666), bold: false),
bottom: 12, ),
child: baseText('13679个', 21, Color(0xffF25874), Positioned(
bold: true), right: 20,
), top: 132,
bottom: 12,
Positioned( child: baseText('', 12, Color(0xff666666), bold: false),
right: 20, ),
top: 112, ])));
bottom: 12, }
child: baseText('销量', 12, Color(0xff666666),
bold: false),
),
Positioned(
right: 20,
top: 132,
bottom: 12,
child: baseText('', 12, Color(0xff666666),
bold: false),
),
]
)
)
);
}
Widget planPopularityRightItem() {
return Container(
color: Colors.red,
// height: 80,
child:
Expanded(
child: Stack(
children: <Widget>[
Positioned(
left: 20,
top: 12,
child: baseText('99%', 21, Color(0xffF25874),
bold: true)
),
Positioned(
left: 20,
top: 33,
// bottom: 12,
child: baseText('好评率', 12, Color(0xff666666),
bold: false),
),
Positioned(
left: 20,
top: 55,
// bottom: 12,
child: FiveStarView(3,5),
),
Positioned(
left: 20,
top: 98,
bottom: 12,
child: baseText('13679个', 21, Color(0xffF25874),
bold: true),
),
Positioned(
left: 20,
top: 112,
bottom: 12,
child: baseText('销量', 12, Color(0xff666666),
bold: false),
),
Positioned( Widget planPopularityRightItem(PlansInfo plan) {
left: 20, return Container(
top: 132, color: Colors.red,
bottom: 12, // height: 80,
child: baseText('', 12, Color(0xff666666), child: Expanded(
bold: false), child: Stack(children: <Widget>[
), Positioned(
] left: 20,
top: 12,
) child: baseText('99%', 21, Color(0xffF25874), bold: true)),
) Positioned(
); left: 20,
} top: 33,
// bottom: 12,
child: baseText('好评率', 12, Color(0xff666666), bold: false),
),
Positioned(
left: 20,
top: 55,
// bottom: 12,
child: FiveStarView(3, 5),
),
Positioned(
left: 20,
top: 98,
bottom: 12,
child: baseText('13679个', 21, Color(0xffF25874), bold: true),
),
Positioned(
left: 20,
top: 112,
bottom: 12,
child: baseText('销量', 12, Color(0xff666666), bold: false),
),
Positioned(
left: 20,
top: 132,
bottom: 12,
child: baseText('', 12, Color(0xff666666), bold: false),
),
])));
}
Widget planNormalEffectiveAttrsView(Groups groups) { Widget planNormalEffectiveAttrsView(Groups groups) {
List<Widget> list = new List();
list.add(titleView(groups.groupName));
groups.plans.forEach((element) {
list.add(planBaseAttrsView(element));
});
return Container( return Container(
color: Colors.green, color: Colors.green,
child: Column( child:
mainAxisAlignment: MainAxisAlignment.center, Column(mainAxisAlignment: MainAxisAlignment.center, children: list
children: <Widget>[
Expanded( // <Widget>[
child: Stack( // Expanded(
children: <Widget>[ // child: Stack(children: <Widget>[
titleView(), // ,
Expanded ( // Expanded(
child: Container( // child: Container(
margin: EdgeInsets.fromLTRB(0, 68, 0, 0), // margin: EdgeInsets.fromLTRB(0, 68, 0, 0),
child: // child:
ListView.builder( // ListView.builder(
itemBuilder: (c, index) { // shrinkWrap: true,
return planBaseAttrsView(); // physics: NeverScrollableScrollPhysics(),
}, // itemBuilder: (c, index) {
itemCount: 5, // return planBaseAttrsView(groups.plans);
) // },
) // itemCount: 5,
) // )))
] // ]))
) ));
)
]
)
);
} }
Widget planBaseAttrsView() { Widget planBaseAttrsView(Plans plans) {
return Container( return Container(
color: Colors.red, color: Colors.red,
height: 80, height: 80,
child: Row( child: Row(children: <Widget>[
children: <Widget>[ Expanded(flex: 1, child: planBaseAttrsLeftView(plans)),
Expanded( Expanded(flex: 1, child: planBaseAttrsRightView(plans))
flex:1, ]));
child: planBaseAttrsLeftView()
),
Expanded(
flex: 1,
child: planBaseAttrsRightView()
)
]
)
);
} }
Widget planBaseAttrsLeftView() { Widget planBaseAttrsLeftView(Plans plan) {
return Container( return Container(
color: Colors.red, color: Colors.red,
height: 80, height: 80,
child: Stack( child: Stack(children: <Widget>[
children: <Widget>[ Positioned(
Positioned( right: 20,
right: 20, top: 12,
top: 12, child: baseText(plan.attrs[0].attrValue, 14, Color(0xff3FB5AF),
child: baseText('嘻嘻嘻嘻嘻嘻', 14, Color(0xff3FB5AF), bold: true)),
bold: true) Positioned(
), right: 20,
// top: 12,
Positioned( bottom: 12,
right: 20, child: baseText(plan.attrs[0].attrName, 12, Color(0xff666666),
// top: 12, bold: false),
bottom: 12, ),
child: baseText('哈哈哈哈', 12, Color(0xff666666), ]));
bold: false), }
),
]
)
);
}
Widget planBaseAttrsRightView() {
return Container(
color: Colors.red,
height: 80,
child: Stack(
children: <Widget>[
Positioned(
left: 20,
top: 12,
child: baseText('嘻嘻嘻嘻嘻嘻', 14, Color(0xffF25874),
bold: true)
),
Positioned(
left: 20,
// top: 12,
bottom: 12,
child: baseText('哈哈哈哈', 12, Color(0xff666666),
bold: false),
),
] Widget planBaseAttrsRightView(Plans plan) {
return Container(
) color: Colors.red,
); height: 80,
} child: Stack(children: <Widget>[
} Positioned(
\ No newline at end of file left: 20,
top: 12,
child: baseText(plan.attrs[0].attrValue, 14, Color(0xffF25874),
bold: true)),
Positioned(
left: 20,
// top: 12,
bottom: 12,
child: baseText(plan.attrs[0].attrName, 12, Color(0xff666666),
bold: false),
),
]));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment