| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:location/data/bean/track_daily_bean.dart';
- import 'package:location/data/consts/constants.dart';
- import 'package:location/dialog/track_error_tips_dialog.dart';
- import 'package:location/module/track/track_util.dart';
- import 'package:location/resource/assets.gen.dart';
- import 'package:location/resource/colors.gen.dart';
- import 'package:location/resource/string.gen.dart';
- import 'package:location/utils/common_expand.dart';
- import 'package:location/utils/date_util.dart';
- import 'package:location/utils/toast_util.dart';
- import '../track_status.dart';
- typedef TrackItemClick = void Function(TrackDailyBean bean);
- typedef TrackAIAnalyseClick = void Function(TrackDailyBean bean);
- Widget buildTrackDailyItem(TrackDailyBean bean, bool isEnd,
- {TrackItemClick? onItemClick, TrackAIAnalyseClick? onAIAnalyseClick}) {
- return Container(
- padding: EdgeInsets.symmetric(horizontal: 12.w),
- margin: EdgeInsets.only(bottom: 8.w),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Builder(builder: (context) {
- if (bean.status == TrackStatus.moving) {
- return _buildMovingTrackDailyItem(bean, onItemClick: onItemClick);
- } else if (bean.status == TrackStatus.stay) {
- return buildStayTrackDailyItem(bean, onItemClick: onItemClick);
- } else if (bean.status == TrackStatus.error) {
- return buildErrorTrackDailyItem(bean,
- onItemClick: onItemClick, onAIAnalyseClick: onAIAnalyseClick);
- } else {
- return SizedBox(height: 50.w, child: Text('未知轨迹,请更新最新应用版本'));
- }
- }),
- if (isEnd) buildEndPoint(bean)
- ],
- ),
- );
- }
- Widget _buildMovingTrackDailyItem(TrackDailyBean bean,
- {TrackItemClick? onItemClick}) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- IntrinsicHeight(
- child: Row(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- _buildTimeText(bean.start),
- SizedBox(height: 4.w),
- _buildRingView(),
- SizedBox(height: 4.w),
- Expanded(
- child: Container(
- width: 1.w,
- decoration: BoxDecoration(
- color: '#F0F0F0'.color,
- borderRadius: BorderRadius.circular(100.r),
- ),
- ),
- )
- ],
- ),
- Expanded(
- child: GestureDetector(
- onTap: () {
- onItemClick?.call(bean);
- },
- child: Container(
- height: 50.w,
- margin: EdgeInsets.only(top: 26.w),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8.r),
- gradient: LinearGradient(colors: [
- '#F8F5FF'.color,
- ColorName.transparent,
- ])),
- padding: EdgeInsets.symmetric(horizontal: 14.w),
- child: Row(
- children: [
- Assets.images.iconTrackMoving.image(width: 16.w),
- SizedBox(width: 5.w),
- Text(
- StringName.trackDetailMoving,
- style: TextStyle(
- fontSize: 12.sp,
- color: '#333333'.color,
- fontWeight: FontWeight.bold),
- )
- ],
- ),
- ),
- ))
- ],
- ),
- ),
- SizedBox(height: 8.w),
- ],
- );
- }
- Widget buildStayTrackDailyItem(TrackDailyBean bean,
- {EdgeInsetsGeometry? contentPadding, TrackItemClick? onItemClick}) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- IntrinsicHeight(
- child: Row(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- _buildTimeText(bean.start),
- SizedBox(height: 4.w),
- _buildRingView(),
- SizedBox(height: 4.w),
- Expanded(
- child: Container(
- width: 1.w,
- decoration: BoxDecoration(
- color: '#F0F0F0'.color,
- borderRadius: BorderRadius.circular(100.r),
- ),
- ),
- )
- ],
- ),
- Expanded(
- child: GestureDetector(
- onTap: () {
- onItemClick?.call(bean);
- },
- child: Container(
- padding: EdgeInsets.all(10.w),
- margin: contentPadding ?? EdgeInsets.only(top: 20.w),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8.r),
- gradient: LinearGradient(colors: [
- '#F8F5FF'.color,
- ColorName.transparent,
- ])),
- child: ConstrainedBox(
- constraints: BoxConstraints(minHeight: 60.w),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Expanded(
- child: Text(
- bean.addr ?? '',
- style: TextStyle(
- fontSize: 12.sp,
- color: '#333333'.color,
- fontWeight: FontWeight.bold),
- ),
- ),
- SizedBox(height: 11.w),
- Row(
- children: [
- _buildStayDesc(bean.duration),
- SizedBox(width: 18.w),
- _buildLockDesc(bean.highUnlock, bean.totalUnlock),
- SizedBox(width: 18.w),
- Expanded(child: _buildNetDesc(bean.network))
- ],
- )
- ],
- ),
- ),
- ),
- ))
- ],
- ),
- ),
- SizedBox(height: 8.w),
- ],
- );
- }
- Widget buildErrorTrackDailyItem(TrackDailyBean bean,
- {EdgeInsetsGeometry? contentPadding,
- TrackItemClick? onItemClick,
- TrackAIAnalyseClick? onAIAnalyseClick}) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- IntrinsicHeight(
- child: Row(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- _buildTimeText(bean.start),
- SizedBox(height: 4.w),
- _buildRingView(isError: true),
- SizedBox(height: 4.w),
- Expanded(
- child: Container(
- width: 1.w,
- decoration: BoxDecoration(
- color: '#F0F0F0'.color,
- borderRadius: BorderRadius.circular(100.r),
- ),
- ),
- )
- ],
- ),
- Expanded(
- child: GestureDetector(
- onTap: () {
- onItemClick?.call(bean);
- },
- child: Container(
- height: 50.w,
- padding: EdgeInsets.all(10.w),
- margin:
- contentPadding ?? EdgeInsets.only(top: 41.w, bottom: 7.w),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8.r),
- gradient: LinearGradient(colors: [
- '#FFECEC'.color,
- ColorName.white,
- ])),
- child: Row(
- children: [
- Assets.images.iconTrackError.image(width: 19.4.w),
- SizedBox(width: 5.5.w),
- Text(StringName.trackDetailError,
- style: TextStyle(
- fontSize: 12.sp,
- color: '#333333'.color,
- fontWeight: FontWeight.bold)),
- SizedBox(width: 10.w),
- GestureDetector(
- onTap: () {
- TrackErrorTipsDialog.show();
- },
- child: Text(
- StringName.trackDetailSeeError,
- style:
- TextStyle(fontSize: 11.sp, color: '#4476FF'.color),
- ),
- ),
- Spacer(),
- GestureDetector(
- onTap: () {
- onAIAnalyseClick?.call(bean);
- },
- child:
- Assets.images.imgTrackAiAnalyse.image(width: 73.w)),
- SizedBox(width: 6.w),
- ],
- ),
- ),
- ))
- ],
- ),
- ),
- SizedBox(height: 8.w),
- ],
- );
- }
- Widget _buildRingView({bool isError = false}) {
- return Container(
- width: 12.w,
- height: 12.w,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- border: Border.all(
- color: isError ? '#F24D4D'.color : '#66999999'.color,
- width: isError ? 2.w : 1.w,
- ),
- ),
- );
- }
- Widget _buildTimeText(int time) {
- return Text(
- DateUtil.fromMillisecondsSinceEpoch('HH:mm', time),
- style: TextStyle(
- fontSize: 12.sp, color: '#333333'.color, fontWeight: FontWeight.w500),
- );
- }
- Widget buildEndPoint(TrackDailyBean bean) {
- return Column(
- children: [
- SizedBox(height: 4.w),
- _buildRingView(),
- SizedBox(height: 4.w),
- _buildTimeText(bean.end),
- ],
- );
- }
- Widget _buildNetDesc(String? network) {
- bool isMobile = network == Constants.kMobileNetworkTag;
- return IntrinsicWidth(
- child: Row(
- children: [
- isMobile
- ? Assets.images.iconNetMobile.image(width: 14.w, height: 14.w)
- : Assets.images.iconNetWifi.image(width: 14.w, height: 14.w),
- SizedBox(width: 2.w),
- Expanded(
- child: Text(
- isMobile ? StringName.trackDetailMobile : network ?? '',
- style:
- TextStyle(fontSize: 11.sp, color: '#666666'.color, height: 1),
- ),
- )
- ],
- ),
- );
- }
- Widget _buildDoubtView() {
- return Container(
- constraints: BoxConstraints(
- maxWidth: 0.9.sw,
- ),
- decoration: BoxDecoration(
- color: ColorName.black60,
- borderRadius: BorderRadius.circular(4.r),
- ),
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 10.w),
- child: Text(
- StringName.trackNoDoubtDesc,
- style: TextStyle(fontSize: 12.sp, color: ColorName.white),
- ));
- }
- Widget _buildLockDesc(int? highUnlock, int? totalUnlock) {
- if ((highUnlock == null && totalUnlock == null) ||
- (highUnlock == 0 && totalUnlock == 0)) {
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- ToastUtil.show("",
- displayTime: Duration(seconds: 3),
- alignment: Alignment.center,
- builder: (cxt) => _buildDoubtView());
- },
- child: Row(
- children: [
- Assets.images.iconTrackUnlockNoPermission
- .image(width: 14.w, height: 14.w),
- SizedBox(width: 2.w),
- Text(StringName.trackDetailNoAuthorize,
- style: TextStyle(
- fontSize: 11.sp, color: '#919DBE'.color, height: 1)),
- SizedBox(width: 1.w),
- Assets.images.iconTrackDailyDoubt.image(width: 12.w, height: 12.w)
- ],
- ),
- );
- } else {
- return Row(
- children: [
- Assets.images.iconTrackStay.image(width: 14.w, height: 14.w),
- SizedBox(width: 2.w),
- if (highUnlock != null && highUnlock == 0)
- Text('高频解锁$highUnlock次,共${totalUnlock ?? 0}次',
- style:
- TextStyle(fontSize: 11.sp, color: '#666666'.color, height: 1))
- else
- Text('解锁${totalUnlock ?? 0}次',
- style:
- TextStyle(fontSize: 11.sp, color: '#666666'.color, height: 1))
- ],
- );
- }
- }
- Widget _buildStayDesc(int duration) {
- return Row(
- children: [
- Assets.images.iconTrackStay.image(width: 14.w, height: 14.w),
- SizedBox(width: 2.w),
- Text(TrackUtil.formatDurationFromMillis(duration),
- style: TextStyle(fontSize: 11.sp, color: '#666666'.color, height: 1))
- ],
- );
- }
|