🚀 DevOps Certified Professional
📅 Starting: 1st of Every Month 🤝 +91 8409492687 | 🤝 +1 (469) 756-6329 🔍 Contact@DevOpsSchool.com

Stateful Widget in Flutter.

DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Stateful Widget :- When user interacts with an App and the widget change then it is called Stateful Widget. A Stateful widget is Dynamic.

For Example :- When user click on a button on App and text changes then it is called Stateful Widget.

When the widget’s state changes, the state objects calls setState(), telling the framework to redraw the widget.

Write down the below code in main.dart file in your project.

import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "My App",
home: new HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String myText = "Hello World";
void _changeText() {
setState(() {
if(myText.startsWith("H")){
myText = "welcome To My App";
} else{
myText = "Hello World";
}
});
}
Widget _bodywidget() {
return new Container(
padding: const EdgeInsets.all(8.0),
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(myText),
new RaisedButton(
child: new Text("click"),
onPressed: _changeText,
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Home Page"),
),
body: _bodywidget());
}
}
view raw gistfile1.txt hosted with ❤ by GitHub
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x