You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/views/widgets/requests/service_request_item.dart

305 lines
15 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/enums/translation_keys.dart';
import 'package:test_sa/models/enums/user_types.dart';
import 'package:test_sa/models/service_request/service_request.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/models/user.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/pages/user/requests/report/create_service_report.dart';
import 'package:test_sa/views/widgets/loaders/image_loader.dart';
import 'package:test_sa/views/widgets/requests/request_status.dart';
class ServiceRequestItem extends StatelessWidget {
final int index;
final ServiceRequest request;
final Function(ServiceRequest) onPressed;
const ServiceRequestItem({Key key, this.request, this.onPressed, this.index}) : super(key: key);
@override
Widget build(BuildContext context) {
Subtitle _subtitle = AppLocalization.of(context).subtitle;
User _user = Provider.of<UserProvider>(context, listen: false).user;
final servicesProvider = Provider.of<ServiceRequestsProvider>(context, listen: false);
final settingProvider = Provider.of<SettingProvider>(context, listen: false);
Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary;
Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary;
return index % 2 == 0
? Container(
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)],
),
child: Column(
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
decoration: ShapeDecoration(
color: const Color(0xFFFFDBDC),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
),
child: Text('HIGH PRIORITY', style: AppTextStyles.overline.copyWith(color: const Color(0xFF8C0409))),
),
8.width,
Container(
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
decoration: ShapeDecoration(
color: const Color(0xFFFFEDBC),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
),
child: Text('IN PROGRESS', style: AppTextStyles.overline.copyWith(color: const Color(0xFF886300))),
),
1.width.expanded,
Text('05 Dec, 2022\n09:30 AM', textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))),
],
),
8.height,
Text(context.translate(TranslationKeys.serviceRequest), style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))),
],
).paddingAll(16),
],
),
)
: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
primary: itemColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)),
),
),
//padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8),
onPressed: () {
onPressed(request);
},
child: Row(
children: [
//Placeholder(color: onItemColor,fallbackWidth: 80,fallbackHeight: 80,),
_user.type == UsersTypes.normal_user && request.devicePhotos.isEmpty
? SizedBox.shrink()
: SizedBox(
width: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
request.devicePhotos?.isEmpty != false
? SizedBox.shrink()
: Column(
children: [
SizedBox(
height: 80,
width: 80,
child: ImageLoader(
url: request.devicePhotos.first,
boxFit: BoxFit.cover,
),
),
SizedBox(
height: 24,
),
],
),
_user.type == UsersTypes.engineer
? Material(
color: onItemColor,
elevation: 6,
shape: CircleBorder(),
child: IconButton(
icon: Icon(
Icons.description,
color: itemColor,
size: 32,
),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => CreateServiceReport(
request: request,
)),
);
},
),
)
: SizedBox.shrink(),
//SizedBox(height: 8,),
],
),
),
SizedBox(
width: 8,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: request.requestCode == null
? SizedBox.shrink()
: Text(
request.requestCode ?? "-----",
style: Theme.of(context).textTheme.headline6.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold),
),
),
request.engineerName == null
? SizedBox.shrink()
: Text(
request.engineerName ?? "",
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
],
),
Divider(
color: onItemColor,
),
Text(
request.deviceNumber,
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
Divider(
color: onItemColor,
),
Row(
children: [
Expanded(
child: request.deviceModel == null
? SizedBox.shrink()
: Text(
request.deviceModel ?? "Model not available",
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
),
request.engineerMobile == null
? SizedBox.shrink()
: Text(
request.engineerMobile,
style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
],
),
Divider(
color: onItemColor,
),
Row(
children: [
Expanded(
child: request.deviceSerialNumber == null
? SizedBox.shrink()
: Text(
request.deviceSerialNumber,
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
),
],
),
request.deviceEnName == null
? SizedBox.shrink()
: Row(
children: [
Expanded(
child: Text(
request.deviceEnName,
style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal),
),
),
],
),
],
),
),
],
),
Divider(
color: onItemColor,
),
Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text(
request.callComments ?? "No maintenance issue found",
style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor),
textAlign: TextAlign.center,
),
),
),
Divider(
color: onItemColor,
),
Row(
children: [
Text(
request.date ?? "Date not available",
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor),
),
Spacer(),
StatusLabel(label: request.statusLabel, color: AColors.getRequestStatusColor(request.statusValue)),
],
),
request.nextVisitDate == null
? SizedBox.shrink()
: Column(
children: [
Divider(
color: onItemColor,
),
Row(
children: [
Text(
_subtitle.nextVisitDate,
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor),
),
Spacer(),
Text(
DateFormat('EE dd/MM/yyyy').format(request.nextVisitDate),
style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor),
),
],
),
],
),
],
),
),
],
),
),
);
}
}