Code from 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 _n1Controller = TextEditingController();
TextEditingController _n2Controller = TextEditingController();
int _sum = 0;
@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: _n1Controller,
decoration: InputDecoration(
labelText: " First Number ",
hintText: "Enter first number here",
border: OutlineInputBorder(
borderSide: const BorderSide(
width: 1,
color: Colors.blue,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
),
),
const SizedBox(
height: 10.0,
),
TextField(
controller: _n2Controller,
decoration: InputDecoration(
labelText: " Second Number ",
hintText: "Enter second number here",
border: OutlineInputBorder(
borderSide: const BorderSide(
width: 1,
color: Colors.blue,
),
borderRadius: BorderRadius.circular(
5.0,
),
),
),
),
const SizedBox(
height: 10.0,
),
ElevatedButton(
onPressed: () {
int x = int.parse(_n1Controller.text);
int y = int.parse(_n2Controller.text);
setState(() {
_sum = x + y;
});
},
child: const Text(
"Compute Sum",
),
),
const SizedBox(
height: 15.0,
),
Text(
_sum.toString(),
style: const TextStyle(fontSize: 30.0),
)
],
),
),
),
);
}
}
No comments:
Post a Comment