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.
185 lines
6.3 KiB
Dart
185 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../api/user_api_client.dart';
|
|
import '../../../controllers/localization/localization.dart';
|
|
import '../../../models/enums/user_types.dart';
|
|
import '../../../models/visits/visit.dart';
|
|
import '../../app_style/sizing.dart';
|
|
import 'visit_status.dart';
|
|
|
|
class VisitItem extends StatelessWidget {
|
|
final Visit visit;
|
|
final int index;
|
|
final bool isSelected;
|
|
final bool activeSelectMod;
|
|
final Function(Visit) onPressed;
|
|
final Function(Visit) onLongPress;
|
|
final Function(Visit) onSelect;
|
|
|
|
const VisitItem({
|
|
Key? key,
|
|
this.isSelected = false,
|
|
this.activeSelectMod = false,
|
|
required this.visit,
|
|
required this.onPressed,
|
|
required this.onLongPress,
|
|
required this.onSelect,
|
|
required this.index,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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;
|
|
final subtitle = AppLocalization.of(context)?.subtitle;
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
primary: itemColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)),
|
|
),
|
|
),
|
|
onPressed: () {
|
|
if (activeSelectMod && UserApiClient().user?.roles == UsersTypes.engineer.name) {
|
|
onSelect(visit);
|
|
} else {
|
|
onPressed(visit);
|
|
}
|
|
},
|
|
onLongPress: UserApiClient().user?.roles == UsersTypes.engineer.name
|
|
? () {
|
|
onLongPress(visit);
|
|
}
|
|
: null,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
"S.N: ${visit.assetSerialNo ?? "No serial number"}",
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 400),
|
|
child: Visibility(
|
|
key: ValueKey(activeSelectMod),
|
|
visible: activeSelectMod,
|
|
child: SizedBox(
|
|
height: 18,
|
|
child: Checkbox(
|
|
activeColor: Colors.black38,
|
|
value: isSelected,
|
|
onChanged: (value) {
|
|
onSelect(visit);
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
VisitStatusLabel(
|
|
visit: visit,
|
|
)
|
|
],
|
|
),
|
|
Divider(
|
|
color: onItemColor,
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
visit.assetSerialNo ?? "No client found",
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
visit.modelName ?? "",
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
Divider(
|
|
color: onItemColor,
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
visit.assignedEmployeeName ?? "No employ found",
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(color: onItemColor, fontSize: 14, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
Text(
|
|
visit.deviceStatusName ?? "",
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Divider(
|
|
color: onItemColor,
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
subtitle?.expectDate ?? '',
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
Text(
|
|
visit.expectedDate ?? subtitle?.noDateFound ?? '',
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
subtitle?.actualDate ?? '',
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
Text(
|
|
visit.actualDate ?? subtitle?.noDateFound ?? '',
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: onItemColor,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|