Is there a way to create a text field with a prefix that is always visible in flutter

This is the perfect solution that worked when I have to display the prefix always visible

prefixIcon: Padding(padding: EdgeInsets.all(15), child: Text('+91 ')),

UPDATE: WE CAN NOW OVERRIDE THE MINIMUM PADDING OF prefixIcon AND suffixIcon WITH prefixIconConstraints.

We can use prefixIcon instead of prefixText. Since prefixIcon accepts any widget, we can use prefixIcon: Text("$").

Here is an example:

InputDecoration(
   isDense: true,
   prefixIcon:Text("$"),
   prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
),

There is a bug that was closed with solution:

Closing for now as it's not possible to keep the prefix text visible in all states with a floating placeholder which is the main usage of this widget.

And some workaround that worked for me:

TextStyle _decorationStyleOf(BuildContext context) {
  final theme = Theme.of(context);
  return theme.textTheme.subhead
      .copyWith(color: theme.hintColor);
}

Stack(
  alignment: Alignment.centerLeft,
  children: <Widget>[
    Builder(
      builder: (context) {
        return Text(
          'prefix',
          style: _decorationStyleOf(context),
        );
      }
    ),
    TextField(
      decoration: InputDecoration(
        prefixText: 'prefix',
        prefixStyle: TextStyle(color: Colors.transparent),
      ),
    ),
  ],
)

Tags:

Flutter