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.
113 lines
3.3 KiB
Dart
113 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/models/fault_description.dart';
|
|
import 'package:test_sa/views/app_style/colors.dart';
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
|
|
class FaultDescriptionMenu extends StatefulWidget {
|
|
final List<FaultDescription> statuses;
|
|
final FaultDescription initialStatus;
|
|
final Function(FaultDescription) onSelect;
|
|
|
|
const FaultDescriptionMenu({Key key, this.statuses, this.onSelect, this.initialStatus}) : super(key: key);
|
|
|
|
@override
|
|
_SingleStatusMenuState createState() => _SingleStatusMenuState();
|
|
}
|
|
|
|
class _SingleStatusMenuState extends State<FaultDescriptionMenu> {
|
|
FaultDescription _selectedStatus;
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
if (mounted) super.setState(fn);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant FaultDescriptionMenu oldWidget) {
|
|
if (widget.initialStatus != null) {
|
|
final result = widget.statuses?.where((element) {
|
|
return element.id == widget.initialStatus.id;
|
|
});
|
|
if (result.isNotEmpty) {
|
|
_selectedStatus = result.first;
|
|
} else {
|
|
_selectedStatus = null;
|
|
}
|
|
if ((widget.initialStatus?.id ?? "") != (_selectedStatus?.id ?? "")) {
|
|
widget.onSelect(_selectedStatus);
|
|
}
|
|
} else {
|
|
_selectedStatus = null;
|
|
}
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
|
|
if (widget.initialStatus != null) {
|
|
final result = widget.statuses?.where((element) {
|
|
|
|
return element.id == widget.initialStatus.id;
|
|
});
|
|
if (result.isNotEmpty) _selectedStatus = result.first;
|
|
if (widget.initialStatus.id != _selectedStatus?.id) {
|
|
widget.onSelect(_selectedStatus);
|
|
}
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
decoration: BoxDecoration(
|
|
color: AColors.inputFieldBackgroundColor,
|
|
border: Border.all(
|
|
color: Color(0xffefefef),
|
|
),
|
|
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
|
// boxShadow: const [
|
|
// AppStyle.boxShadow
|
|
// ]
|
|
),
|
|
child: DropdownButton<FaultDescription>(
|
|
value: _selectedStatus,
|
|
iconSize: 24,
|
|
icon: const Icon(Icons.keyboard_arrow_down_rounded),
|
|
elevation: 0,
|
|
isExpanded: true,
|
|
hint: Text(
|
|
"Select",
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
),
|
|
style: TextStyle(color: Theme.of(context).primaryColor),
|
|
underline: SizedBox.shrink(),
|
|
onChanged: (FaultDescription newValue) {
|
|
setState(() {
|
|
_selectedStatus = newValue;
|
|
});
|
|
widget.onSelect(newValue);
|
|
},
|
|
items: widget.statuses.map<DropdownMenuItem<FaultDescription>>(
|
|
(FaultDescription value) {
|
|
return DropdownMenuItem<FaultDescription>(
|
|
value: value,
|
|
child: Text(
|
|
value.defectName ?? "",
|
|
style: Theme.of(context).textTheme.subtitle1.copyWith(
|
|
color: Theme.of(context).primaryColor,
|
|
fontSize: 11,
|
|
//fontWeight: FontWeight.bold
|
|
),
|
|
),
|
|
);
|
|
},
|
|
).toList(),
|
|
),
|
|
);
|
|
}
|
|
}
|