Reputation: 1950
I have a TextFormField, which, when users delete the text they have entered, they can currently also delete this initial value. I want to make it so my users can never delete the initial value, which is their country's currency symbol, in the TextFormField. I don't want to change it to a hintText because I always want to show the currency Symbol to the user as they type in text. This is my code below:
Padding(
padding: EdgeInsets.only(bottom: 40),
child: TextFormField(
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^\d+\.?\d{0,2}')),
],
autocorrect: false,
keyboardType: TextInputType.numberWithOptions(decimal: true,),
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none,
),
autofocus: true,
initialValue: '${Provider.of<Data>(context, listen: false).format.currencySymbol}',
keyboardAppearance: Brightness.dark,
style: TextStyle(
fontFamily: 'Lato',
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
),
Upvotes: 1
Views: 950
Reputation: 268444
It's not going to be easy without setting up a TextEditingController
for what you're asking for. I'd suggest you to use prefixText
property for your currency symbol
.
decoration: InputDecoration(prefixText: '\$'),
Upvotes: 1