Comprehensive guide for configuring text behavior in FlutterDropdownButton.text().
The TextDropdownConfig class provides precise control over text rendering, overflow behavior, and styling in text mode.
Since 2.4.0 text mode is not limited to String: pass a label callback and any T renders as text, keeping the tooltip, the overflow handling and the default search filter.
FlutterDropdownButton<String>.text(
items: ['Short', 'Medium text', 'Very long text that might overflow'],
onChanged: (value) {},
// Uses TextDropdownConfig.defaultConfig by default
)FlutterDropdownButton<String>.text(
items: ['Option 1', 'Option 2'],
onChanged: (value) {},
config: TextDropdownConfig(
overflow: TextOverflow.ellipsis,
maxLines: 1,
textStyle: TextStyle(fontSize: 16),
),
)Shows "..." when text is too long:
TextDropdownConfig(
overflow: TextOverflow.ellipsis,
maxLines: 1,
)Result: "This is a very long text t..."
Gradually fades out overflowing text:
TextDropdownConfig(
overflow: TextOverflow.fade,
maxLines: 1,
)Cuts off text abruptly:
TextDropdownConfig(
overflow: TextOverflow.clip,
maxLines: 1,
)Result: "This is a very long text t"
Allows text to overflow (may cause layout issues):
TextDropdownConfig(
overflow: TextOverflow.visible,
maxLines: 1,
)TextDropdownConfig(
maxLines: 3,
overflow: TextOverflow.ellipsis,
softWrap: true,
)TextDropdownConfig(
maxLines: null, // No limit
overflow: TextOverflow.visible,
softWrap: true,
)Handle \n characters in text:
FlutterDropdownButton<String>.text(
items: [
'Single line',
'Multi-line text\nwith explicit\nbreaks',
],
config: TextDropdownConfig(
maxLines: 3,
softWrap: true,
),
itemHeight: 60, // Increase height for multi-line
onChanged: (value) {},
)TextDropdownConfig(
textStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black87,
),
hintStyle: TextStyle(
fontSize: 16,
color: Colors.grey[500],
fontStyle: FontStyle.italic,
),
)TextDropdownConfig(
textStyle: TextStyle(fontSize: 16),
selectedTextStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.blue[700],
),
)TextDropdownConfig(
textStyle: TextStyle(
fontFamily: 'Roboto',
fontSize: 14,
letterSpacing: 0.5,
),
)TextDropdownConfig(
textAlign: TextAlign.start,
)TextDropdownConfig(
textAlign: TextAlign.center,
)TextDropdownConfig(
textAlign: TextAlign.end,
)TextDropdownConfig(
textAlign: TextAlign.justify,
maxLines: null,
softWrap: true,
)FlutterDropdownButton<String>.text(
config: TextDropdownConfig.defaultConfig,
// Equivalent to:
// TextDropdownConfig(
// overflow: TextOverflow.ellipsis,
// maxLines: 1,
// )
)FlutterDropdownButton<String>.text(
config: TextDropdownConfig.multiLine,
itemHeight: 80, // Increase height for multi-line
// Equivalent to:
// TextDropdownConfig(
// maxLines: null,
// overflow: TextOverflow.visible,
// softWrap: true,
// )
)FlutterDropdownButton<String>.text(
config: TextDropdownConfig.centered,
// Equivalent to:
// TextDropdownConfig(
// textAlign: TextAlign.center,
// )
)FlutterDropdownButton<String>.text(
config: TextDropdownConfig.fadeOverflow,
// Equivalent to:
// TextDropdownConfig(
// overflow: TextOverflow.fade,
// )
)TextDropdownConfig(
textDirection: TextDirection.rtl,
textAlign: TextAlign.start, // Will align to right in RTL
)TextDropdownConfig(
semanticsLabel: 'Fruit selection dropdown',
textScaler: TextScaler.linear(1.2), // Larger text for accessibility
)semanticsLabel describes the button. A screen reader announces it alongside
the selected value — "Fruit selection dropdown, Banana" — not in place of it.
Menu items do not take the label — each announces its own text, plus whether it
is the chosen one (selected), which is the only place that state exists for a
screen reader: on screen it is a colour.
TextDropdownConfig(
locale: Locale('ar'), // Arabic locale
textDirection: TextDirection.rtl,
)TextDropdownConfig buildConfig(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final isTablet = screenWidth > 600;
return TextDropdownConfig(
textStyle: TextStyle(
fontSize: isTablet ? 18 : 14,
),
maxLines: isTablet ? 2 : 1,
);
}TextDropdownConfig buildThemedConfig(BuildContext context) {
final theme = Theme.of(context);
return TextDropdownConfig(
textStyle: theme.textTheme.bodyMedium,
hintStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.hintColor,
),
selectedTextStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.primaryColor,
fontWeight: FontWeight.w600,
),
);
}FlutterDropdownButton<String>.text(
items: [
'Apple Inc. (AAPL)',
'Microsoft Corporation (MSFT)',
'Alphabet Inc. Class A (GOOGL)',
],
maxWidth: 200,
config: TextDropdownConfig(
overflow: TextOverflow.ellipsis,
textStyle: TextStyle(fontSize: 14),
),
onChanged: (value) {},
)FlutterDropdownButton<String>.text(
items: [
'Option 1\nShort description',
'Option 2\nA longer description that explains the purpose of this option',
],
itemHeight: 60,
config: TextDropdownConfig(
maxLines: 2,
textStyle: TextStyle(fontSize: 14, height: 1.3),
overflow: TextOverflow.ellipsis,
),
onChanged: (value) {},
)FlutterDropdownButton<String>.text(
items: ['English', '中文', 'العربية', 'עברית'],
config: TextDropdownConfig(
textAlign: TextAlign.center,
textStyle: TextStyle(fontSize: 16),
),
onChanged: (value) {},
)// For single-line text
itemHeight: 48
// For two-line text
itemHeight: 64
// For three-line text
itemHeight: 80TextDropdownConfig(
textScaler: MediaQuery.textScalerOf(context),
)Ensure text is readable against the background:
TextDropdownConfig(
textStyle: TextStyle(
color: Theme.of(context).textTheme.bodyMedium?.color,
),
)Choose appropriate overflow behavior for your content:
- Ellipsis: Best for single-line critical text
- Fade: Good for less important overflow text
- Multi-line: For descriptive or detailed content