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.
125 lines
4.1 KiB
Dart
125 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/models/lookup.dart';
|
|
|
|
import '../../../new_views/app_style/app_color.dart';
|
|
|
|
class SingleStatusMenu extends StatefulWidget {
|
|
final List<Lookup> statuses;
|
|
final Lookup initialStatus;
|
|
final Function(Lookup) onSelect;
|
|
final bool enabled;
|
|
final String title;
|
|
|
|
const SingleStatusMenu({Key key, this.enabled = true, this.title, this.statuses, this.onSelect, this.initialStatus}) : super(key: key);
|
|
|
|
@override
|
|
_SingleStatusMenuState createState() => _SingleStatusMenuState();
|
|
}
|
|
|
|
class _SingleStatusMenuState extends State<SingleStatusMenu> {
|
|
Lookup _selectedStatus;
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
if (mounted) super.setState(fn);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant SingleStatusMenu oldWidget) {
|
|
if (widget.initialStatus != null) {
|
|
final result = widget.statuses?.where((element) {
|
|
return element == widget.initialStatus;
|
|
});
|
|
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 == widget.initialStatus;
|
|
});
|
|
if (result.isNotEmpty) _selectedStatus = result.first;
|
|
if (widget.initialStatus.id != _selectedStatus?.id) {
|
|
widget.onSelect(_selectedStatus);
|
|
}
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 60.toScreenHeight,
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
|
decoration: BoxDecoration(
|
|
color: context.isDark ? AppColor.neutral50 : Colors.white,
|
|
borderRadius: BorderRadius.circular(10),
|
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
|
),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
if (widget.enabled) const PositionedDirectional(end: 0, child: Icon(Icons.keyboard_arrow_down_rounded)),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
if (widget.title != null)
|
|
Text(
|
|
widget.title,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500),
|
|
),
|
|
DropdownButton<Lookup>(
|
|
value: _selectedStatus,
|
|
iconSize: 24,
|
|
isDense: true,
|
|
icon: const SizedBox.shrink(),
|
|
elevation: 0,
|
|
isExpanded: true,
|
|
hint: Text(
|
|
context.translation.select,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
style: TextStyle(color: Theme.of(context).primaryColor),
|
|
underline: const SizedBox.shrink(),
|
|
onChanged: widget.enabled == false
|
|
? null
|
|
: (Lookup newValue) {
|
|
setState(() {
|
|
_selectedStatus = newValue;
|
|
});
|
|
widget.onSelect(newValue);
|
|
},
|
|
items: widget.statuses?.map<DropdownMenuItem<Lookup>>((value) {
|
|
return DropdownMenuItem<Lookup>(
|
|
value: value,
|
|
child: Text(
|
|
value?.name ?? "",
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
);
|
|
})?.toList(),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|