Commit 62c5f3da authored by 汪林玲's avatar 汪林玲

升级到flutter2.5.1

parents
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
pubspec.lock
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: 84f3d28555368a70270e9ac8390a9441df95e752
channel: stable
project_type: package
{
"dart.flutterSdkPath": "/Users/qiaomeng/flutter_2.5.1"
}
\ No newline at end of file
## [1.0.0] - TODO: 支持Flutter 2.5.1.
* TODO: 支持Flutter当前最新版本(2021-10-16).
\ No newline at end of file
# xiaoxiong_price_module
A new Flutter package project.
## Getting Started
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
import 'package:flutter/foundation.dart';
class NotifyEventType {
NotifyEventEnum eventType;
NotifyEventType({@required this.eventType});
}
enum NotifyEventEnum {
PlatformIconEnum,
MeiQiaEnum,
}
\ No newline at end of file
class PlatformIconEvent {
Map<int,dynamic> map;
PlatformIconEvent({this.map = const {}});
}
\ No newline at end of file
import 'package:flutter/material.dart';
abstract class IDSAction<VM> {
VM vm;
void initState();
///
/// 当页面初始化的时候调用
/// context 上下文的对象
///
void initBuilder(BuildContext context) {}
///
/// 组件被销毁时候调用;
/// 通常在该方法中执行一些资源的释放工作,比如监听器的移除,channel的销毁等
///
void dispose() {}
}
import 'package:flutter/cupertino.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:provider/provider.dart';
class DSProvider<VO extends IDSModel> extends ChangeNotifierProvider<VO> {
final VO vo;
final Widget Function(
BuildContext context,
VO value,
Widget child,
) builderWidget;
DSProvider.value({
@required this.vo,
@required this.builderWidget,
}) : super.value(
value: vo,
child: Consumer<VO>(
builder: builderWidget,
),
);
}
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:price_module/framework/action/ds_action.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:provider/provider.dart';
class DSProviderWidget<VM extends IDSModel, T extends IDSAction<VM>> extends StatefulWidget {
final T dsAction;
final Widget child;
final Widget Function(BuildContext context,Widget child) builder;
const DSProviderWidget({Key key,@required this.dsAction,@required this.builder,this.child}):super(key:key);
@override
_DSProviderWidgetState<VM,T> createState() => _DSProviderWidgetState<VM,T>();
}
class _DSProviderWidgetState<VM extends IDSModel,T extends IDSAction<VM>> extends State<DSProviderWidget<VM,T>> {
T action;
Widget get _child => widget.child;
@override
void initState() {
action = widget.dsAction;
action?.initState();
super.initState();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<VM>.value(
value: action.vm,
child: Consumer<VM>(
builder:(context,vm,child){
action?.initBuilder(context);
return widget.builder(context,child);
},
child: _child,
),
);
}
@override
void dispose() {
action?.dispose();
super.dispose();
}
}
\ No newline at end of file
class DSNetException implements Exception {
final String message;
final int code;
@pragma("vm:entry-point")
const DSNetException({this.message = "", this.code});
String toString() {
Map<String,dynamic> data = {'message':this.message,'code':this.code};
return "$data";
}
}
\ No newline at end of file
import 'package:flutter/foundation.dart';
abstract class IDSModel extends ChangeNotifier {
///
/// 当前页面的状态[viewState]
///
DSViewState viewState = DSViewState.idle;
void notifyListener([bool notify = true]) {
if (notify) {
super.notifyListeners();
}
}
}
/// 页面状态类型
enum DSViewState {
idle, //加载完成
busy, //加载中
empty, //无数据
error, //加载失败
unAuthorized, //未登录
}
import 'package:flutter/material.dart';
import 'package:price_module/eventbus/notify_event_type.dart';
import 'package:price_module/eventbus/platform_icon_event.dart';
import 'package:price_module/framework/action/ds_action.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:price_module/page/model/details/index.dart';
import 'package:price_module/page/service/details/index.dart';
import 'package:price_module/utils/event_bus_utils.dart';
import 'package:price_module/utils/time_utils.dart';
import 'package:xiaoxiong_repository/app_xiaoxiong_repository.dart';
import 'package:xiaoxiong_repository/entity/turn_chain_entity.dart';
import 'package:price_module/framework/exception/ds_net_exception.dart';
abstract class IPriceDetailsAction<PriceDetailsVo>
extends IDSAction<PriceDetailsVo> {
///
/// 商品举报
/// [reportType] 举报类型
///
void report({String reportType});
///
/// 用户点赞
/// [status] 点赞的状态
///
void userLike({bool status = true});
///
/// 用户收藏
/// [status] 收藏的状态
///
void userCollect({bool status = true});
///
/// 用户点击购买
///
Future<TurnChainEntity> goToBuyEvent();
///
/// 凑单购买
/// [itemId] 商品Id
/// [platform] 平台
///
///
Future<TurnChainEntity> goToBuyItemId({String itemId, String platform});
///
/// 获取举报配置信息
///
List<dynamic> get sellReportList;
}
class PriceDetailsAction extends IPriceDetailsAction<PriceDetailsVo> {
PriceDetailsService _detailsService = PriceDetailsService();
IPriceDetailsActionDelegate _actionDelegate;
Map<int, dynamic> _platformIconMap;
List<dynamic> _sellReportList = [];
@override
List<dynamic> get sellReportList => _sellReportList;
PriceDetailsAction(
{Map<String, dynamic> param, IPriceDetailsActionDelegate delegate}) {
eventBus.on<PlatformIconEvent>().listen((event) {
_platformIconMap = event.map;
});
eventBus.fire(NotifyEventType(eventType: NotifyEventEnum.PlatformIconEnum));
this._actionDelegate = delegate;
this.vm = PriceDetailsVo(productId: param['productId']);
if (param['src'] != null && param['src'] is String) {
this.vm.itemPic = [param['src']];
}
if (param['title'] != null && param['title'] is String) {
this.vm.itemTitle = param['title'];
}
if (param['sellReportList'] is List) {
_sellReportList = List<dynamic>.from(param['sellReportList']);
try {
this.vm.reports =
List<ReportModel>.generate(sellReportList.length, (index) {
Map<String, dynamic> sellReport =
Map<String, dynamic>.from(sellReportList[index]);
List<dynamic> subList = List<dynamic>.from(sellReport['sub']);
return ReportModel(
text: sellReport['text'],
value: sellReport['value'],
sub: List<ReportModel>.generate(subList.length, (index) {
Map<String, dynamic> sellSUb =
Map<String, dynamic>.from(subList[index]);
return ReportModel(
sub: [], text: sellSUb['text'], value: sellSUb['value']);
}));
});
} catch (e) {
print(e);
}
}
}
@override
void report({String reportType}) async {
_detailsService
.report(id: this.vm.productId, reportType: reportType)
.asStream()
.first
.then((value) {
if (value['code'] == 2000) {
_actionDelegate?.showTipsMsg(msg: '举报成功,感谢您的反馈!');
}
});
}
bool disableLike = false, disableCollect = false;
@override
void userLike({bool status = true}) {
if (disableLike) {
return;
}
disableLike = true;
_detailsService
.userLike(
markId: this.vm.productId,
platform: this.vm.platform,
status: status ? '2' : '1')
.asStream()
.first
.then((value) {
if (value['code'] == 2000) {
if (status) {
try {
this.vm.likeTimes = '${int.parse(this.vm.likeTimes) - 1}';
} catch (e) {}
} else {
try {
this.vm.likeTimes = '${int.parse(this.vm.likeTimes) + 1}';
} catch (e) {}
}
this.vm.isLike = !status;
this.vm.notifyListener(true);
}
})
.catchError((error) {})
.whenComplete(() {
disableLike = false;
});
}
@override
void userCollect({bool status = true}) {
if (disableCollect) {
return;
}
disableCollect = true;
_detailsService
.userCollect(
itemId: this.vm.productId,
platform: this.vm.platform,
status: status ? '2' : '1')
.asStream()
.first
.then((value) {
if (value['code'] == 2000) {
if (!status) {
_actionDelegate?.showTipsMsg(msg: '收藏成功');
}
if (status) {
try {
this.vm.collegeTimes = '${int.parse(this.vm.collegeTimes) - 1}';
} catch (e) {}
} else {
try {
this.vm.collegeTimes = '${int.parse(this.vm.collegeTimes) + 1}';
} catch (e) {}
}
this.vm.isFavorites = !status;
this.vm.notifyListener(true);
}
})
.catchError((error) {})
.whenComplete(() {
disableCollect = false;
});
}
@override
void initState() async {
this.vm.viewState = DSViewState.busy;
_detailsService
.qryProductDetails(productId: this.vm.productId)
.asStream()
.first
.then((value) {
this.vm.viewState = DSViewState.idle;
this.vm.itemPic = value.itemPic;
this.vm.itemId = value.itemId;
this.vm.platform = value.platform;
this.vm.platformText = _getPlatformName(int.parse(value.platform));
this.vm.itemTitle = value.itemTitle;
this.vm.subTitle = value.subTitle;
this.vm.status = value.status;
this.vm.likeTimes = value.likeTimes;
this.vm.collegeTimes = value.collegeTimes;
this.vm.buttonText = value.buttonText;
this.vm.description = value.description;
this.vm.releaseTime = value.releaseTime;
this.vm.couponText = value.couponText;
this.vm.checkText = value.checkText;
this.vm.coupons = value.coupons;
this.vm.shareUrl = value.shareUrl;
this.vm.price = value.price;
this.vm.endPrice = value.endPrice;
this.vm.shareMessage = value.shareMessage;
this.vm.isLike = value.isLike;
this.vm.isFavorites = value.isFavorites;
this.vm.isOverdue = value.isOverdue;
this.vm.shopTitle = value.shopTitle;
this.vm.rebate = value.rebate;
this.vm.collectOrders = value.collectOrders;
this.vm.newItemInfo = value.newItemInfo;
}).catchError((error) {
this.vm.viewState = DSViewState.idle;
}).catchError((error) {
this.vm.viewState = DSViewState.error;
}).whenComplete(() {
_detailsService
.getSellingRecommends(
excludeId: this.vm.productId,
keywords: this.vm.itemTitle,
page: 1,
pagesize: 7,
)
.then((value) {
if (value.isSuccess) {
this.vm.productEntitys = value.data;
this.vm.productEntitys.forEach((ele) {
ele.releaseTime = TimeUtils.formatTime(timestamp: ele.releaseTime);
ele.platform = _getPlatformName(int.parse(ele.platform));
});
}
}).catchError((error) {
print(error);
}).whenComplete(() {
this.vm.notifyListener(true);
});
});
}
///
/// 将平台的id,转换为平台的名称
/// [platform] 平台id
///
String _getPlatformName(int platform) {
if (_platformIconMap != null && _platformIconMap[platform] is Map) {
Map<String, dynamic> platformMap =
Map<String, dynamic>.from(_platformIconMap[platform]);
return platformMap['name'] ?? '';
}
return '';
}
@override
Future<TurnChainEntity> goToBuyEvent() async {
DSResponseObject<TurnChainEntity> resObject = await _detailsService
.turnChainForItemId(
itemId: this.vm.itemId, platform: this.vm.platform, type: '6')
.asStream()
.first;
if (resObject.isSuccess) {
return resObject.data;
}
throw DSNetException(code: resObject.code, message: resObject.msg);
}
@override
Future<TurnChainEntity> goToBuyItemId({
String itemId,
String platform,
}) async {
if (platform == null) {
platform = this.vm.platform;
}
DSResponseObject<TurnChainEntity> resObject = await _detailsService
.turnChainForItemId(itemId: itemId, platform: platform, type: '6')
.asStream()
.first;
if (resObject.isSuccess) {
return resObject.data;
}
throw DSNetException(code: resObject.code, message: resObject.msg);
}
}
///
/// 代理类,类似接口
///
abstract class IPriceDetailsActionDelegate {
void showTipsMsg({@required String msg});
}
import 'package:price_module/eventbus/notify_event_type.dart';
import 'package:price_module/eventbus/platform_icon_event.dart';
import 'package:price_module/framework/action/ds_action.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:price_module/page/model/discount/index.dart';
import 'package:price_module/utils/event_bus_utils.dart';
import 'package:price_module/utils/time_utils.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
import 'package:xiaoxiong_repository/repository/price_repository.dart';
abstract class IPriceDiscountAction<PriceDiscountVo>
extends IDSAction<PriceDiscountVo> {
IPriceDiscountAction();
///
/// 加载数据
///
void reloadData();
///
/// 加载更多
///
void onLoad();
///
/// 获取当前数据
///
PriceDiscountVo get getVo;
}
class PriceDiscountAction extends IPriceDiscountAction<PriceDiscountVo> {
PriceRepository _priceRepository = PriceRepository.get();
Map<int, dynamic> _platformIconMap;
IPriceDiscountDelegate _discountDelegate;
Map<String, dynamic> _pageParam;
PriceDiscountAction({
IPriceDiscountDelegate delegate,
Map<String, dynamic> pageParam,
}) {
this._pageParam = pageParam;
_discountDelegate = delegate;
this.vm = PriceDiscountVo();
eventBus.on<PlatformIconEvent>().listen((event) {
_platformIconMap = event.map;
});
eventBus.fire(NotifyEventType(eventType: NotifyEventEnum.PlatformIconEnum));
}
@override
void initState() {
this._getSellingRecommends(pagesize: 10, page: 1, isFirst: true);
}
int currentPage = 1;
@override
void reloadData() {
this._getSellingRecommends(
page: 1,
pagesize: 10,
isRefresh: true,
);
this.vm.notifyListener();
}
@override
void onLoad() {
this._getSellingRecommends(
page: currentPage + 1,
pagesize: 10,
isLoad: true,
);
}
///
/// 查询数据
///
void _getSellingRecommends({
int page = 1,
int pagesize = 10,
bool isFirst = false,
bool isLoad = false,
bool isRefresh = false,
}) {
currentPage = page;
if (isFirst) {
this.vm.viewState = DSViewState.busy;
}
_priceRepository
.getSellingRecommends(
keywords: _pageParam['keywords'],
excludeId: _pageParam['excludeId'],
page: page,
pagesize: pagesize,
)
.then((value) {
if (value.isSuccess) {
List<ProductItemEntity> productEntitys = value.data;
productEntitys.forEach((ele) {
ele.releaseTime = TimeUtils.formatTime(timestamp: ele.releaseTime);
ele.platform = _getPlatformName(int.parse(ele.platform));
});
if (isLoad) {
if (this.vm.productEntitys == null) {
this.vm.productEntitys = List<ProductItemEntity>.empty(growable: true);
}
this.vm.productEntitys.addAll(productEntitys);
} else {
this.vm.productEntitys = productEntitys;
if (this.vm.productEntitys.isEmpty) {
this.vm.viewState = DSViewState.empty;
} else {
this.vm.viewState = DSViewState.idle;
}
}
}
if (isLoad) {
_discountDelegate.onLoadComplete(isLoading: true);
} else if (isRefresh) {
_discountDelegate.onLoadComplete(isLoading: false);
}
}).catchError((error) {
this.vm.viewState = DSViewState.error;
if (isLoad) {
_discountDelegate.onloadFailed(isLoading: true);
} else if (isRefresh) {
_discountDelegate.onloadFailed(isLoading: false);
}
}).whenComplete(() {
this.vm.notifyListener();
});
}
///
/// 将平台的id,转换为平台的名称
/// [platform] 平台id
///
String _getPlatformName(int platform) {
if (_platformIconMap != null && _platformIconMap[platform] is Map) {
Map<String, dynamic> platformMap =
Map<String, dynamic>.from(_platformIconMap[platform]);
return platformMap['name'] ?? '';
}
return '';
}
@override
PriceDiscountVo get getVo => this.vm;
}
///
/// 代理类,类似接口
///
abstract class IPriceDiscountDelegate {
///
/// 数据加载完成
///
void onLoadComplete({bool isLoading = true});
///
/// 数据加载失败
///
void onloadFailed({bool isLoading = true, String msg});
}
import 'package:price_module/framework/action/ds_action.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:price_module/page/model/index.dart';
import 'package:price_module/utils/time_utils.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
import 'package:xiaoxiong_repository/repository/price_repository.dart';
abstract class IPriceAction<PriceVo> extends IDSAction<PriceVo> {
///
/// 代理设置
///
IPriceAction({IPriceActionDelegate delegate, bool isGrid});
///
/// 设置分类参数
///
void setPriceCategory(
{List<dynamic> sellingTabList,
List<dynamic> priceCategory,
Map<int, dynamic> platformIconMap,
String keywords});
///
/// 获取分类Tab
///
TabListVo getTabListVo();
///
/// 获取快捷分类列表
///
List<dynamic> get sellingTabs;
///
/// 获取产品列表
///
ProductListVo getProductListVo();
///
/// 关闭Tab
///
void closeTab();
///
/// 重置筛选条件
///
void resetProductList();
///
/// 查询筛选条件
///
void qryProductListEvent({String keywords, int page});
///
/// 刷新
///
void onRefresh();
///
/// 加载更多
///
void loadMore();
}
class PriceAction extends IPriceAction<PriceVo> {
PriceRepository _repository = PriceRepository.get();
Map<int, dynamic> platformIconMap;
String keywords;
bool isGrid = false;
IPriceActionDelegate delegate;
PriceAction({this.delegate, this.isGrid}) : super(delegate: delegate);
@override
void initState() async {
if (this.vm == null) {
this.vm = PriceVo();
}
if (this.vm?.productListVo == null) {
this.vm?.productListVo = ProductListVo();
}
this.vm?.productListVo?.isGrid = isGrid;
this.vm?.productListVo?.viewState = DSViewState.busy;
}
@override
List<dynamic> get sellingTabs => this.vm.sellingTabs ?? [];
@override
void setPriceCategory(
{List<dynamic> sellingTabList,
List<dynamic> priceCategory,
Map<int, dynamic> platformIconMap,
String keywords}) {
this.platformIconMap = platformIconMap;
this.page = 1;
if (keywords != null && keywords.isNotEmpty) {
isGrid = true;
}
this.keywords = keywords;
if (this.vm == null) {
this.vm = PriceVo();
}
if (this.vm.tabListVo == null) {
this.vm.tabListVo = TabListVo();
}
this.vm.sellingTabs = sellingTabList;
dynamic data = this
.vm
.sellingTabs
?.singleWhere((ele) => ele['is_default'] == '1', orElse: () => null);
if (data != null && data is Map<String, dynamic>) {
this.vm.tabListVo.sellTab = Map<String, dynamic>.from(data);
}
if (priceCategory != null) {
List<TabVo> tabList = List<TabVo>.empty(growable: true);
priceCategory.forEach((ele) {
Map<String, dynamic> categoryMap = Map<String, dynamic>.from(ele);
tabList.add(TabVo.fromJson(
'${categoryMap['type']}', Map<String, dynamic>.from(ele)));
});
TabListVo tabListVo = this.vm.tabListVo;
tabListVo.tabList = tabList;
this.vm.tabListVo = tabListVo;
}
TabListVo tabListVo = this.vm.tabListVo;
String categoryId;
if (tabListVo.sellTab != null && tabListVo.sellTab['id'] != null) {
categoryId = "${tabListVo.sellTab['id']}";
}
_qryProductList(keywords: keywords, categoryId: categoryId);
}
@override
TabListVo getTabListVo() {
return this.vm.tabListVo ?? TabListVo();
}
@override
ProductListVo getProductListVo() {
return this.vm?.productListVo ?? ProductListVo(productList: []);
}
///
/// 重置筛选条件
///
@override
void resetProductList() async {
for (TabVo item in this.vm.tabListVo?.tabList ?? []) {
item.selected = null;
item.open = false;
}
this.vm.tabListVo?.sellTab = null;
this.vm.tabListVo?.notifyListener(true);
_qryProductList(keywords: this.keywords);
}
///
/// 过滤筛选条件
///
@override
void qryProductListEvent({String keywords, int page = 1}) async {
if (keywords != null) {
this.keywords = keywords;
}
List<dynamic> filters;
this.vm.tabListVo?.tabList?.forEach((ele) {
if (filters == null) {
filters = List<dynamic>.empty(growable: true);
}
if (ele.selected != null) {
Map<String, dynamic> data;
if (ele.keyName == 'category') {
data = {
'key_name': ele.keyName,
'key_value': '${ele.selected['id']}'
};
} else if (ele.keyName == 'price_section') {
data = {
'key_name': ele.keyName,
'key_value': ele.selected['price_section']
};
} else {
data = {
'key_name': ele.keyName,
'key_value': '${ele.selected['type']}'
};
}
if (data != null && data.isNotEmpty) {
filters.add(data);
}
}
});
TabListVo tabListVo = this.vm.tabListVo;
String categoryId;
if (tabListVo.sellTab != null && tabListVo.sellTab['id'] != null) {
categoryId = "${tabListVo.sellTab['id']}";
}
_qryProductList(
keywords: this.keywords,
filters: filters,
page: page,
categoryId: categoryId);
}
@override
void closeTab() {
TabListVo tabListVo = this.vm.tabListVo;
tabListVo.tabList.forEach((ele) {
ele.open = false;
});
tabListVo.notifyListener(true);
}
String getPlatformName(int platform) {
if (platformIconMap != null && platformIconMap[platform] is Map) {
Map<String, dynamic> platformMap =
Map<String, dynamic>.from(platformIconMap[platform]);
return platformMap['name'] ?? '';
}
return '';
}
void _qryProductList(
{int page = 1,
int pagesize = 10,
String keywords,
String categoryId,
List<dynamic> filters}) async {
this.page = page ?? 1;
await _repository
.qryProductList(
page: page,
pagesize: pagesize,
keywords: keywords,
categoryId: categoryId,
filters: filters,
)
.then((value) {
this.vm?.productListVo?.viewState = DSViewState.idle;
if (page == 1) {
List<ProductItemEntity> productList = [];
if (value.isSuccess) {
productList = value.data;
productList.forEach((ele) {
ele.releaseTime = TimeUtils.formatTime(timestamp: ele.releaseTime);
ele.platform = getPlatformName(int.parse(ele.platform));
});
}
this.vm?.productListVo?.productList = productList;
} else {
List<ProductItemEntity> productList = [];
if (value.isSuccess) {
productList = value.data;
productList.forEach((ele) {
ele.releaseTime = TimeUtils.formatTime(timestamp: ele.releaseTime);
ele.platform = getPlatformName(int.parse(ele.platform));
});
this.vm?.productListVo?.productList?.addAll(productList);
}
}
delegate?.onLoadComplete();
}).catchError((error) {
this.vm?.productListVo?.viewState = DSViewState.error;
delegate?.onloadFailed();
}).whenComplete(() {
this.vm?.productListVo?.notifyListener(true);
});
}
int page = 1;
@override
void loadMore() {
qryProductListEvent(page: page + 1);
}
@override
void onRefresh() {
qryProductListEvent(page: 1);
}
}
///
/// 代理类,类似接口
///
abstract class IPriceActionDelegate {
///
/// 数据加载完成
///
void onLoadComplete();
///
/// 数据加载失败
///
void onloadFailed({String msg});
}
import 'package:price_module/framework/model/ds_model.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
class PriceDetailsVo extends IDSModel {
String productId;
List<String> itemPic;
String itemTitle;
String subTitle;
String description;
String status;
//商品的ItemId
String itemId;
//平台Id
String platform;
//平台名称
String platformText;
//喜欢次数
String likeTimes;
//收藏次数
String collegeTimes;
//是否喜欢和收藏
bool isLike = false;
bool isFavorites = false;
//Button按钮的文字
String buttonText;
String price;
String endPrice;
//发布时间
String releaseTime;
String checkText;
//分享文字和分享URL
String shareUrl;
String shareMessage;
//优惠卷
List<Coupon> coupons = [];
//举报
List<ReportModel> reports = [];
//优惠卷过期描述
String couponText;
String isOverdue;
String shopTitle;
String rebate;
List<dynamic> collectOrders;
Map<String, dynamic> newItemInfo;
//商品推荐相关信息
List<ProductItemEntity> productEntitys;
PriceDetailsVo({
this.productId,
this.itemPic,
this.itemTitle,
this.subTitle,
this.description,
this.itemId,
this.platform,
this.platformText,
this.likeTimes,
this.collegeTimes,
this.isLike = false,
this.isFavorites = false,
this.buttonText,
this.releaseTime,
this.checkText,
this.reports,
this.shareUrl,
this.shareMessage,
this.price,
this.endPrice,
this.status,
this.couponText,
this.isOverdue,
this.shopTitle,
this.collectOrders,
this.newItemInfo,
this.productEntitys,
});
}
class Coupon {
String url;
String name;
String status;
Coupon({this.url, this.name, this.status});
}
class ReportModel {
String value;
String text;
List<ReportModel> sub = [];
ReportModel({this.value, this.text, this.sub});
}
import 'package:price_module/framework/model/ds_model.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
class PriceDiscountVo extends IDSModel{
///
/// 好价商品列表
///
List<ProductItemEntity> productEntitys;
}
\ No newline at end of file
import 'package:price_module/framework/model/ds_model.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
class PriceVo extends IDSModel {
// 商品列表
ProductListVo productListVo;
//筛选Tab
TabListVo tabListVo;
// 快捷分类列表
List<dynamic> sellingTabs;
PriceVo({this.productListVo, this.tabListVo, this.sellingTabs});
}
class TabListVo extends IDSModel {
//分类
List<TabVo> tabList = [];
//快捷分类
Map<String, dynamic> sellTab;
TabListVo({this.tabList = const [], this.sellTab});
}
class TabVo extends IDSModel {
String type;
String text;
String keyName;
bool open = false;
Map<String, dynamic> selected;
List<dynamic> structure;
TabVo({this.type, this.text, this.keyName, this.structure, this.selected});
TabVo.fromJson(String type, Map<String, dynamic> json) {
this.type = type;
this.text = '${json['text']}';
this.keyName = '${json['key_name']}';
this.structure = [];
if (json['structure'] != null && json['structure'] is List) {
this.structure = List.from(json['structure']);
}
}
}
class ProductListVo extends IDSModel {
bool isGrid = false;
List<ProductItemEntity> productList = [];
ProductListVo({this.productList = const [], this.isGrid = false});
}
import 'package:flutter/material.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:price_module/page/model/details/index.dart';
import 'package:price_module/utils/time_utils.dart';
import 'package:xiaoxiong_repository/entity/product_details_entity.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
import 'package:xiaoxiong_repository/repository/price_repository.dart';
import 'package:xiaoxiong_repository/entity/turn_chain_entity.dart';
import 'package:xiaoxiong_repository/app_xiaoxiong_repository.dart';
class PriceDetailsService {
PriceRepository _priceRepository = PriceRepository.get();
///
/// 查询商品详情
/// [productId] 查询的商品Id
///
Future<PriceDetailsVo> qryProductDetails({@required String productId}) async {
return await _priceRepository
.qryProductDetails(id: productId)
.asStream()
.map((event) {
PriceDetailsVo detailsVo;
if (event.isSuccess) {
detailsVo = PriceDetailsVo();
ProductDetailsEntity entity = event.data;
detailsVo.viewState = DSViewState.idle;
detailsVo.likeTimes = entity.likeTimes;
detailsVo.collegeTimes = entity.collegeTimes;
detailsVo.itemTitle = entity.itemTitle;
detailsVo.subTitle = entity.special;
detailsVo.itemPic = entity.itemPics;
detailsVo.description = entity.description;
detailsVo.status = entity.itemStatus;
detailsVo.buttonText = entity.buttonText;
detailsVo.itemId = entity.itemId;
detailsVo.platform = entity.platform;
detailsVo.couponText = entity.couponText;
detailsVo.isLike = entity.isLike == '1';
detailsVo.isFavorites = entity.isCollect == '1';
detailsVo.shareMessage = entity.shareMessage ?? '';
detailsVo.shareUrl = entity.shareUrl ?? '';
if (entity.releaseTime != null && entity.releaseTime.length > 0) {
detailsVo.releaseTime =
TimeUtils.formatTime(timestamp: entity.releaseTime);
}
detailsVo.checkText = entity.checkText ?? '';
detailsVo.endPrice = entity.endPrice;
detailsVo.price = entity.price;
detailsVo.coupons =
List.generate(entity.couponInfos?.length, (index) {
CouponInfo info = entity.couponInfos[index];
return Coupon(
name: info.couponName, url: info.url, status: info.status);
});
detailsVo.isOverdue = entity.isOverdue;
detailsVo.shopTitle = entity.shopTitle;
detailsVo.rebate = entity.rebate;
detailsVo.collectOrders = entity.collectOrders;
detailsVo.newItemInfo = entity.newItemInfo;
}
return detailsVo ?? PriceDetailsVo();
})
.first
.catchError((error) {
print("==================> error:$error");
});
}
///
/// 好价推荐列表
/// [keywords] 搜索关键词
/// [excludeId] 排除id
/// [page] 当前页码
/// [pagesize] 当前页显示的大小
///
Future<DSResponseList<ProductItemEntity>> getSellingRecommends({
String keywords,
String excludeId,
int page = 1,
int pagesize = 10,
}) async {
return _priceRepository.getSellingRecommends(
keywords: keywords,
excludeId: excludeId,
page: page,
pagesize: pagesize,
);
}
///
/// 举报
/// [id] 举报的商品Id
/// [report_type] 举报的商品类型
///
Future<dynamic> report(
{@required String id, @required String reportType}) async {
return await _priceRepository
.report(id: id, reportType: reportType)
.asStream()
.map((event) {
return {'code': event.code, 'msg': event.msg};
}).first;
}
///
/// 用户喜欢
/// [markId] 产品Id
/// [type] 类型
/// [status] 状态
/// [platform] 平台
///
Future<dynamic> userLike(
{@required String markId,
@required String platform,
String type = '2',
String status = '1'}) async {
return await _priceRepository
.userLike(
markId: markId, type: type, status: status, platform: platform)
.asStream()
.map((event) {
return {'code': event.code, 'msg': event.msg};
}).first;
}
///
/// 用户收藏
///
Future<dynamic> userCollect(
{@required String itemId,
@required String platform,
String type = '2',
String status = '1'}) async {
return await _priceRepository
.userCollect(
itemId: itemId, type: type, status: status, platform: platform)
.asStream()
.map((event) {
return {'code': event.code, 'msg': event.msg};
}).first;
}
///
/// 通过商品Id进行转链
/// [itemId] 商品id
/// [platform] 平台,1淘宝 2京东 3拼多多 4唯品会
/// [type] 转链类型 好价传6 默认为5
///
Future<DSResponseObject<TurnChainEntity>> turnChainForItemId(
{@required String itemId,
@required String platform,
String type = '6'}) async {
return await _priceRepository
.turnChainForItemId(itemId: itemId, platform: platform, type: type)
.asStream()
.first;
}
}
This diff is collapsed.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/boost_navigator.dart';
import 'package:price_module/framework/base/ds_provider_widget.dart';
import 'package:price_module/framework/model/ds_model.dart';
import 'package:price_module/page/action/discount/index.dart';
import 'package:price_module/page/model/discount/index.dart';
import 'package:price_module/page/widget/discount/index.dart';
import 'package:price_module/route/index.dart';
import 'package:price_module/widget/failed/failed_load_page.dart';
import 'package:price_module/widget/price/price_item.dart';
import 'package:price_module/widget/pull/pull_widget.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:xiaoxiong_repository/entity/product_item_entity.dart';
import 'package:common_module/utils/xapp_utils.dart';
///
/// 好价更多优惠页面
///
class PriceDiscountPage extends StatefulWidget {
final Map<String, dynamic> pageParam;
const PriceDiscountPage({Key key, @required this.pageParam})
: super(key: key);
@override
_PriceDiscountPageState createState() => _PriceDiscountPageState();
}
class _PriceDiscountPageState extends State<PriceDiscountPage>
with IPriceDiscountDelegate {
IPriceDiscountAction _discountAction;
bool _isAudituser = false;
List<dynamic> _sellReportList;
@override
void initState() {
_isAudituser = widget.pageParam['isAudituser'];
_sellReportList = widget.pageParam['sellReportList'];
_discountAction = PriceDiscountAction(
delegate: this,
pageParam: widget.pageParam,
);
super.initState();
}
RefreshController _refreshController = RefreshController();
@override
Widget build(BuildContext context) {
return DSProviderWidget<PriceDiscountVo,
IPriceDiscountAction<PriceDiscountVo>>(
dsAction: _discountAction,
builder: (BuildContext context, Widget child) {
return Scaffold(
appBar: buildAppBar(),
body: _buildBody1(vo: _discountAction.getVo),
);
},
);
}
Widget _buildBody1({PriceDiscountVo vo}) {
return PullWidget(
controller: _refreshController,
child: Container(child: _buildBody(vo: vo)),
onRefresh: () {
_discountAction.reloadData();
},
onLoad: () {
_discountAction.onLoad();
},
);
}
Widget _buildBody({PriceDiscountVo vo}) {
if (vo.viewState == DSViewState.busy) {
return LoadingPage(
padding: EdgeInsets.all(13.w),
length: 8,
);
} else if (vo.viewState == DSViewState.empty ||
vo.viewState == DSViewState.error) {
return FailedLoadPage(
margin: EdgeInsets.only(top: 68.w),
errorMsg:
vo.viewState == DSViewState.empty ? '未发现数据,请刷新重试' : '加载失败,请刷新重试',
onReloadTap: () {
//重新加载数据
_discountAction.reloadData();
},
);
}
return PriceListWidget(
padding: EdgeInsets.only(
bottom: 20.w,
left: 13.w,
right: 13.w,
),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
list: vo.productEntitys,
onItemTap: (ProductItemEntity entity, int index) async {
Map<String, dynamic> params = {
'isAudituser': _isAudituser,
'sellReportList': _sellReportList,
'productId': entity.id,
'src': entity.itemPic,
'title': entity.itemTitle,
'remark': entity.special
};
await BoostNavigator.instance.push(
RoutePath.PRICE_DETAIL_PAGE.path(),
withContainer: false,
arguments: params,
);
},
);
}
@override
void onLoadComplete({bool isLoading = true}) {
if (isLoading) {
_refreshController.loadComplete();
} else {
_refreshController.refreshCompleted();
}
}
@override
void onloadFailed({bool isLoading = true, String msg}) {
if (isLoading) {
_refreshController.loadFailed();
} else {
_refreshController.refreshFailed();
}
}
}
This diff is collapsed.
This diff is collapsed.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:common_module/utils/xapp_utils.dart';
Widget buildAppBar(){
return AppBar(
backgroundColor:Colors.white,
centerTitle: true,
title: Text('全部优惠',style:TextStyle(fontSize:17.w,fontWeight:FontWeight.w600,color:Color(0xFF333333)),),
elevation:0,
);
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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