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