reduce duplicated code

This commit is contained in:
hannathkadher
2024-09-10 22:57:34 +04:00
parent b362029424
commit b40998558e
7 changed files with 248 additions and 162 deletions

View File

@ -5,11 +5,15 @@ class CustomExpansionTile extends StatefulWidget {
final String title;
final List<Widget>? children;
final bool initiallyExpanded;
final bool? isExpanded; // New parameter to control expansion
final ValueChanged<bool>? onExpansionChanged; // Callback for expansion change
CustomExpansionTile({
required this.title,
this.children,
this.initiallyExpanded = false,
this.isExpanded, // Allow external control over expansion
this.onExpansionChanged, // Notify when expansion changes
});
@override
@ -26,6 +30,16 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
_isExpanded = widget.initiallyExpanded;
}
@override
void didUpdateWidget(CustomExpansionTile oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isExpanded != null && widget.isExpanded != _isExpanded) {
setState(() {
_isExpanded = widget.isExpanded!;
});
}
}
@override
Widget build(BuildContext context) {
return Column(
@ -34,6 +48,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
widget.onExpansionChanged?.call(_isExpanded);
});
},
child: Row(
@ -47,28 +62,22 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
});
},
side: WidgetStateBorderSide.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return const BorderSide(color: ColorsManager.grayBorder);
}
return const BorderSide(color: ColorsManager.grayBorder);
}),
// Customize the color for different checkbox states
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return ColorsManager.grayBorder; // Checked state color
return ColorsManager.grayBorder;
} else {
return ColorsManager.checkBoxFillColor;
}
return ColorsManager
.checkBoxFillColor; // Unchecked state color
}),
checkColor: ColorsManager.whiteColors, // Checkmark color
checkColor: ColorsManager.whiteColors,
),
// Expand/Collapse Icon with reduced size
if (widget.children != null && widget.children!.isNotEmpty)
Icon(
_isExpanded
? Icons.keyboard_arrow_down // Upward arrow when expanded
: Icons
.keyboard_arrow_right, // Right arrow when collapsed
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_right,
color: Colors.grey,
size: 16.0, // Reduced icon size
),
@ -87,7 +96,6 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
],
),
),
// Display children if available and expanded
if (_isExpanded &&
widget.children != null &&
widget.children!.isNotEmpty)

View File

@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
class CustomSearchBar extends StatelessWidget {
final TextEditingController? controller;
final String hintText;
const CustomSearchBar({
Key? key,
this.controller,
this.hintText = 'Search',
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: ColorsManager.whiteColors,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
spreadRadius: 0,
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 20.0),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
),
child: TextField(
controller: controller,
style: const TextStyle(
color: Colors.black,
),
decoration: InputDecoration(
filled: true,
fillColor: ColorsManager.textFieldGreyColor,
hintText: hintText,
hintStyle: TextStyle(
color: Colors.grey[400],
),
suffixIcon: Padding(
padding: const EdgeInsets.only(right: 16),
child: SvgPicture.asset(
Assets.textFieldSearch,
width: 24,
height: 24,
),
),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(12),
),
contentPadding: const EdgeInsets.symmetric(
vertical: 14,
horizontal: 16,
),
),
),
),
);
}
}