timer implemented
parent
6722e19cc5
commit
8b0bf4bedc
@ -1,131 +1,164 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart';
|
||||||
import 'package:test_sa/extensions/context_extension.dart';
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
import'package:test_sa/extensions/int_extensions.dart';
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
import 'package:test_sa/extensions/text_extensions.dart';
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/views/widgets/bottom_sheets/selection_bottom_sheet.dart';
|
||||||
|
|
||||||
import '../../../models/new_models/assistant_employee.dart';
|
import '../../../models/new_models/assistant_employee.dart';
|
||||||
import '../../../new_views/app_style/app_color.dart';
|
import '../../../new_views/app_style/app_color.dart';
|
||||||
|
|
||||||
class AssistantEmployeeMenu extends StatefulWidget {
|
class AssistantEmployeeMenu extends StatefulWidget {
|
||||||
final List<AssistantEmployees> statuses;
|
final List<AssistantEmployees> statuses;
|
||||||
Color? backgroundColor;
|
Color? backgroundColor;
|
||||||
final AssistantEmployees? initialStatus; // Now nullable
|
final AssistantEmployees? initialStatus; // Now nullable
|
||||||
final Function(AssistantEmployees?) onSelect; // Now accepts nullable values
|
final Function(AssistantEmployees?) onSelect; // Now accepts nullable values
|
||||||
final String? title; // Now nullable
|
final String? title; // Now nullable
|
||||||
final bool enable;
|
final bool enable;
|
||||||
|
bool? showAsBottomSheet = false;
|
||||||
|
|
||||||
AssistantEmployeeMenu({Key? key, required this.statuses, this.title, required this.onSelect, this.initialStatus,this.backgroundColor, this.enable = true}) : super(key: key);
|
AssistantEmployeeMenu({Key? key, required this.statuses, this.title, required this.onSelect, this.initialStatus, this.showAsBottomSheet = false, this.backgroundColor, this.enable = true})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SingleAssistantEmployeeMenuState createState() => _SingleAssistantEmployeeMenuState();
|
_SingleAssistantEmployeeMenuState createState() => _SingleAssistantEmployeeMenuState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SingleAssistantEmployeeMenuState extends State<AssistantEmployeeMenu> {AssistantEmployees? _selectedStatus; // Now nullable
|
class _SingleAssistantEmployeeMenuState extends State<AssistantEmployeeMenu> {
|
||||||
|
AssistantEmployees? _selectedStatus; // Now nullable
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setState(VoidCallback fn) {
|
void setState(VoidCallback fn) {
|
||||||
if (mounted) super.setState(fn);
|
if (mounted) super.setState(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant AssistantEmployeeMenu oldWidget) {
|
void didUpdateWidget(covariant AssistantEmployeeMenu oldWidget) {
|
||||||
if (widget.initialStatus != null) {
|
if (widget.initialStatus != null) {
|
||||||
final result = widget.statuses.where((element) => element.user?.id == widget.initialStatus?.user?.id);
|
final result = widget.statuses.where((element) => element.user?.id == widget.initialStatus?.user?.id);
|
||||||
if (result.isNotEmpty) {
|
if (result.isNotEmpty) {
|
||||||
_selectedStatus = result.first;
|
_selectedStatus = result.first;
|
||||||
|
} else {
|
||||||
|
_selectedStatus = null;
|
||||||
|
}
|
||||||
|
if (widget.initialStatus?.user?.id != _selectedStatus?.user?.id) {
|
||||||
|
widget.onSelect(_selectedStatus);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_selectedStatus = null;
|
_selectedStatus = null;
|
||||||
}
|
}
|
||||||
if (widget.initialStatus?.user?.id != _selectedStatus?.user?.id) {
|
super.didUpdateWidget(oldWidget);
|
||||||
widget.onSelect(_selectedStatus);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_selectedStatus = null;
|
|
||||||
}
|
}
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.initialStatus != null) {
|
if (widget.initialStatus != null) {
|
||||||
final result = widget.statuses.where((element) => element.user?.id == widget.initialStatus?.user?.id);
|
final result = widget.statuses.where((element) => element.user?.id == widget.initialStatus?.user?.id);
|
||||||
if (result.isNotEmpty) {
|
if (result.isNotEmpty) {
|
||||||
_selectedStatus = result.first;
|
_selectedStatus = result.first;
|
||||||
}
|
}
|
||||||
if (widget.initialStatus?.user?.id != _selectedStatus?.user?.id) {
|
if (widget.initialStatus?.user?.id != _selectedStatus?.user?.id) {
|
||||||
widget.onSelect(_selectedStatus);
|
widget.onSelect(_selectedStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
super.initState();
|
||||||
}
|
}
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 60.toScreenHeight,
|
height: 60.toScreenHeight,
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color:widget.backgroundColor ?? (context.isDark ? AppColor.neutral50 : AppColor.neutral120),
|
color: widget.backgroundColor ?? (context.isDark ? AppColor.neutral50 : AppColor.neutral120),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
PositionedDirectional(
|
PositionedDirectional(
|
||||||
end: 0,
|
end: 0,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.keyboard_arrow_down_rounded,
|
Icons.keyboard_arrow_down_rounded,
|
||||||
color: widget.enable ? null : Colors.grey,
|
color: widget.enable ? null : Colors.grey,
|
||||||
),
|
|
||||||
),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
if (widget.title != null)
|
|
||||||
Text(
|
|
||||||
widget.title!, // Non-null assertion after null check
|
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500),
|
|
||||||
),
|
|
||||||
DropdownButton<AssistantEmployees>(
|
|
||||||
value: _selectedStatus,
|
|
||||||
dropdownColor: AppColor.white10,
|
|
||||||
iconSize: 24,
|
|
||||||
isDense: true,
|
|
||||||
icon: const SizedBox.shrink(),
|
|
||||||
elevation: 0,
|
|
||||||
isExpanded: true,
|
|
||||||
hint: Text(
|
|
||||||
context.translation.select,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
),
|
|
||||||
style: AppTextStyles.bodyText2.copyWith(color: AppColor.black20),
|
|
||||||
underline: const SizedBox.shrink(),
|
|
||||||
onChanged: widget.enable
|
|
||||||
? (AssistantEmployees? newValue) { // Now accepts nullable values
|
|
||||||
setState(() {
|
|
||||||
_selectedStatus = newValue;
|
|
||||||
});
|
|
||||||
widget.onSelect(newValue);
|
|
||||||
}
|
|
||||||
:null,
|
|
||||||
items: widget.statuses.map<DropdownMenuItem<AssistantEmployees>>(
|
|
||||||
(AssistantEmployees value) {
|
|
||||||
return DropdownMenuItem<AssistantEmployees>(
|
|
||||||
value: value,
|
|
||||||
child: Text(
|
|
||||||
value.user?.name ?? "NULL", // Use null-aware operator for user.name
|
|
||||||
style: AppTextStyles.bodyText.copyWith(color: AppColor.black20),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
).toList(),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
Column(
|
||||||
],
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
);
|
children: [
|
||||||
|
if (widget.title != null)
|
||||||
|
Text(
|
||||||
|
widget.title!, // Non-null assertion after null check
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
DropdownButton<AssistantEmployees>(
|
||||||
|
value: _selectedStatus,
|
||||||
|
dropdownColor: AppColor.white10,
|
||||||
|
iconSize: 24,
|
||||||
|
isDense: true,
|
||||||
|
icon: const SizedBox.shrink(),
|
||||||
|
elevation: 0,
|
||||||
|
isExpanded: true,
|
||||||
|
hint: Text(
|
||||||
|
context.translation.select,
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.black20),
|
||||||
|
underline: const SizedBox.shrink(),
|
||||||
|
onChanged: widget.enable
|
||||||
|
? (AssistantEmployees? newValue) {
|
||||||
|
// Now accepts nullable values
|
||||||
|
setState(() {
|
||||||
|
_selectedStatus = newValue;
|
||||||
|
});
|
||||||
|
widget.onSelect(newValue);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
items: widget.statuses.map<DropdownMenuItem<AssistantEmployees>>(
|
||||||
|
(AssistantEmployees value) {
|
||||||
|
return DropdownMenuItem<AssistantEmployees>(
|
||||||
|
value: value,
|
||||||
|
child: Text(
|
||||||
|
value.user?.name ?? "NULL", // Use null-aware operator for user.name
|
||||||
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.black20),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
).toList(),
|
||||||
|
).onPress(widget.showAsBottomSheet!
|
||||||
|
? () async {
|
||||||
|
final selectedT = await showModalBottomSheet<AssistantEmployees?>(
|
||||||
|
// Specify return type
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(
|
||||||
|
top: Radius.circular(20),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAliasWithSaveLayer,
|
||||||
|
builder: (BuildContext context) => SelectionBottomSheet<AssistantEmployees>(
|
||||||
|
// Specify generic type
|
||||||
|
items:
|
||||||
|
(Provider.of<ServiceReportAssistantsEmployeeProvider>(context, listen: false).assistantEmployees as List<AssistantEmployees>) ?? [], // Provide default empty list if null
|
||||||
|
selectedItem: _selectedStatus,
|
||||||
|
// title: widget.title,
|
||||||
|
builderString: (emp) => emp?.name ?? "", // Null-aware operator for emp.name
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (selectedT != null) {
|
||||||
|
widget.onSelect!(selectedT); // Non-null assertion after null check
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: null),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue