parent
93e944e557
commit
b4f9c87d3e
@ -0,0 +1,66 @@
|
||||
import 'package:aku_community_manager/models/common/img_model.dart';
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
|
||||
class ActivityDetailModel {
|
||||
int id;
|
||||
String title;
|
||||
String content;
|
||||
String activityStartTime;
|
||||
String activityEndTime;
|
||||
String location;
|
||||
String registrationEndTime;
|
||||
List<ImgModel> imgUrls;
|
||||
ImgModel get firstImg {
|
||||
if (imgUrls.isEmpty)
|
||||
return null;
|
||||
else
|
||||
return imgUrls.first;
|
||||
}
|
||||
|
||||
DateTime get registrationEnd => DateUtil.getDateTime(registrationEndTime);
|
||||
|
||||
DateTime get activityStart => DateUtil.getDateTime(activityStartTime);
|
||||
|
||||
DateTime get activityEnd => DateUtil.getDateTime(activityEndTime);
|
||||
|
||||
ActivityDetailModel(
|
||||
{this.id,
|
||||
this.title,
|
||||
this.content,
|
||||
this.activityStartTime,
|
||||
this.activityEndTime,
|
||||
this.location,
|
||||
this.registrationEndTime,
|
||||
this.imgUrls});
|
||||
|
||||
ActivityDetailModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
title = json['title'];
|
||||
content = json['content'];
|
||||
activityStartTime = json['activityStartTime'];
|
||||
activityEndTime = json['activityEndTime'];
|
||||
location = json['location'];
|
||||
registrationEndTime = json['registrationEndTime'];
|
||||
if (json['imgUrls'] != null) {
|
||||
imgUrls = new List<ImgModel>();
|
||||
json['imgUrls'].forEach((v) {
|
||||
imgUrls.add(new ImgModel.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['title'] = this.title;
|
||||
data['content'] = this.content;
|
||||
data['activityStartTime'] = this.activityStartTime;
|
||||
data['activityEndTime'] = this.activityEndTime;
|
||||
data['location'] = this.location;
|
||||
data['registrationEndTime'] = this.registrationEndTime;
|
||||
if (this.imgUrls != null) {
|
||||
data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
import 'package:aku_community_manager/models/common/img_model.dart';
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
|
||||
class ActivityItemModel {
|
||||
int id;
|
||||
String title;
|
||||
String sponsorName;
|
||||
String location;
|
||||
String registrationStartTime;
|
||||
String registrationEndTime;
|
||||
String createDate;
|
||||
List<ImgModel> imgUrls;
|
||||
|
||||
ImgModel get firstImg {
|
||||
if (imgUrls.isEmpty)
|
||||
return null;
|
||||
else
|
||||
return imgUrls.first;
|
||||
}
|
||||
|
||||
DateTime get create => DateUtil.getDateTime(createDate);
|
||||
|
||||
DateTime get registrationStart => DateUtil.getDateTime(registrationStartTime);
|
||||
|
||||
DateTime get registrationEnd => DateUtil.getDateTime(registrationEndTime);
|
||||
|
||||
ActivityItemModel(
|
||||
{this.id,
|
||||
this.title,
|
||||
this.sponsorName,
|
||||
this.location,
|
||||
this.registrationStartTime,
|
||||
this.registrationEndTime,
|
||||
this.createDate,
|
||||
this.imgUrls});
|
||||
|
||||
ActivityItemModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
title = json['title'];
|
||||
sponsorName = json['sponsorName'];
|
||||
location = json['location'];
|
||||
registrationStartTime = json['registrationStartTime'];
|
||||
registrationEndTime = json['registrationEndTime'];
|
||||
createDate = json['createDate'];
|
||||
if (json['imgUrls'] != null) {
|
||||
imgUrls = new List<ImgModel>();
|
||||
json['imgUrls'].forEach((v) {
|
||||
imgUrls.add(new ImgModel.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['title'] = this.title;
|
||||
data['sponsorName'] = this.sponsorName;
|
||||
data['location'] = this.location;
|
||||
data['registrationStartTime'] = this.registrationStartTime;
|
||||
data['registrationEndTime'] = this.registrationEndTime;
|
||||
data['createDate'] = this.createDate;
|
||||
if (this.imgUrls != null) {
|
||||
data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
// Flutter imports:
|
||||
import 'package:aku_community_manager/utils/network/base_list_model.dart';
|
||||
import 'package:aku_community_manager/utils/network/net_util.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
|
||||
|
||||
/// ## BeeListView
|
||||
///```dart
|
||||
///BeeListView(
|
||||
/// path: API.someAPI,
|
||||
/// convert: (model) {
|
||||
/// return model.tableList
|
||||
/// .map((e) => SomeModel.fromJson(e))
|
||||
/// .toList();
|
||||
/// },
|
||||
/// controller: _refreshController,
|
||||
/// builder: (items) {
|
||||
/// return ListView.builder(
|
||||
/// itemBuilder: (context, index) {
|
||||
/// return _buildSomeItem(items[index]);
|
||||
/// },
|
||||
/// itemCount: items.length,
|
||||
/// );
|
||||
/// },
|
||||
///)
|
||||
///```
|
||||
class BeeListView<T> extends StatefulWidget {
|
||||
///API path
|
||||
final String path;
|
||||
|
||||
///same as EasyRefreshController
|
||||
final EasyRefreshController controller;
|
||||
|
||||
///转换器
|
||||
///
|
||||
///BaseListModel to T
|
||||
///
|
||||
///T is a tableList item.
|
||||
///
|
||||
///```dart
|
||||
///...
|
||||
///convert: (model) {
|
||||
/// return model.tableList
|
||||
/// .map((e) => SomeModel.fromJson(e))
|
||||
/// .toList();
|
||||
///},
|
||||
///...
|
||||
///```
|
||||
final List<T> Function(BaseListModel model) convert;
|
||||
|
||||
///子组件构造器
|
||||
final Widget Function(List<T> items) builder;
|
||||
|
||||
///每页记录数
|
||||
final int size;
|
||||
|
||||
///额外的参数
|
||||
final Map<String, dynamic> extraParams;
|
||||
BeeListView({
|
||||
Key key,
|
||||
@required this.path,
|
||||
@required this.controller,
|
||||
@required this.convert,
|
||||
@required this.builder,
|
||||
this.size = 10,
|
||||
this.extraParams,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_BeeListViewState<T> createState() => _BeeListViewState<T>();
|
||||
}
|
||||
|
||||
class _BeeListViewState<T> extends State<BeeListView> {
|
||||
int _pageNum = 1;
|
||||
BaseListModel _model = BaseListModel.zero();
|
||||
List<T> _models = [];
|
||||
Map<String, dynamic> get _params {
|
||||
Map<String, dynamic> tempMap = {
|
||||
'pageNum': _pageNum,
|
||||
'size': widget.size,
|
||||
};
|
||||
tempMap.addAll(widget.extraParams ?? {});
|
||||
return tempMap;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return EasyRefresh(
|
||||
controller: widget.controller,
|
||||
header: MaterialHeader(),
|
||||
footer: MaterialFooter(),
|
||||
onRefresh: () async {
|
||||
_pageNum = 1;
|
||||
_model = await NetUtil().getList(
|
||||
widget.path,
|
||||
params: _params,
|
||||
);
|
||||
_models = widget.convert(_model);
|
||||
widget.controller?.resetLoadState();
|
||||
setState(() {});
|
||||
},
|
||||
firstRefresh: true,
|
||||
onLoad: () async {
|
||||
_pageNum++;
|
||||
_model = await NetUtil().getList(
|
||||
widget.path,
|
||||
params: _params,
|
||||
);
|
||||
_models.addAll(widget.convert(_model) as List<T>);
|
||||
if (_pageNum >= _model.pageCount)
|
||||
widget.controller.finishLoad(noMore: true);
|
||||
setState(() {});
|
||||
},
|
||||
child: widget.builder(_models),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue