Commit 353d5b11 authored by 林生雨's avatar 林生雨

Merge branch 'zx/gmFlutter' into 'test'

Zx/gm flutter

See merge request !6
parents c22fb1c0 65f6b83c
...@@ -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();
} }
} }
...@@ -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-01 22:11:20 * @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,6 +14,7 @@ import 'package:gm_flutter/ClueModel/server/entity/PlanCompareDetail.dart'; ...@@ -14,6 +14,7 @@ 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
...@@ -22,26 +23,17 @@ class PlanCompareDetailPage extends StatefulWidget { ...@@ -22,26 +23,17 @@ class PlanCompareDetailPage extends StatefulWidget {
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();
} }
...@@ -57,82 +49,86 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -57,82 +49,86 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
}), }),
body: Container( body: Container(
child: child:
// head(),
// planPopularityView() // planPopularityView()
// planNormalEffectiveAttrsView() // planNormalEffectiveAttrsView()
// setupHome([], []), // setupHome([], []),
reloadPage(), 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(
children: <Widget>[
head(plansInfo),
Expanded (
child: Container( child: Container(
margin: EdgeInsets.fromLTRB(15, 105, 15, 0), margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
child: color: Colors.green,
// ListView.builder( child: ListView.builder(
// itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
// Groups group = groups[index]; Groups group = groups[index];
// switch (group.groupType) { switch (group.groupType) {
// case 'hot': case 'hot':
// return planPopularityView(group); // return planPopularityView(plansInfo);
// break;
// case 'normal_attrs':
// return planNormalEffectiveAttrsView(group); // return planNormalEffectiveAttrsView(group);
// break; return Container(
// case 'effective_attrs': height: 100,
color: Colors.red,
);
break;
case 'normal_attrs':
return Container(
// height: double.maxFinite,
color: Colors.yellow,
child: planNormalEffectiveAttrsView(group),
);
// return planNormalEffectiveAttrsView(group); // return planNormalEffectiveAttrsView(group);
// break; break;
// default: case 'effective_attrs':
return Container(
// height: double.maxFinite,
color: Colors.blue,
child: planNormalEffectiveAttrsView(group),
);
// return planNormalEffectiveAttrsView(group); // return planNormalEffectiveAttrsView(group);
// } break;
// }, default:
// itemCount: groups.length, return planNormalEffectiveAttrsView(group);
// ) }
CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return viewList[index];
}, },
childCount: viewList.length, itemCount: groups.length,
), )),
),
],
),
)
),
],
),
) )
], ],
); );
} }
Widget head(List<PlansInfo> plansInfo) { Widget head() {
PlansInfo plan; PlansInfo plan;
return Container( return Container(
// key: keyTop, // key: keyTop,
...@@ -143,61 +139,39 @@ Widget reloadPage () { ...@@ -143,61 +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: Container(
margin: EdgeInsets.fromLTRB(5.5, 15, 5.5, 15),
width: (screenWidth - 41) / 2.0,
// child: Text('1111111'),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0), borderRadius: BorderRadius.circular(15),
image:
DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://pic.igengmei.com/2018/09/11/1513/b7e825a4e4c1-w")
)
)
),
), ),
alignment: Alignment.center,
margin: EdgeInsets.fromLTRB(5.5, 15, 5.5, 15),
child: Image.asset('assets/plan_compare_detail_info_bg.png',
fit: BoxFit.cover),
)),
Positioned( Positioned(
left: 17.5, left: 17.5,
top: 31, top: 31,
child: baseText('11111', 15, Color(0xff333333), child: baseText('11111', 15, Color(0xff333333), bold: true),
bold: true),
), ),
Positioned( Positioned(
left: 17.5, left: 17.5,
bottom: 31, bottom: 31,
child: baseText('¥¥¥¥¥¥¥¥¥¥', 14, Colors.red, child: baseText('¥¥¥¥¥¥¥¥¥¥', 14, Colors.red, bold: true),
bold: true),
), ),
]));
}
] Widget titleView(String title) {
)
);
}
Widget titleView() {
return Container( return Container(
height: 81, height: 81,
width: screenWidth, width: screenWidth,
...@@ -205,259 +179,190 @@ Widget titleView() { ...@@ -205,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(
children: <Widget>[
Positioned( Positioned(
right: 20, right: 20,
top: 12, top: 12,
child: baseText('99%', 21, Color(0xffF25874), child: baseText('99%', 21, Color(0xffF25874), bold: true)),
bold: true)
),
Positioned( Positioned(
right: 20, right: 20,
top: 33, top: 33,
// bottom: 12, // bottom: 12,
child: baseText('好评率', 12, Color(0xff666666), child: baseText('好评率', 12, Color(0xff666666), bold: false),
bold: false),
), ),
Positioned( Positioned(
right: 20, right: 20,
top: 55, top: 55,
// bottom: 12, // bottom: 12,
child: FiveStarView(3,5), child: FiveStarView(3, 5),
), ),
Positioned( Positioned(
right: 20, right: 20,
top: 98, top: 98,
bottom: 12, bottom: 12,
child: baseText('13679个', 21, Color(0xffF25874), child: baseText('13679个', 21, Color(0xffF25874), bold: true),
bold: true),
), ),
Positioned( Positioned(
right: 20, right: 20,
top: 112, top: 112,
bottom: 12, bottom: 12,
child: baseText('销量', 12, Color(0xff666666), child: baseText('销量', 12, Color(0xff666666), bold: false),
bold: false),
), ),
Positioned( Positioned(
right: 20, right: 20,
top: 132, top: 132,
bottom: 12, bottom: 12,
child: baseText('', 12, Color(0xff666666), child: baseText('', 12, Color(0xff666666), bold: false),
bold: false),
), ),
] ])));
}
)
)
);
}
Widget planPopularityRightItem() { Widget planPopularityRightItem(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(
children: <Widget>[
Positioned( Positioned(
left: 20, left: 20,
top: 12, top: 12,
child: baseText('99%', 21, Color(0xffF25874), child: baseText('99%', 21, Color(0xffF25874), bold: true)),
bold: true)
),
Positioned( Positioned(
left: 20, left: 20,
top: 33, top: 33,
// bottom: 12, // bottom: 12,
child: baseText('好评率', 12, Color(0xff666666), child: baseText('好评率', 12, Color(0xff666666), bold: false),
bold: false),
), ),
Positioned( Positioned(
left: 20, left: 20,
top: 55, top: 55,
// bottom: 12, // bottom: 12,
child: FiveStarView(3,5), child: FiveStarView(3, 5),
), ),
Positioned( Positioned(
left: 20, left: 20,
top: 98, top: 98,
bottom: 12, bottom: 12,
child: baseText('13679个', 21, Color(0xffF25874), child: baseText('13679个', 21, Color(0xffF25874), bold: true),
bold: true),
), ),
Positioned( Positioned(
left: 20, left: 20,
top: 112, top: 112,
bottom: 12, bottom: 12,
child: baseText('销量', 12, Color(0xff666666), child: baseText('销量', 12, Color(0xff666666), bold: false),
bold: false),
), ),
Positioned( Positioned(
left: 20, left: 20,
top: 132, top: 132,
bottom: 12, bottom: 12,
child: baseText('', 12, Color(0xff666666), child: baseText('', 12, Color(0xff666666), bold: false),
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(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Stack(
children: <Widget>[
titleView(),
Expanded (
child: Container(
margin: EdgeInsets.fromLTRB(0, 68, 0, 0),
child: child:
ListView.builder( Column(mainAxisAlignment: MainAxisAlignment.center, children: list
itemBuilder: (c, index) {
return planBaseAttrsView(); // <Widget>[
}, // Expanded(
itemCount: 5, // child: Stack(children: <Widget>[
) // ,
) // Expanded(
) // child: Container(
] // margin: EdgeInsets.fromLTRB(0, 68, 0, 0),
) // child:
) // ListView.builder(
// shrinkWrap: true,
] // physics: NeverScrollableScrollPhysics(),
) // itemBuilder: (c, index) {
); // 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('嘻嘻嘻嘻嘻嘻', 14, Color(0xff3FB5AF), child: baseText(plan.attrs[0].attrValue, 14, Color(0xff3FB5AF),
bold: true) bold: true)),
),
Positioned( Positioned(
right: 20, right: 20,
// top: 12, // top: 12,
bottom: 12, bottom: 12,
child: baseText('哈哈哈哈', 12, Color(0xff666666), child: baseText(plan.attrs[0].attrName, 12, Color(0xff666666),
bold: false), bold: false),
), ),
] ]));
)
);
} }
Widget planBaseAttrsRightView() {
Widget planBaseAttrsRightView(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(
left: 20, left: 20,
top: 12, top: 12,
child: baseText('嘻嘻嘻嘻嘻嘻', 14, Color(0xffF25874), child: baseText(plan.attrs[0].attrValue, 14, Color(0xffF25874),
bold: true) bold: true)),
),
Positioned( Positioned(
left: 20, left: 20,
// top: 12, // top: 12,
bottom: 12, bottom: 12,
child: baseText('哈哈哈哈', 12, Color(0xff666666), child: baseText(plan.attrs[0].attrName, 12, Color(0xff666666),
bold: false), 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