Commit 44fc10b9 authored by 林生雨's avatar 林生雨

Merge branch 'zx/gmFlutter' into 'test'

Zx/gm flutter

See merge request !22
parents 553ec9d8 2bb4c8a5
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
* @Last Modified by: zx * @Last Modified by: zx
* @Last Modified time: 2020-07-03 13:47:57 * @Last Modified time: 2020-07-03 13:47:57
*/ */
import 'dart:ffi';
import 'dart:math';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gm_flutter/ClueModel/page/PlanCompareDetail/PlanCompareDetailModel.dart'; import 'package:gm_flutter/ClueModel/page/PlanCompareDetail/PlanCompareDetailModel.dart';
...@@ -29,7 +32,6 @@ class PlanCompareDetailPage extends StatefulWidget { ...@@ -29,7 +32,6 @@ class PlanCompareDetailPage extends StatefulWidget {
class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
PlanCompareDetailModel _model = new PlanCompareDetailModel(); PlanCompareDetailModel _model = new PlanCompareDetailModel();
double screenWidth; double screenWidth;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
...@@ -44,10 +46,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -44,10 +46,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
@override @override
Widget buildItem(BuildContext context) { Widget buildItem(BuildContext context) {
screenWidth = MediaQuery screenWidth = MediaQuery.of(context).size.width;
.of(context)
.size
.width;
return Scaffold( return Scaffold(
appBar: baseAppBar( appBar: baseAppBar(
title: "对比详情", title: "对比详情",
...@@ -66,16 +65,10 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -66,16 +65,10 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
initialData: _model.stateLive.data ?? LOADING, initialData: _model.stateLive.data ?? LOADING,
builder: (c, data) { builder: (c, data) {
if (data.data == FAIL) { if (data.data == FAIL) {
return errorItem(MediaQuery return errorItem(MediaQuery.of(context).size.width,
.of(context) MediaQuery.of(context).size.height, () {
.size _model.init(widget._planIds);
.width, });
MediaQuery
.of(context)
.size
.height, () {
_model.init(widget._planIds);
});
} }
if (data.data == LOADING) { if (data.data == LOADING) {
return loadingItem(); return loadingItem();
...@@ -91,66 +84,60 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -91,66 +84,60 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
head(), head(),
Expanded( Expanded(
child: Container( child: Container(
child: StreamBuilder<Pair<int, List<Groups>>>( child: StreamBuilder<Pair<int, List<Groups>>>(
stream: _model.detailLive.stream, stream: _model.detailLive.stream,
initialData: _model.detailLive.data ?? Pair(LOADING, null), initialData: _model.detailLive.data ?? Pair(LOADING, null),
builder: (c, data) { builder: (c, data) {
if (data.data.first == FAIL) { if (data.data.first == FAIL) {
return errorItem(MediaQuery return errorItem(MediaQuery.of(context).size.width,
.of(context) MediaQuery.of(context).size.height, () {
.size _model.init(widget._planIds);
.width, });
MediaQuery }
.of(context) return ListView.builder(
.size itemBuilder: (BuildContext context, int index) {
.height, () { if (index == data.data.second.length * 2 - 1) {
_model.init(widget._planIds); return Container(
}); height: 40,
color: Color(0xffF7F6FA),
);
}
if (index % 2 != 0) {
return Container(
height: 5,
color: Color(0xffF7F6FA),
);
}
int newIndex = (index / 2).floor();
Groups group = data.data.second[newIndex];
Widget widget;
if (group.groupType == 'hot') {
widget = Container(
child: planPopularityView(group),
// height: 100,
// alignment: Alignment.center,
// child: baseText("第一个", 15, Colors.black),
);
} else if (group.groupType == 'normal_attrs') {
widget = Container(
child: planNormalEffectiveAttrsView(group),
);
} else if (group.groupType == 'effective_attrs') {
widget = Container(
child: planNormalEffectiveAttrsView(group),
);
} else {
widget = planNormalEffectiveAttrsView(group);
} }
return ListView.builder( return Container(
itemBuilder: (BuildContext context, int index) { margin: EdgeInsets.only(left: 15, right: 15),
if (index == data.data.second.length * 2 - 1) { child: widget,
return Container(
height: 40,
color: Color(0xffF7F6FA),
);
}
if (index % 2 != 0) {
return Container(
height: 5,
color: Color(0xffF7F6FA),
);
}
int newIndex = (index / 2).floor();
Groups group = data.data.second[newIndex];
Widget widget;
if (group.groupType == 'hot') {
widget = Container(
child: planPopularityView(group),
// height: 100,
// alignment: Alignment.center,
// child: baseText("第一个", 15, Colors.black),
);
} else if (group.groupType == 'normal_attrs') {
widget = Container(
child: planNormalEffectiveAttrsView(group),
);
} else if (group.groupType == 'effective_attrs') {
widget = Container(
child: planNormalEffectiveAttrsView(group),
);
} else {
widget = planNormalEffectiveAttrsView(group);
}
return Container(
margin: EdgeInsets.only(left: 15, right: 15),
child: widget,
);
},
itemCount: data.data.second.length * 2,
); );
}), },
)) itemCount: data.data.second.length * 2,
);
}),
))
], ],
); );
} }
...@@ -181,34 +168,32 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -181,34 +168,32 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
PlansInfo planinfo = data.data.second[index]; PlansInfo planinfo = data.data.second[index];
return Container( return Container(
child: Stack(children: <Widget>[ child: Stack(children: <Widget>[
Positioned( Positioned(
top: 8, top: 8,
left: index == 0 ? 0 : 5.5, left: index == 0 ? 0 : 5.5,
child: Container( child: Container(
height: 75, height: 75,
width: (screenWidth - 30 - 11) / 2, width: (screenWidth - 30 - 11) / 2,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(7),
child: Image.asset( child: Image.asset('assets/plan_compare_detail_info_bg.png',
'assets/plan_compare_detail_info_bg.png', fit: BoxFit.cover),
fit: BoxFit.cover), ),
), )),
)), Positioned(
Positioned( left: 12,
left: 12, top: 24,
top: 24, child:
child:
baseText(planinfo.planName, 15, Color(0xff333333), bold: true), baseText(planinfo.planName, 15, Color(0xff333333), bold: true),
), ),
Positioned( Positioned(
left: 12, left: 12,
top: 48, top: 48,
child: baseText( child: baseText('¥' + planinfo.minPrice + '-' + planinfo.maxPrice,
'¥' + planinfo.minPrice + '-' + planinfo.maxPrice, 14, Colors.red,
14, Colors.red, bold: true),
bold: true), ),
), ]));
]));
}, },
); );
} }
...@@ -260,12 +245,14 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -260,12 +245,14 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
return Container( return Container(
height: 170, height: 170,
child: Row(children: <Widget>[ child: Row(children: <Widget>[
Expanded(flex: 1, child: planPopularityLeftItem(groups.plans[0])), Expanded(
Expanded(flex: 1, child: planPopularityRightItem(groups.plans[1])) flex: 1, child: planPopularityLeftItem(groups.plans[0], groups)),
Expanded(
flex: 1, child: planPopularityRightItem(groups.plans[1], groups))
])); ]));
} }
Widget planPopularityLeftItem(Plans plan) { Widget planPopularityLeftItem(Plans plan, Groups groups) {
return Container( return Container(
height: 170, height: 170,
child: Stack(children: <Widget>[ child: Stack(children: <Widget>[
...@@ -317,7 +304,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -317,7 +304,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
Positioned( Positioned(
right: 0, right: 0,
top: 0, top: 0,
width: 95 * 0.7, width: 95 * sellCount(0, groups.plans[1]),
height: 7, height: 7,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(3.5), borderRadius: BorderRadius.circular(3.5),
...@@ -331,7 +318,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -331,7 +318,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
])); ]));
} }
Widget planPopularityRightItem(Plans plan) { Widget planPopularityRightItem(Plans plan, Groups groups) {
return Container( return Container(
height: 170, height: 170,
child: Stack(children: <Widget>[ child: Stack(children: <Widget>[
...@@ -389,7 +376,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -389,7 +376,7 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
Positioned( Positioned(
left: 0, left: 0,
top: 0, top: 0,
width: 95 * 0.3, width: 95 * sellCount(1, groups.plans[0]),
height: 7, height: 7,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(3.5), borderRadius: BorderRadius.circular(3.5),
...@@ -460,4 +447,16 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> { ...@@ -460,4 +447,16 @@ class PlanCompareDetailPageState extends BaseState<PlanCompareDetailPage> {
), ),
])); ]));
} }
double sellCount(int index, Plans anotherPlans) {
Groups popularity = _model.detailLive.data.second[0];
Plans plans = popularity.plans[index];
int salesCount = int.parse(plans.salesCount);
int anSalesCount = int.parse(plans.salesCount);
if (salesCount >= anSalesCount) {
return 1.0;
} else {
return anSalesCount / salesCount;
}
}
} }
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