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/visits/visit_item.dart

173 lines
6.5 KiB
Dart

3 years ago
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
3 years ago
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/extensions/context_extension.dart';
3 years ago
import 'package:test_sa/models/enums/user_types.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/models/visits/visit.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/widgets/visits/visit_status.dart';
3 years ago
3 years ago
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;
3 years ago
const VisitItem({Key key, this.visit, this.onPressed, this.isSelected = false, this.activeSelectMod = false, this.onLongPress, this.onSelect, this.index}) : super(key: key);
3 years ago
@override
Widget build(BuildContext context) {
UserProvider userProvider = Provider.of<UserProvider>(context);
3 years ago
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;
3 years ago
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
backgroundColor: itemColor,
3 years ago
shape: RoundedRectangleBorder(
3 years ago
borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)),
3 years ago
),
),
3 years ago
onPressed: () {
if (activeSelectMod && userProvider.user.type == UsersTypes.engineer) {
3 years ago
onSelect(visit);
} else {
3 years ago
onPressed(visit);
}
3 years ago
},
onLongPress: userProvider.user.type == UsersTypes.engineer
3 years ago
? () {
onLongPress(visit);
}
: null,
child: Column(
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
"S.N: ${visit.deviceSerialNumber}" ?? "No serial number",
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold),
3 years ago
),
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
3 years ago
child: Visibility(
key: ValueKey(activeSelectMod),
visible: activeSelectMod,
child: SizedBox(
height: 18,
child: Checkbox(
3 years ago
activeColor: Colors.black38,
3 years ago
value: isSelected,
3 years ago
onChanged: (value) {
3 years ago
onSelect(visit);
3 years ago
}),
3 years ago
),
),
),
3 years ago
VisitStatusLabel(
visit: visit,
)
3 years ago
],
),
3 years ago
Divider(
color: onItemColor,
),
2 years ago
Text(
visit.deviceNumber ?? "",
style: Theme.of(context).textTheme.titleMedium.copyWith(color: onItemColor, fontSize: 14),
2 years ago
),
Divider(
color: onItemColor,
),
3 years ago
Row(
children: [
Expanded(
child: Text(
visit.hospitalName ?? "No client found",
style: Theme.of(context).textTheme.titleMedium.copyWith(
3 years ago
color: onItemColor,
fontSize: 14,
),
3 years ago
),
),
3 years ago
],
),
Text(
visit.modelAndBrand ?? "",
style: Theme.of(context).textTheme.titleMedium.copyWith(
3 years ago
color: onItemColor,
fontSize: 14,
),
),
if (visit.employName != null && visit.employName.isNotEmpty) Divider(color: onItemColor),
if (visit.employName != null && visit.employName.isNotEmpty)
Row(
children: [
Expanded(
child: Text(
visit.employName ?? "No employ found",
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 14, fontWeight: FontWeight.bold),
),
3 years ago
),
// Text(
// visit.contactStatus ?? "",
// style: Theme.of(context).textTheme.subtitle1.copyWith(
// color: onItemColor,
// fontSize: 14,
// ),
// ),
],
),
3 years ago
Divider(
color: onItemColor,
),
3 years ago
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.translation.expectDate,
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 14),
3 years ago
),
Text(
visit.expectDate ?? context.translation.noDateFound,
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 14),
3 years ago
),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.translation.actualDate,
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 14),
3 years ago
),
Text(
visit.actualDate ?? context.translation.noDateFound,
style: Theme.of(context).textTheme.titleLarge.copyWith(color: onItemColor, fontSize: 14),
3 years ago
),
],
),
],
),
],
),
),
);
}
}