parent
577781cdbf
commit
27b2bbede1
After Width: | Height: | Size: 564 KiB |
After Width: | Height: | Size: 306 KiB |
After Width: | Height: | Size: 863 B |
@ -0,0 +1,39 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'home_message_list_model.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class HomeMessageListModel extends Equatable {
|
||||
final int id;
|
||||
final int type;
|
||||
final int status;
|
||||
final String title;
|
||||
final String content;
|
||||
final String sendDate;
|
||||
final int jumpId;
|
||||
|
||||
factory HomeMessageListModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$HomeMessageListModelFromJson(json);
|
||||
|
||||
const HomeMessageListModel({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.sendDate,
|
||||
required this.jumpId,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
type,
|
||||
status,
|
||||
title,
|
||||
content,
|
||||
sendDate,
|
||||
jumpId,
|
||||
];
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'home_message_list_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
HomeMessageListModel _$HomeMessageListModelFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
HomeMessageListModel(
|
||||
id: json['id'] as int,
|
||||
type: json['type'] as int,
|
||||
status: json['status'] as int,
|
||||
title: json['title'] as String,
|
||||
content: json['content'] as String,
|
||||
sendDate: json['sendDate'] as String,
|
||||
jumpId: json['jumpId'] as int,
|
||||
);
|
@ -0,0 +1,62 @@
|
||||
import 'package:aku_new_community_manager/gen/assets.gen.dart';
|
||||
import 'package:aku_new_community_manager/ui/manage_pages/inspection_manage/inspection_manage_page.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ApplicationUtil {
|
||||
ApplicationUtil(this.titles);
|
||||
|
||||
List<String> titles = [];
|
||||
|
||||
List<AppElement> get elements {
|
||||
var list = <AppElement>[];
|
||||
this.titles.forEach((element) {
|
||||
var re = _findByTitle(element);
|
||||
if (re != null) {
|
||||
list.add(re);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
AppElement? _findByTitle(String title) {
|
||||
for (var item in allApplications) {
|
||||
if (title == item.title) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<AppElement> get allApplications => [
|
||||
AppElement(
|
||||
title: '巡检管理',
|
||||
imgPath: Assets.home.icPatrol.path,
|
||||
onTap: () async {
|
||||
await Get.to(InspectionManagePage());
|
||||
}),
|
||||
AppElement(
|
||||
title: '工单管理',
|
||||
imgPath: Assets.home.icArticle.path,
|
||||
onTap: () async {})
|
||||
];
|
||||
}
|
||||
|
||||
class AppElement extends Equatable {
|
||||
final String title;
|
||||
final String imgPath;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const AppElement({
|
||||
required this.title,
|
||||
required this.imgPath,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
title,
|
||||
imgPath,
|
||||
onTap,
|
||||
];
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aku_new_community_manager/gen/assets.gen.dart';
|
||||
import 'package:aku_new_community_manager/new_models/home/home_message_list_model.dart';
|
||||
import 'package:aku_new_community_manager/utils/bee_date_util.dart';
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
||||
class HomeSwiper extends StatefulWidget {
|
||||
final List<HomeMessageListModel> models;
|
||||
|
||||
const HomeSwiper({Key? key, required this.models}) : super(key: key);
|
||||
|
||||
@override
|
||||
_HomeSwiperState createState() => _HomeSwiperState();
|
||||
}
|
||||
|
||||
class _HomeSwiperState extends State<HomeSwiper> {
|
||||
int _currentPage = 0;
|
||||
final PageController _pageController = PageController(initialPage: 0);
|
||||
late Timer timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// _pageController.addListener(() {
|
||||
// setState(() {});
|
||||
// });
|
||||
timer = Timer.periodic(Duration(seconds: 5), (timer) {
|
||||
if (_currentPage != widget.models.length - 1) {
|
||||
var page = (_currentPage + 1).toInt();
|
||||
_pageController.animateToPage(page,
|
||||
duration: Duration(milliseconds: 500), curve: Curves.easeInOut);
|
||||
} else {
|
||||
_pageController.animateToPage(0,
|
||||
duration: Duration(milliseconds: 500), curve: Curves.easeInOut);
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 440.w,
|
||||
height: 272.w,
|
||||
padding: EdgeInsets.only(left: 24.w, right: 24.w, top: 40.w),
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0xFFFFC40C).withOpacity(0.15),
|
||||
offset: Offset(0, 2),
|
||||
blurRadius: 6,
|
||||
spreadRadius: 0)
|
||||
],
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8.w),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: PageView.builder(
|
||||
controller: _pageController,
|
||||
reverse: true,
|
||||
onPageChanged: (page) {
|
||||
_currentPage = page;
|
||||
setState(() {});
|
||||
},
|
||||
itemCount: widget.models.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _card(widget.models[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
16.w.heightBox,
|
||||
_indicator(),
|
||||
8.w.heightBox,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _indicator() {
|
||||
return Stack(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(
|
||||
widget.models.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
_pageController.animateToPage(index,
|
||||
duration: Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut);
|
||||
setState(() {});
|
||||
},
|
||||
child: Material(
|
||||
child: Container(
|
||||
width: 32.w,
|
||||
height: 6.w,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: index == 0
|
||||
? BorderRadius.only(
|
||||
topLeft: Radius.circular(3.w),
|
||||
bottomLeft: Radius.circular(3.w))
|
||||
: index == widget.models.length - 1
|
||||
? BorderRadius.only(
|
||||
topRight: Radius.circular(3.w),
|
||||
bottomRight: Radius.circular(3.w))
|
||||
: BorderRadius.circular(3.w),
|
||||
color: Color(0xFFF6F6F6),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
top: 0,
|
||||
left: _currentPage * 32.w,
|
||||
child: Container(
|
||||
width: 32.w,
|
||||
height: 6.w,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFFFC40C),
|
||||
borderRadius: BorderRadius.circular(3.w),
|
||||
),
|
||||
),
|
||||
curve: Curves.easeInOut,
|
||||
duration: Duration(
|
||||
milliseconds: 500,
|
||||
))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _card(HomeMessageListModel model) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Assets.home.message.image(width: 40.w, height: 40.w),
|
||||
16.w.widthBox,
|
||||
model.title.text.size(28.sp).color(Colors.black).bold.make(),
|
||||
],
|
||||
),
|
||||
20.w.heightBox,
|
||||
model.content.text
|
||||
.size(24.sp)
|
||||
.maxLines(3)
|
||||
.overflow(TextOverflow.ellipsis)
|
||||
.color(Colors.black.withOpacity(0.65))
|
||||
.make(),
|
||||
40.w.heightBox,
|
||||
BeeDateUtil(DateUtil.getDateTime(model.sendDate))
|
||||
.timeAgo
|
||||
.text
|
||||
.size(20.sp)
|
||||
.color(Colors.black.withOpacity(0.25))
|
||||
.make(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import 'package:aku_new_community_manager/const/saas_api.dart';
|
||||
import 'package:aku_new_community_manager/gen/assets.gen.dart';
|
||||
import 'package:aku_new_community_manager/models/common/img_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class BeeImageNetwork extends StatelessWidget {
|
||||
final List<ImgModel>? imgs;
|
||||
final List<String>? urls;
|
||||
final double? width;
|
||||
final double? height;
|
||||
final BoxFit? fit;
|
||||
|
||||
const BeeImageNetwork(
|
||||
{Key? key,
|
||||
this.imgs,
|
||||
this.width,
|
||||
this.height,
|
||||
this.urls,
|
||||
this.fit = BoxFit.cover})
|
||||
: assert(imgs != null || urls != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FadeInImage.assetNetwork(
|
||||
placeholder: Assets.placeholder.path,
|
||||
image: imgs == null
|
||||
? SAASAPI.image(urls!.isEmpty ? '' : urls!.first)
|
||||
: SAASAPI.image(ImgModel.first(imgs)),
|
||||
imageErrorBuilder: (context, obj, stackTrace) {
|
||||
return Image.asset(
|
||||
Assets.placeholder.path,
|
||||
width: width ?? 160.w,
|
||||
height: height ?? 160.w,
|
||||
fit: BoxFit.fill,
|
||||
);
|
||||
},
|
||||
height: height ?? 160.w,
|
||||
width: width ?? 160.w,
|
||||
fit: fit,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
|
||||
class BeeDateUtil {
|
||||
DateTime? date;
|
||||
|
||||
BeeDateUtil(this.date);
|
||||
|
||||
DateTime get _now => DateTime.now();
|
||||
|
||||
bool get sameYear => _now.year == this.date!.year;
|
||||
|
||||
bool get sameMonth => sameYear && _now.month == this.date!.month;
|
||||
|
||||
bool get sameDay => sameMonth && _now.day == this.date!.day;
|
||||
|
||||
bool get isYesterday =>
|
||||
(DateTime(_now.year, _now.month, _now.day - 1).compareTo(
|
||||
DateTime(this.date!.year, this.date!.month, this.date!.day)) ==
|
||||
0);
|
||||
|
||||
bool get isDoubleYesterday =>
|
||||
(DateTime(_now.year, _now.month, _now.day - 2).compareTo(
|
||||
DateTime(this.date!.year, this.date!.month, this.date!.day)) ==
|
||||
0);
|
||||
|
||||
String get timeAgo {
|
||||
Duration duration = _now.difference(date!);
|
||||
if (duration.inSeconds <= 60) return '${duration.inSeconds}秒前';
|
||||
if (duration.inMinutes <= 60) return '${duration.inMinutes}分钟前';
|
||||
if (duration.inHours <= 12) return '${duration.inHours}小时前';
|
||||
if (isYesterday) return '昨天';
|
||||
if (isDoubleYesterday) return '前天';
|
||||
if (duration.inDays <= 30)
|
||||
return '${duration.inDays}天前';
|
||||
else
|
||||
return DateUtil.formatDate(date, format: 'yyyy-MM-dd');
|
||||
}
|
||||
|
||||
String get timeAgoWithHm {
|
||||
Duration duration = _now.difference(date!);
|
||||
if (duration.inSeconds <= 60) return '${duration.inSeconds}秒前';
|
||||
if (duration.inMinutes <= 60) return '${duration.inMinutes}分钟前';
|
||||
if (duration.inHours <= 12) return '${duration.inHours}小时前';
|
||||
if (isYesterday) return '昨天';
|
||||
if (isDoubleYesterday) return '前天';
|
||||
if (duration.inDays <= 30)
|
||||
return '${duration.inDays}天前';
|
||||
else
|
||||
return DateUtil.formatDate(date, format: 'yyyy-MM-dd HH-mm');
|
||||
}
|
||||
}
|
Loading…
Reference in new issue