Code as seen in the video:
import 'package:flutter/material.dart';
import 'package:lessons/second_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _nameController = TextEditingController();
TextEditingController _commentsController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Hello World',
style: TextStyle(color: Colors.white),
),
centerTitle: true,
backgroundColor: Colors.blue,
elevation: 10.0,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
const Text(
"Flutter University",
style: TextStyle(fontSize: 30.0),
),
const SizedBox(
height: 10.0,
),
TextField(
controller: _nameController,
// keyboardType: const TextInputType.numberWithOptions(
// decimal: true), //can see only in a mobile emulator
decoration: InputDecoration(
labelText: " Name ",
hintText: "Enter your name...",
prefixIcon: const Icon(Icons.verified_user),
prefixIconColor: Colors.green,
border: OutlineInputBorder(
borderSide: const BorderSide(
width: 1,
color: Colors.blue,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
),
),
const SizedBox(
height: 10.0,
),
TextField(
controller: _commentsController,
maxLines: 3,
decoration: InputDecoration(
labelText: " Comments ",
hintText: "Enter your comments here...",
border: OutlineInputBorder(
borderSide: const BorderSide(
width: 1,
color: Colors.blue,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
),
),
const SizedBox(
height: 10.0,
),
ElevatedButton(
onPressed: () {
SnackBar snackBar = SnackBar(
content: Text(
"Your name is ${_nameController.text} and your comment is ${_commentsController.text}"),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: const Text(
"Click Me",
),
),
],
),
),
),
);
}
}
No comments:
Post a Comment