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.
133 lines
4.4 KiB
Dart
133 lines
4.4 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/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/models/employee.dart';
|
|
import 'package:test_sa/views/widgets/bottom_sheets/selection_bottom_sheet.dart';
|
|
|
|
import '../../../new_views/app_style/app_color.dart';
|
|
|
|
class NurseEmployeeMenu extends StatefulWidget {
|
|
final List<Employee>? list;
|
|
final Employee? initialValue;
|
|
final Function(Employee?) onSelect;
|
|
final String title;
|
|
final bool? enable;
|
|
|
|
const NurseEmployeeMenu({Key? key, this.list, required this.title, required this.onSelect, this.initialValue, this.enable = true}) : super(key: key);
|
|
|
|
@override
|
|
_SingleNurseEmployeeMenuState createState() => _SingleNurseEmployeeMenuState();
|
|
}
|
|
|
|
class _SingleNurseEmployeeMenuState extends State<NurseEmployeeMenu> {
|
|
Employee? _selectedStatus;
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
if (mounted) super.setState(fn);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant NurseEmployeeMenu oldWidget) {
|
|
if (widget.initialValue != null) {
|
|
final result = widget.list?.where((element) {
|
|
return element.id == widget.initialValue?.id;
|
|
}) ??
|
|
[];
|
|
if (result.isNotEmpty) {
|
|
_selectedStatus = result.first;
|
|
} else {
|
|
_selectedStatus = null;
|
|
}
|
|
if ((widget.initialValue?.id ?? "") != (_selectedStatus?.id ?? "")) {
|
|
widget.onSelect!(_selectedStatus!);
|
|
}
|
|
} else {
|
|
_selectedStatus = null;
|
|
}
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
if (widget.initialValue != null) {
|
|
final result = widget.list?.where((element) {
|
|
return element.id == widget.initialValue?.id;
|
|
}) ??
|
|
[];
|
|
if (result.isNotEmpty) _selectedStatus = result.first;
|
|
if (widget.initialValue?.id != _selectedStatus?.id) {
|
|
widget.onSelect(_selectedStatus);
|
|
}
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 60.toScreenHeight,
|
|
width: double.infinity,
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
|
decoration: BoxDecoration(
|
|
color: context.isDark && (widget.enable == false)
|
|
? AppColor.neutral50
|
|
: (widget.enable == false)
|
|
? AppColor.neutral40
|
|
: AppColor.background(context),
|
|
borderRadius: BorderRadius.circular(10),
|
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
|
),
|
|
child: Stack(
|
|
alignment: Alignment.centerLeft,
|
|
children: [
|
|
PositionedDirectional(
|
|
end: 0,
|
|
child: Icon(
|
|
Icons.keyboard_arrow_down_rounded,
|
|
color: widget.enable == null ? null : Colors.grey,
|
|
)),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
widget.title,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500),
|
|
),
|
|
Text(
|
|
_selectedStatus?.name?.cleanupWhitespace?.capitalizeFirstOfEach ?? context.translation.select,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
).onPress(((widget.enable ?? false)
|
|
? () async {
|
|
_selectedStatus = (await showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(
|
|
top: Radius.circular(20),
|
|
),
|
|
),
|
|
clipBehavior: Clip.antiAliasWithSaveLayer,
|
|
builder: (BuildContext context) => SelectionBottomSheet(
|
|
items: widget.list ?? [],
|
|
selectedItem: _selectedStatus,
|
|
title: widget.title,
|
|
builderString: (emp) => emp?.name ?? "",
|
|
),
|
|
)) as Employee?;
|
|
if (_selectedStatus != null) setState(() {});
|
|
widget.onSelect(_selectedStatus!);
|
|
}
|
|
: null));
|
|
}
|
|
}
|