The TextField widget is used to create an input field where the user can enter text.
Users can enter alphanumeric characters, and you can customize them using various properties to control their appearance and behavior.
There Are Some Common Attributes for TextField
File open lib->main.dart file −
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('Baseline Example',
style:TextStyle(fontSize: 20,color: Colors.white)),
),
body: MyApp(),
),
)
);
}
class MyApp extends StatelessWidget {
TextEditingController _textEditingController = TextEditingController();
@override
Widget build(BuildContext context) {
return
Column(
children: [
Padding(
padding: EdgeInsets.all(16.0),
child: TextField(
controller: _textEditingController,
decoration: InputDecoration(
labelText: 'Enter your text',
),
),
),
SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
// Access the text using the controller
String enteredText = _textEditingController.text;
print('Entered Text: $enteredText');
},
child: Text('Submit'),
),
],
);
}
}
Open
Device Manager, run the emulator, and then run the application. Next,
check the working output and check the output you declared in your
code.