Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Added align text issue: Align Header text and dropdown item text #71 #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/custom_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class CustomDropdown<T> extends StatefulWidget {
/// Text maxlines for header and list item text.
final int maxlines;

/// Text align for head, hint and list item and so on.
/// Default [TextAlign.start]
final TextAlign textAlign;

/// Padding for [CustomDropdown] header (closed state).
final EdgeInsets? closedHeaderPadding;

Expand Down Expand Up @@ -197,6 +201,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.headerBuilder,
this.hintBuilder,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.closedHeaderPadding,
this.expandedHeaderPadding,
Expand Down Expand Up @@ -256,6 +261,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.validator,
this.validateOnChange = true,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.closedHeaderPadding,
this.expandedHeaderPadding,
Expand Down Expand Up @@ -314,6 +320,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.validator,
this.validateOnChange = true,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.closedHeaderPadding,
this.expandedHeaderPadding,
Expand Down Expand Up @@ -358,6 +365,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.canCloseOutsideBounds = true,
this.hideSelectedFieldWhenExpanded = false,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.closedHeaderPadding,
this.expandedHeaderPadding,
Expand Down Expand Up @@ -419,6 +427,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.canCloseOutsideBounds = true,
this.hideSelectedFieldWhenExpanded = false,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.closedHeaderPadding,
this.expandedHeaderPadding,
Expand Down Expand Up @@ -477,6 +486,7 @@ class CustomDropdown<T> extends StatefulWidget {
this.listValidator,
this.validateOnChange = true,
this.maxlines = 1,
this.textAlign = TextAlign.start,
this.overlayHeight,
this.searchRequestLoadingIndicator,
this.closedHeaderPadding,
Expand Down Expand Up @@ -639,6 +649,7 @@ class _CustomDropdownState<T> extends State<CustomDropdown<T>> {
listItemBuilder: widget.listItemBuilder,
layerLink: layerLink,
hideOverlay: hideCallback,
textAlign: widget.textAlign,
hintStyle: decoration?.hintStyle,
headerStyle: decoration?.headerStyle,
noResultFoundStyle: decoration?.noResultFoundStyle,
Expand Down Expand Up @@ -682,6 +693,7 @@ class _CustomDropdownState<T> extends State<CustomDropdown<T>> {
: enabled
? decoration?.closedBorderRadius
: disabledDecoration?.borderRadius,
textAlign: widget.textAlign,
shadow: enabled
? decoration?.closedShadow
: disabledDecoration?.shadow,
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/dropdown_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class _DropDownField<T> extends StatefulWidget {
final Color? fillColor;
final BoxBorder? border;
final BorderRadius? borderRadius;
final TextAlign? textAlign;
final TextStyle? headerStyle, hintStyle;
final Widget? prefixIcon, suffixIcon;
final List<BoxShadow>? shadow;
Expand All @@ -36,6 +37,7 @@ class _DropDownField<T> extends StatefulWidget {
this.fillColor,
this.border,
this.borderRadius,
this.textAlign,
this.hintStyle,
this.headerStyle,
this.headerBuilder,
Expand Down Expand Up @@ -85,6 +87,7 @@ class _DropDownFieldState<T> extends State<_DropDownField<T>> {
return Text(
itemList != null ? itemList.join(', ') : oneItem.toString(),
maxLines: widget.maxLines,
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
style: widget.headerStyle ??
TextStyle(
Expand All @@ -100,6 +103,7 @@ class _DropDownFieldState<T> extends State<_DropDownField<T>> {
hint,
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: widget.textAlign,
style: widget.hintStyle ??
const TextStyle(
fontSize: 16,
Expand Down
5 changes: 5 additions & 0 deletions lib/widgets/dropdown_overlay/dropdown_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _DropdownOverlay<T> extends StatefulWidget {
final Duration? futureRequestDelay;
final int maxLines;
final double? overlayHeight;
final TextAlign? textAlign;
final TextStyle? hintStyle, headerStyle, noResultFoundStyle, listItemStyle;
final EdgeInsets? headerPadding, listItemPadding, itemsListPadding;
final Widget? searchRequestLoadingIndicator;
Expand Down Expand Up @@ -56,6 +57,7 @@ class _DropdownOverlay<T> extends StatefulWidget {
required this.canCloseOutsideBounds,
required this.maxLines,
required this.overlayHeight,
required this.textAlign,
required this.dropdownType,
required this.decoration,
required this.hintStyle,
Expand Down Expand Up @@ -127,6 +129,7 @@ class _DropdownOverlayState<T> extends State<_DropdownOverlay<T>> {
child: Text(
result.toString(),
maxLines: widget.maxLines,
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
style: widget.listItemStyle ?? const TextStyle(fontSize: 16),
),
Expand Down Expand Up @@ -156,6 +159,7 @@ class _DropdownOverlayState<T> extends State<_DropdownOverlay<T>> {
return Text(
items != null ? items.join(', ') : item.toString(),
maxLines: widget.maxLines,
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
style: widget.headerStyle ??
const TextStyle(
Expand All @@ -169,6 +173,7 @@ class _DropdownOverlayState<T> extends State<_DropdownOverlay<T>> {
return Text(
hint,
maxLines: 1,
textAlign: widget.textAlign,
overflow: TextOverflow.ellipsis,
style: widget.hintStyle ??
const TextStyle(
Expand Down