Skip to content

Commit 57af8c8

Browse files
committed
Commit-1
Added Button and by clicking on that text changes
1 parent 50dbf16 commit 57af8c8

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/main.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,42 @@ class HomePage extends StatefulWidget{
2222
}
2323

2424
class _MyAppState extends State<HomePage>{
25+
26+
String myText = "Hello World";
27+
void _changeText(){
28+
setState(() {
29+
if(myText.startsWith("H")){
30+
myText = "Welcome to app";
31+
}else{
32+
myText = "Hello World";
33+
}
34+
});
35+
}
36+
37+
Widget _bodyWidget(){
38+
return new Container(
39+
padding: const EdgeInsets.all(8.0),
40+
child: new Center(
41+
child: new Column(
42+
mainAxisAlignment: MainAxisAlignment.center,
43+
children: <Widget>[
44+
new Text(myText, style: new TextStyle(fontSize: 20.0),),
45+
new RaisedButton(child: new Text("Click",style: new TextStyle(color: Colors.white),),
46+
onPressed: _changeText,
47+
color: Colors.blue,
48+
)
49+
],),
50+
),
51+
);
52+
53+
}
54+
2555
@override
2656
Widget build(BuildContext context) {
2757
return new Scaffold(
2858
appBar: new AppBar(title: new Text("Home Page"),
2959
),
30-
body: new Center(child: new Text("Hello World"),),
60+
body: _bodyWidget()
3161
);
3262
}
3363

0 commit comments

Comments
 (0)