FlagSelector class
A highly customizable country selector widget for Flutter.
This widget allows users to select a country from a comprehensive list using different modal interfaces like bottom sheets, dialogs, or popup menus. It supports SVG flags, multilingual country names, and extensive customization options.
Example:
FlagSelector(
flagSelectorLanguageCode: 'en',
flagSelectorInitialCountry: 'us',
onFlagSelectorCountryChanged: (country) {
print('Selected country: ${country.name}');
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- FlagSelector
Constructors
-
FlagSelector({Key? key, FlagSelectorOptionType flagSelectorOptionType = FlagSelectorOptionType.modalBottomSheet, String flagSelectorLanguageCode = 'en', List<
Country> flagSelectorCountries = defaultCountries, String? flagSelectorInitialCountry, ValueChanged<Country> ? onFlagSelectorCountryChanged, EdgeInsetsGeometry? flagSelectorPadding, BoxDecoration? flagSelectorDecoration, double flagSelectorGap = 8.0, double? flagSelectorWidth, double? flagSelectorHeight, Color? flagSelectorBackgroundColor, Clip? flagSelectorClipBehavior, BoxConstraints? flagSelectorConstraints, Decoration? flagSelectorForegroundDecoration, Matrix4? flagSelectorTransform, AlignmentGeometry? flagSelectorTransformAlignment, EdgeInsetsGeometry? flagSelectorMargin, double flagSelectorFlagWidth = 30, double flagSelectorFlagHeight = 20, Widget flagSelectorFlagBuilder(BuildContext, Country)?, TextStyle? flagSelectorTextStyle, String flagSelectorCountryNameBuilder(Country)?, Widget? flagSelectorDropdownIcon, double flagSelectorIconSize = 24, Color? flagSelectorIconColor, bool flagSelectorShowCountryName = true, ModalPickerBuilder? flagSelectorModalBuilder, CountryPickerStyle? flagSelectorPickerStyle, bool flagSelectorShowModalTitle = true, String? flagSelectorModalTitle = 'Select Country', TextStyle? flagSelectorModalTitleStyle, EdgeInsetsGeometry? flagSelectorModalTitlePadding, double flagSelectorModalHeightFactor = 0.7, CountryItemBuilder? flagSelectorCountryItemBuilder, EdgeInsetsGeometry? flagSelectorCountryItemPadding, double? flagSelectorCountryItemHeight, Color? flagSelectorCountryItemColor, Color? flagSelectorSelectedCountryItemColor, SearchInputBuilder? flagSelectorSearchBuilder, InputDecoration? flagSelectorSearchDecoration, TextStyle? flagSelectorSearchTextStyle, String? flagSelectorSearchHintText = 'Search countries...', EdgeInsetsGeometry? flagSelectorSearchPadding, bool flagSelectorShowSearch = true, Color? flagSelectorSearchContainerColor, BorderRadius? flagSelectorSearchContainerBorderRadius, BoxBorder? flagSelectorSearchContainerBorder, List<BoxShadow> ? flagSelectorSearchContainerShadow, EdgeInsetsGeometry? flagSelectorSearchContainerMargin, EdgeInsetsGeometry? flagSelectorSearchContainerPadding, EdgeInsetsGeometry? flagSelectorSearchInputPadding, double? flagSelectorSearchContainerWidth, double? flagSelectorSearchContainerHeight, BoxConstraints? flagSelectorSearchContainerConstraints, bool? flagSearchEnabled}) -
Creates a flag selector widget with customizable appearance and behavior.
const
Properties
- flagSearchEnabled → bool?
-
Whether search functionality is enabled.
final
- flagSelectorBackgroundColor → Color?
-
Background color for the selector container.
final
- flagSelectorClipBehavior → Clip?
-
Determines how the selector's content is clipped.
final
- flagSelectorConstraints → BoxConstraints?
-
Size constraints for the selector container.
final
-
flagSelectorCountries
→ List<
Country> -
The list of countries available for selection.
final
- flagSelectorCountryItemBuilder → CountryItemBuilder?
-
Custom builder for country list items.
final
- flagSelectorCountryItemColor → Color?
-
Background color for country list items.
final
- flagSelectorCountryItemHeight → double?
-
Height of each country list item.
final
- flagSelectorCountryItemPadding → EdgeInsetsGeometry?
-
Padding for country list items.
final
- flagSelectorCountryNameBuilder → String Function(Country)?
-
Custom builder for formatting the country name.
final
- flagSelectorDecoration → BoxDecoration?
-
Decoration for the selector container.
final
- flagSelectorDropdownIcon → Widget?
-
Custom widget for the dropdown indicator.
final
- flagSelectorFlagBuilder → Widget Function(BuildContext, Country)?
-
Custom builder for the flag widget.
final
- flagSelectorFlagHeight → double
-
Height of the flag image.
final
- flagSelectorFlagWidth → double
-
Width of the flag image.
final
- flagSelectorForegroundDecoration → Decoration?
-
Decoration to paint in front of the selector's content.
final
- flagSelectorGap → double
-
The spacing between elements within the selector.
final
- flagSelectorHeight → double?
-
Fixed height for the selector. If null, the height will be determined by its content.
final
- flagSelectorIconColor → Color?
-
Color of the dropdown icon.
final
- flagSelectorIconSize → double
-
Size of the dropdown icon.
final
- flagSelectorInitialCountry → String?
-
The initial country code to be selected when the widget is first built.
final
- flagSelectorLanguageCode → String
-
The language code used for displaying country names.
final
- flagSelectorMargin → EdgeInsetsGeometry?
-
Margin around the selector container.
final
- flagSelectorModalBuilder → ModalPickerBuilder?
-
Custom builder for the entire modal.
final
- flagSelectorModalHeightFactor → double
-
Height of the modal as a factor of the screen height.
final
- flagSelectorModalTitle → String?
-
Text for the modal title.
final
- flagSelectorModalTitlePadding → EdgeInsetsGeometry?
-
Padding around the modal title.
final
- flagSelectorModalTitleStyle → TextStyle?
-
Text style for the modal title.
final
- flagSelectorOptionType → FlagSelectorOptionType
-
The type of selector to show when tapped.
final
- flagSelectorPadding → EdgeInsetsGeometry?
-
Padding around the content of the selector.
final
- flagSelectorPickerStyle → CountryPickerStyle?
-
Global style for the country picker modal.
final
- flagSelectorSearchBuilder → SearchInputBuilder?
-
Custom builder for the search input.
final
- flagSelectorSearchContainerBorder → BoxBorder?
-
Border for the search container.
final
- flagSelectorSearchContainerBorderRadius → BorderRadius?
-
Border radius for the search container.
final
- flagSelectorSearchContainerColor → Color?
-
Background color for the search container.
final
- flagSelectorSearchContainerConstraints → BoxConstraints?
-
Size constraints for the search container.
final
- flagSelectorSearchContainerHeight → double?
-
Height of the search container.
final
- flagSelectorSearchContainerMargin → EdgeInsetsGeometry?
-
Margin around the search container.
final
- flagSelectorSearchContainerPadding → EdgeInsetsGeometry?
-
Padding inside the search container.
final
-
flagSelectorSearchContainerShadow
→ List<
BoxShadow> ? -
Shadow for the search container.
final
- flagSelectorSearchContainerWidth → double?
-
Width of the search container.
final
- flagSelectorSearchDecoration → InputDecoration?
-
Decoration for the search text field.
final
- flagSelectorSearchHintText → String?
-
Hint text for the search input.
final
- flagSelectorSearchInputPadding → EdgeInsetsGeometry?
-
Padding inside the search input field.
final
- flagSelectorSearchPadding → EdgeInsetsGeometry?
-
Padding around the search input.
final
- flagSelectorSearchTextStyle → TextStyle?
-
Text style for the search input.
final
- flagSelectorSelectedCountryItemColor → Color?
-
Background color for the selected country item.
final
- flagSelectorShowCountryName → bool
-
Whether to show the country name in the selector.
final
- flagSelectorShowModalTitle → bool
-
Whether to show the title in the modal.
final
- flagSelectorShowSearch → bool
-
Whether to show the search bar in the modal.
final
- flagSelectorTextStyle → TextStyle?
-
Text style for the country name.
final
- flagSelectorTransform → Matrix4?
-
Transform matrix to apply to the selector.
final
- flagSelectorTransformAlignment → AlignmentGeometry?
-
Alignment of the transform operation.
final
- flagSelectorWidth → double?
-
Fixed width for the selector. If null, the width will be determined by its content.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onFlagSelectorCountryChanged
→ ValueChanged<
Country> ? -
Callback function that is called when a country is selected.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< FlagSelector> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited