I'm trying to create a custom input in Flutter with a superscript text right before the input (which is borderless) like the image:
Asked
Active
Viewed 333 times
2 Answers
0
How about you wrap 'TextFormField' with column widget.
I added full code with screenshot.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _incrementCounter() {
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Text('\$'),
Expanded(
child: TextFormField(),
),
],
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}

KuKu
- 6,654
- 1
- 13
- 25
-
I want only the "$" sign to be up, not the whole TextFormField() – Luis Abe Jun 16 '20 at 13:27
-
I couldn't figure out a code with the '$', but look at the image thats I what I was trying to do. Maybe a better example is this image: [link](https://techpanorama.org/wp-content/uploads/2019/11/5dcafa2b3afd375eb842af8a.jpeg) the user can type the money he is willing to change and the '$' is always at the left-top side of the input – Luis Abe Jun 19 '20 at 14:24
-
I updated full code and screenshot. Is it what you want? – KuKu Jun 19 '20 at 15:01
0
Consider using an icon (attach_money
) and controlling the size (size: 22.0,
) to get the vertical positioning right, instead of a text dollar sign Text('\$'),
Here's the code:
Row(
children: <Widget>[
Icon(
Icons.attach_money,
size: 22.0,
),
//Text('\$'),
Expanded(
child: TextFormField(),
),
],
),
And here's how it looks in my Android emulator:

Mark Gavagan
- 878
- 12
- 45