-
Notifications
You must be signed in to change notification settings - Fork 104
/
textfield.dart
73 lines (67 loc) · 2.17 KB
/
textfield.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'package:flutter/material.dart';
class MyTextField extends StatefulWidget {
const MyTextField({Key? key}) : super(key: key);
@override
State<MyTextField> createState() => _MyTextFieldState();
}
class _MyTextFieldState extends State<MyTextField> {
// use this controller to get what the user typed
final _textController = TextEditingController();
// store user text input into a variable
String userPost = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Text Field")),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
// display text
Expanded(
child: Center(
child: Text(
userPost,
style: const TextStyle(fontSize: 24),
),
),
),
// text input
TextField(
controller: _textController,
decoration: InputDecoration(
hintText: 'What\'s on your mind?',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
onPressed: () {
// clear whats currently in the TextField
_textController.clear();
},
icon: const Icon(Icons.clear),
),
),
),
const SizedBox(height: 10),
MaterialButton(
onPressed: () {
// update our string variable to get the new user input
setState(() {
userPost = _textController.text;
});
},
color: Colors.deepPurple[300],
child: const Text(
"POST",
style: TextStyle(fontSize: 20, color: Colors.white),
),
)
],
),
),
),
);
}
}