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/status/service_request/supplier_engineers_menu.dart

119 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test_sa/models/service_request/search_work_order.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart';
class SupplierEngineersMenu extends StatefulWidget {
final List<SuppPersons> engineers;
final SuppEngineerWorkOrders initialValue;
final Function(SuppEngineerWorkOrders) onSelect;
const SupplierEngineersMenu({Key key, this.engineers, this.onSelect, this.initialValue}) : super(key: key);
@override
SingleAssistantEmployeeMenuState createState() => SingleAssistantEmployeeMenuState();
}
class SingleAssistantEmployeeMenuState extends State<SupplierEngineersMenu> {
SuppPersons _selectedEngineer;
@override
void setState(VoidCallback fn) {
if (mounted) super.setState(fn);
}
@override
void didUpdateWidget(covariant SupplierEngineersMenu oldWidget) {
if (widget.initialValue != null) {
final result = widget.engineers?.where((element) {
return element?.id == widget.initialValue?.supplierContactId;
});
if (result.isNotEmpty) {
_selectedEngineer = result.first;
} else {
_selectedEngineer = null;
}
if ((widget.initialValue?.supplierContactId ?? "") != (_selectedEngineer?.id ?? "")) {
onSelect(_selectedEngineer);
}
} else {
_selectedEngineer = null;
}
super.didUpdateWidget(oldWidget);
}
@override
void initState() {
if (widget.initialValue != null) {
final result = widget.engineers?.where((element) {
return element?.id == widget.initialValue?.supplierContactId;
});
if (result.isNotEmpty) _selectedEngineer = result.first;
if (widget.initialValue?.supplierContactId != _selectedEngineer?.id) {
onSelect(_selectedEngineer);
}
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: AColors.inputFieldBackgroundColor,
border: Border.all(
color: const Color(0xffefefef),
),
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
// boxShadow: const [
// AppStyle.boxShadow
// ]
),
child: DropdownButton<SuppPersons>(
value: _selectedEngineer,
iconSize: 24,
icon: const Icon(Icons.keyboard_arrow_down_rounded),
elevation: 0,
isExpanded: true,
hint: Text("Vendor Engineer", style: Theme.of(context).textTheme.titleMedium),
style: TextStyle(color: Theme.of(context).primaryColor),
underline: const SizedBox.shrink(),
onChanged: (SuppPersons newValue) {
setState(() {
_selectedEngineer = newValue;
});
onSelect(newValue);
},
items: widget.engineers?.map<DropdownMenuItem<SuppPersons>>((SuppPersons value) {
return DropdownMenuItem<SuppPersons>(
value: value,
child: Text(
value?.personName ?? "NULL",
style: Theme.of(context).textTheme.titleMedium.copyWith(
color: Theme.of(context).primaryColor,
fontSize: 11,
//fontWeight: FontWeight.bold
),
),
);
})?.toList(),
),
);
}
void onSelect(SuppPersons engineer) {
widget.onSelect(
SuppEngineerWorkOrders(
id: engineer?.supplierId,
supplierContactId: engineer?.id,
personName: engineer?.personName,
contact: engineer?.contact,
externalEngCode: engineer?.externalEngCode,
email: engineer?.email,
),
);
}
}