<p>This can be achieved by adding a controller to the TextField of type font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre-wrap; background-color: rgb(30, 30, 30); color: rgb(78, 201, 176);](TextEditingControllercolor: rgb(212, 212, 212); font-family: Consolas, "Courier New", monospace; font-size: 14px; white-space: pre-wrap; background-color: rgb(30, 30, 30);]( . Here is how the output is going to look. ; background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre-wrap;](color: #569cd6;](import color: #ce9178;]('package:flutter/material.dart'; color: #569cd6;](void color: #dcdcaa;](main() => color: #dcdcaa;](runApp(color: #4ec9b0;](MyApp()); color: #569cd6;](class color: #4ec9b0;](MyApp color: #569cd6;](extends color: #4ec9b0;](StatelessWidget { color: #569cd6;](@override color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #4ec9b0;](MaterialApp( title: color: #ce9178;]('Flutter TextField Demo', theme: color: #4ec9b0;](ThemeData( primarySwatch: color: #4ec9b0;](Colors.blue, ), home: color: #4ec9b0;](MyHomePage(title: color: #ce9178;]('Flutter TextField Demo'), ); }} color: #569cd6;](class color: #4ec9b0;](MyHomePage color: #569cd6;](extends color: #4ec9b0;](StatefulWidget { color: #4ec9b0;](MyHomePage({color: #4ec9b0;](Key key, color: #569cd6;](this.title}) : color: #569cd6;](super(key: key); color: #569cd6;](final color: #4ec9b0;](String title; color: #569cd6;](@override color: #4ec9b0;](_MyHomePageState color: #dcdcaa;](createState() => color: #4ec9b0;](_MyHomePageState();} color: #569cd6;](class color: #4ec9b0;](_MyHomePageState color: #569cd6;](extends color: #4ec9b0;](State { color: #4ec9b0;](String _inputtext; color: #4ec9b0;](TextEditingController inputtextField = color: #4ec9b0;](TextEditingController(); color: #569cd6;](void color: #dcdcaa;](_processText() { color: #dcdcaa;](setState(() ); } color: #569cd6;](@override color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) { color: #c586c0;](return color: #4ec9b0;](Scaffold( appBar: color: #4ec9b0;](AppBar( title: color: #4ec9b0;](Text(widget.title), ), body: color: #4ec9b0;](Center( child: color: #4ec9b0;](Column( mainAxisAlignment: color: #4ec9b0;](MainAxisAlignment.center, children: [ color: #4ec9b0;](Padding( padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](16.0), child: color: #4ec9b0;](TextField( controller: inputtextField, decoration: color: #4ec9b0;](InputDecoration( border: color: #4ec9b0;](OutlineInputBorder(), labelText: color: #ce9178;]('Enter some text' ), ), ), color: #4ec9b0;](Padding( padding: color: #569cd6;](const color: #4ec9b0;](EdgeInsets.color: #dcdcaa;](all(color: #b5cea8;](16.0), child: color: #4ec9b0;](Text( color: #ce9178;]('$color: #9cdcfe;](_inputtextcolor: #ce9178;](', style: color: #4ec9b0;](Theme.color: #dcdcaa;](of(context).textTheme.display1, ), ), color: #4ec9b0;](RaisedButton( onPressed: _processText, child: color: #4ec9b0;](Text(color: #ce9178;]('Process Text'), ) ], ), ), ); }}</p> <p>Hope this is helpful to you. Thanks,Srikanth</p>
How to get Text from TextField on button click?
This Article is posted by seven.srikanth at 1/3/2020 4:38:08 AM
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter
Tags:
Check out our other latest articles
Safearea widget - How to avoid visual overlap with Notch on flutter mobile app?How to convert row of widgets into column of widgets in flutter based on screen size?
How to run Flutter programs from GitHub?
How to get screen orientation in flutter?
NavigationRail example in flutter
1 Comments
Recent Comments

pc_systemx1 at 3/26/2024
Hello friend, I have corrected the code today 2024: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter TextField Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter TextField Demo'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { String _inputtext=''; TextEditingController inputtextField = TextEditingController(); void _processText() { setState(() { _inputtext = inputtextField.text; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Padding( padding: const EdgeInsets.all(16.0), child: TextField( controller: inputtextField, decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Enter some text' ), ), ), Padding( padding: const EdgeInsets.all(16.0), child: Text( '$_inputtext', style: Theme.of(context).textTheme.headline5, ), ), ElevatedButton( onPressed: _processText, child: Text('Process Text'), ) ], ), ), ); } }