✅ Flutter Default Counter App Explained Step-by-Step
✅ Flutter Default Counter App Explained Step-by-Step
A Complete Beginner Friendly Guide (LearnWithRehan)
Flutter ko jab bhi aap first time install karke ek new project banate ho, to ek simple sa Counter App automatically create ho jata hai. Ye chhota sa app Flutter ki powerful concept ko samajhne ka best starting point hai.
Is article me hum iss default code ko line-by-line samjhenge, taaki aap Flutter ke basics ko clearly grasp kar sako.
✅ 1. Starting Point of Flutter App
Explanation
-
material.dartFlutter ka design toolkit hai jisme buttons, text fields, appbar jaise ready-made widgets hote hain. -
main()function se app chalna start hota hai. -
runApp(MyApp())Flutter ko batata hai ki screen par kaunsa widget load karna hai.
✅ 2. MyApp Widget: App ka Main Structure
Explanation
-
MyAppek StatelessWidget hai.
Matlab ye khud change nahi hota. -
MaterialApppura app ka outer structure handle karta hai. -
thememe app ka color style define hota hai. -
homeme app ka first screen set kiya jata hai, yahanMyHomePage.
✅ 3. MyHomePage: A Stateful Widget
Why Stateful?
Counter app me number change hota hai.
Isliye ye widget StatefulWidget hai.
Stateful widgets wo hote hain jisme UI user interaction ke according change hota hai.
✅ 4. Handling the Counter Logic
Explanation
-
_countervariable button press count karta hai. -
_incrementCounter()mesetState()call hota hai. -
setState()Flutter ko bolta hai:“Data change hua hai, screen ko dobara build karo.”
✅ 5. Building the User Interface (UI)
Explanation
✅ Scaffold
App ka basic layout banata hai (AppBar, Body, FAB).
✅ AppBar
-
Top bar showing the screen title.
-
Theme colors automatically handle design.
✅ Body
-
Center: content ko middle me rakhta hai. -
Column: elements ko vertically arrange karta hai. -
First
Text: description. -
Second
Text: counter value show karta hai.
✅ FloatingActionButton
Button dabane par counter increase hota hai.
onPressed: _incrementCounter isi ka kaam karta hai.
✅ Final Summary (Easy to Remember)
What happens in the app?
-
App load hoti hai →
main()run hota hai. -
MyAppstart hota hai → MaterialApp layout set hota hai. -
Homepage load hota hai → counter = 0.
-
Button dabate ho → counter +1 → UI refresh.
-
Screen updated number show karti hai.
✅ Why This App Is Important For Beginners?
-
You learn Stateless vs Stateful Widgets
-
You understand setState()
-
You see how MaterialApp, Scaffold, AppBar, Column work
-
You get idea of UI rebuild concept
-
It builds a strong base for Flutter development
Comments
Post a Comment