Flutter for Beginners widgets types.pptx

DrAbiramiAnandhan 13 views 70 slides Oct 24, 2025
Slide 1
Slide 1 of 70
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70

About This Presentation

Flutter is an open-source user interface software development kit created by Google, designed to build beautiful, fast, and native-compiled applications for multiple platforms from a single codebase. Introduced publicly in 2017 after its initial beta releases, Flutter has revolutionized the world of...


Slide Content

Flutter for Beginners Dr.T.Abirami Associate Professor Department of Information Technology Kongu Engineering College Perundurai [email protected] 9788654804

🦋 What is Flutter? Flutter is an open-source UI framework created by Google for building beautiful, fast, cross-platform apps — from a single codebase. one set of Dart code to make: ✅ Android apps ✅ iOS apps ✅ Web apps ✅ Windows, macOS, and Linux desktop apps 💡 Write once, run anywhere.

🎯 Purpose / Why Flutter was created developers had to build separate apps for Android (Java/Kotlin) and iOS (Swift/Objective-C). Flutter’s goal is to remove that duplication . Purpose: To build multi-platform apps using a single language (Dart) . To give native performance and beautiful UI on every device. To make development faster using Hot Reload (you can see changes instantly).

⚙️ What is Flutter used for? Flutter is used to create: 🌍 Web apps (like dashboards, e-commerce sites, portals) 📱 Mobile apps (like Google Ads, Dream11, eBay Motors, BMW app) 💻 Desktop apps (like productivity or control panel tools) 🔌 Embedded UI (IoT devices, smart displays)

💡 Need for Flutter Develop Android + iOS + Web apps quickly. Maintain only one codebase instead of multiple. Create modern, visually rich UIs. Avoid learning multiple languages (Kotlin, Swift, JS). Save time, money, and reduce bugs across platforms.

🚀 Advantages of Flutter Feature Description Single codebase One Dart code runs on all platforms. Fast development (Hot Reload) UI/code changes instantly without full rebuild. Beautiful UI Uses its own rendering engine ( Skia ), not native components. High performance Compiles to native ARM code, runs fast like native apps. Open-source Free, large global community by Google. Strong community & packages 30,000+ plugins on pub.dev (e.g., Firebase, camera, maps). Custom widgets Build attractive, animated, and responsive UIs easily. Supports web and desktop Same app runs in Chrome, Windows, macOS, Linux.

🧩 Programming Language used Flutter uses Dart , also developed by Google. Dart is easy to learn for anyone with Java, C++, or Python background.

🛠️ Tools required to install Flutter Tool Purpose Git Used to download Flutter SDK and manage updates Dart SDK Comes with Flutter (no separate install needed) VS Code or any Editor For writing Flutter code Chrome browser To run Flutter Web apps Command line / Terminal To run Flutter commands

🧩 Optional (for Android/iOS development) Android SDK or Android Studio (for emulators and native build tools) Xcode (only for macOS users building iOS apps)

🧭 Installation (Step-by-Step) 🔹 Step 1: Download Flutter SDK 👉 Official site: https://docs.flutter.dev/get-started/quick Choose your OS: Flutter for Windows Flutter for macOS Flutter for Linux

Step 2: Extract and add to PATH git clone https://github.com/flutter/flutter.git -b stable C:\src\flutter setx PATH "%PATH%;C:\ src \flutter\bin"

Verify installation and enable web flutter --version

Verify installation and enable web flutter channel stable This command switches your Flutter SDK to use the Stable channel — the safest and most reliable version of Flutter. Internally, Flutter SDK is just a Git repository. So, this command: flutter channel stable is equivalent to: git checkout stable

Flutter is developed continuously by Google and has different release channels — like "branches" in Git — representing different stability levels of the SDK. Flutter has four main channels: Channel Description Update Frequency Use Case stable Officially tested, production-ready releases ~Every 3 months For app releases, reliability beta Next version candidate; mostly stable but may have minor bugs Monthly Testing upcoming features early dev Frequently updated, less tested Weekly For developers who need latest framework improvements master Latest commits from Flutter’s GitHub (bleeding edge) Daily For Flutter contributors or very advanced users Flutter channel

Create and run your first app Step 1 : flutter create hello_world Step 2: cd hello_world Step 3: flutter run -d chrome

project tree hello_world / ├─ android/ # Android native project (Gradle, manifests) ├─ ios / # iOS native project (Xcode workspace) ├─ web/ # web build files (if web enabled) ├─ macos / windows/ linux / # optional desktop platform projects ├─ lib/ │ ├─ main.dart # app entry point (your Dart code) │ └─ src / # optional: put feature code here ├─ test/ # unit/widget tests ├─ build/ # generated build outputs (auto-created) ├─ . dart_tool / # tool state (auto-created) ├─ . vscode / or .idea/ # editor config (optional) ├─ pubspec.yaml # project manifest (dependencies, assets) ├─ pubspec.lock # locked dependency versions (auto) ├─ analysis_options.yaml # static analysis rules (optional) ├─ README.md ├─ . gitignore └─ CHANGELOG.md (optional)

Most important files & folders — what they mean lib/ main.dart — entry point. Contains main() and runApp (...). This is where your app starts. Put most of your app code here. Common patterns: lib/ main.dart , lib/ src / or lib/screens/, lib/widgets/, lib/models/. pubspec.yaml (critical) Project name, description, version. dependencies: — packages your app uses (e.g., flutter, cupertino_icons , http). dev_dependencies : — test/lint tools. flutter: section — where you list assets and fonts.

Flutter Programming https://api.flutter.dev/index.html

Auto Hot Reload (in VS Code or Android Studio) In the terminal window where Flutter is running, press: r → for hot reload R → for hot restart The change appears instantly in the app.

packages import ' package:flutter / material.dart '; Purpose: Loads the Flutter Material Design library , which contains widgets like MaterialApp, Scaffold, AppBar , Text , etc. MaterialApp → provides theme and overall app structure. Scaffold → gives you a full page layout. AppBar → shows the top bar with title. Text → displays your content.

🧱 1️⃣ MaterialApp Use / Purpose Main root widget for Material Design apps. It sets up themes , routes , navigation , and title bar . Provides the base structure and styling (colors, fonts, transitions) following Google’s Material Design system. 🔹 Why we need it Without MaterialApp, widgets like Scaffold, AppBar , and TextTheme won’t have access to Material styling. It gives your app a consistent look and feel across platforms.

Property Description home The default screen widget of your app. title App title (used by Android/iOS task manager). theme Defines colors , fonts, and styles. routes Named routes (for navigation). debugShowCheckedModeBanner Hides debug banner. 🧱 1️⃣ MaterialApp - Key Properties

import ' package:flutter / material.dart ' ; void main (){ runApp ( MaterialApp ( home : Text ( "Kongu Engg " ), )); }

Entry point void main() { runApp ( MyApp ()); } main() is the starting point of every Dart/Flutter program. runApp () tells Flutter which widget to display first . MyApp () is a custom widget (your app), defined below.

🧩 2️⃣ Scaffold Use / Purpose Provides a basic visual layout structure for your screen (page). Gives a ready-made framework that includes: App bar Body Floating action button Drawer (side menu) Bottom navigation bar 🔹 Why we need it Without Scaffold, you’d have to manually handle screen layout and safe areas. It handles system UI features automatically (like status bar padding, background color, etc.).

Property Description appBar Top bar with title, icons, actions. body Main content of the screen. floatingActionButton Floating button (for quick actions). drawer Side navigation menu. bottomNavigationBar Bottom bar navigation. backgroundColor Screen background color . 🧩 2️⃣ Scaffold – Key Properties

🔹 Example Scaffold( appBar : AppBar(title: Text('Home')), body: Center (child: Text('Welcome!')), floatingActionButton : FloatingActionButton ( onPressed : () {}, child: Icon( Icons.add ), ), )

🎛️ 3️⃣ AppBar 🔹 Use / Purpose The top bar (header) of your app screen. Used to show title, actions (like search, menu, settings), and navigation icons (back button, drawer icon). 🔹 Why we need it Gives a consistent and beautiful top header across all screens. Provides built-in animation and system integration.

🎛️ 3️⃣ AppBar – Key Properties Property Description title Widget (usually Text) displayed in the center/left. backgroundColor Color of the AppBar. actions List of icons or widgets on the right. leading Widget on the left (e.g. back button). centerTitle Center the title (true/false).

🔹 Example AppBar( title: Text(' Kongu Engg '), backgroundColor : Colors.blueAccent , actions: [ IconButton ( onPressed : () {}, icon: Icon( Icons.search )), ], )

✍️ 4️⃣ Text 🔹 Use / Purpose Displays a string of text on the screen. One of the simplest but most-used widgets in Flutter. 🔹 Why we need it Every label, title, or message on your screen uses a Text widget. Highly customizable for style, font, color, and alignment.

✍️ 4️⃣ Text – Key Properties Property Description data The text string to display. style Font size, color, weight, etc. textAlign Alignment (left, right, center ). maxLines Limit number of visible lines. overflow Handle overflow text (ellipsis, clip).

🔹 Example Text( 'Welcome to Kongu Engineering College', style: TextStyle( fontSize : 22, fontWeight : FontWeight.bold , color : Colors.blue , ), textAlign : TextAlign.center , )

🧱 1️⃣ What is a Widget? 👉 In Flutter , everything you see on the screen is a widget — text, buttons, images, layouts, and even the entire app itself. A widget is just a building block of the user interface (UI) . Think of widgets like Lego pieces — each one does a small job, and you combine them to build your full app.

🎯 2️⃣ Purpose of a Widget Widgets are used to: Build the UI layout . Manage the state (data that changes on screen). Handle user interactions (like button taps). Apply styling and themes . In short: a widget tells Flutter what to draw and how to behave .

⚙️ 3️⃣ Why we need Widgets Without widgets, you’d have to write raw layout code (like Android XML or iOS Storyboards). Flutter widgets make UI development: Declarative (you describe what you want, Flutter handles how ). Faster (hot reload). Consistent (same look across Android, iOS, Web).

🧩 4️⃣ Types of Widgets Flutter widgets are mainly divided into two types: Type Description When to use Stateless Widget UI does not change over time For static content Stateful Widget UI changes when data or user input changes For dynamic or interactive screens

🧱 A) Stateless Widget import ' package:flutter / material.dart '; void main() => runApp (const MyApp ()); class MyApp extends StatelessWidget { const MyApp ({ super.key }); @override Widget build( BuildContext context) { return const MaterialApp ( home: Scaffold( body: Center ( child: Text( 'Welcome to Kongu Engg ', style: TextStyle( fontSize : 24, color : Colors.purple ), ), ), ), ); } } Doesn’t change once built. Example: labels, icons, static pages. 🟢 Output: A simple screen showing “Welcome to Kongu Engg ”. 🧠 UI stays same always — no data change.

🎨 1️⃣ Using Scaffold.backgroundColor import ' package:flutter / material.dart '; void main() => runApp (const MyApp ()); class MyApp extends StatelessWidget { const MyApp ({ super.key }); @override Widget build( BuildContext context) { return const MaterialApp ( home: Scaffold( backgroundColor : Colors.lightBlueAccent , // 👈 sets background color body: Center ( child: Text( 'Welcome', style: TextStyle( fontSize : 30, color : Colors.white ), ), ), ), ); }}

✅ Flutter Code: Get name and print it

🔁 B) Stateful Widget import ' package:flutter / material.dart '; void main() => runApp (const MyApp ()); class MyApp extends StatefulWidget { const MyApp ({ super.key }); @override State< MyApp > createState () => _ MyAppState (); } class _ MyAppState extends State< MyApp > { int count = 0; @override Widget build( BuildContext context) { return MaterialApp ( home: Scaffold( appBar : AppBar(title: const Text('Counter Example')), body: Center ( child: Text( 'Count: $count’, style: const TextStyle( fontSize : 30), ), ), floatingActionButton : FloatingActionButton ( onPressed : () { setState (() { count++; // updates UI }); }, child: const Icon( Icons.add ), ), ), ); } }

🧠 5️⃣ Additional categories of widgets Category Example Widgets Purpose Layout Widgets Row , Column , Stack , Container , Center Arrange other widgets Input Widgets TextField , Checkbox , Radio , Slider , Button Take user input Display Widgets Text , Image , Icon , Card , ListTile Show information Interaction Widgets GestureDetector , InkWell Handle touch, tap, drag Styling Widgets Padding , Align , DecoratedBox Add space or decoration Scaffold Widgets Scaffold , AppBar , Drawer Structure the screen Navigation Widgets Navigator , BottomNavigationBar Move between screens

import ' package:flutter / material.dart '; void main() => runApp (const MaterialApp (home: WelcomeWidget ()) ); class WelcomeWidget extends StatelessWidget { const WelcomeWidget ({ super.key }); @override Widget build( BuildContext context) { return const Scaffold( appBar : AppBar(title: Text('Widget Example')), body: Center (child: Text('Welcome to Flutter Widgets!')), ); } }

🧩 Example: import ' package:flutter / material.dart '; void main() { runApp (const MyApp ()); } class MyApp extends StatelessWidget { const MyApp ({ super.key }); @override Widget build( BuildContext context) { return const MaterialApp ( home: Center ( child: Text( 'Hello, Flutter!', style: TextStyle( fontSize : 30, color : Colors.blue ), ), ), ); } } MaterialApp → a root widget (sets up theme/navigation) Center → a layout widget (positions child at center) Text → a UI widget (displays string)

🧠 5️⃣ How they all work together import ' package:flutter / material.dart '; void main() => runApp (const MyApp ()); class MyApp extends StatelessWidget { const MyApp ({ super.key }); @override Widget build( BuildContext context) { return MaterialApp ( debugShowCheckedModeBanner : false, home: Scaffold( appBar : AppBar(title: const Text(' Kongu Engg ')), body: const Center ( child: Text( 'Welcome', style: TextStyle( fontSize : 28, fontWeight : FontWeight.bold ), ), ), ), ); }}

import ' package:flutter / material.dart '; void main() { runApp ( MaterialApp ( home: Scaffold( body: Center ( child: ElevatedButton ( onPressed : () { // Action when button is pressed print("Button Pressed"); }, child: Text("Click Me"), style: ElevatedButton.styleFrom ( backgroundColor : Colors.green , // button color foregroundColor : Colors.white , // text color padding: EdgeInsets.symmetric (horizontal: 50, vertical: 67), textStyle : TextStyle( fontSize : 45), ), ), ), ), ), ); }

Example: Rectangle ElevatedButton shape: RoundedRectangleBorder ( // 👇 Rectangle shape borderRadius : BorderRadius.zero , ),

Class (shortcut stless ) & properties ( Ctrl+space keys) 3. class MyApp extends StatelessWidget You’re creating a new widget called MyApp . StatelessWidget means the screen does not change during runtime (no dynamic content). class MyApp extends StatelessWidget { @override Widget build( BuildContext context) { return ...; // UI layout } }

import ' package:flutter / material.dart '; void main() { runApp ( MyApp ()); } class MyApp extends StatelessWidget { @override Widget build( BuildContext context) { return MaterialApp ( home:Text (" Abirami "), ); } } 4. MaterialApp(...) Root of your app that sets up: Title Theme Routes First screen (home) Property Use title App name (seen in Android task manager) home The first widget/screen shown theme ( Optional ) Controls colors , fonts, etc.

What is Scaffold? Scaffold is a built-in Flutter widget that provides a basic structure (layout) for your app screen . It helps you easily add: AppBar (top bar) Body (main content) Floating Action Button Drawer (side menu) Bottom Navigation Bar, etc.

import ' package:flutter / material.dart '; void main() { runApp ( MaterialApp ( debugShowCheckedModeBanner : false, title: ' Kongu App', theme: ThemeData ( scaffoldBackgroundColor : Colors.lightBlue , ), home: Scaffold( body: Center ( child: Text( " Kongu Engg ", style: TextStyle( fontSize : 24, color : Colors.white , ), ), ), ), )); }

import ' dart:html '; import ' package:flutter / material.dart '; void main() { runApp (Test()); } class Test extends StatelessWidget { @override Widget build( BuildContext context) { return MaterialApp ( home: Scaffold( body:Text ("Anbu"), )); }}

Basic Syntax of Scaffold Scaffold( appBar : AppBar(title: Text('Title')), body: Center (child: Text('Hello')), backgroundColor : Colors.blue , floatingActionButton : FloatingActionButton ( onPressed : () {}, child: Icon( Icons.add ), ), ) Property Purpose appBar Adds a top bar (title, icons, etc.) body Main screen content backgroundColor Set the background color of the screen floatingActionButton Shows a circular button usually used for main action drawer Adds a left-side sliding menu bottomNavigationBar Adds a bottom bar for navigation persistentFooterButtons Adds buttons at the bottom that stay fixed resizeToAvoidBottomInset Handles screen resize when keyboard appears

import ' package:flutter / material.dart ' ; void main () => runApp ( MyApp ()); class MyApp extends StatelessWidget { @override Widget build ( BuildContext context) { return MaterialApp ( home: Scaffold( appBar : AppBar (title: Text("My App")), body: Center(child: Text("Welcome to Flutter!")), ), ); } }

import ' package:flutter / material.dart '; void main() => runApp ( MyApp ()); class MyApp extends StatelessWidget { @override Widget build( BuildContext context) { return MaterialApp ( home: Scaffold( backgroundColor : Colors.lightGreenAccent , appBar : AppBar(title: Text("Green Screen")), body: Center (child: Text("Hello!")), ) ); } }

import ' package:flutter / material.dart '; void main() => runApp ( MyApp ()); class MyApp extends StatelessWidget { @override Widget build( BuildContext context) { return MaterialApp ( home: Scaffold( backgroundColor : Colors.lightGreenAccent , appBar : AppBar(title: Text("Green Screen" )), body: Center (child: Text("Hello!“ , style: TextStyle ( fontSize : 30, fontWeight : FontWeight.bold , ), )), ) ); } }

Screen – background image

Step-by-Step Instructions Step 1 : Add your image to project folderInside your Flutter project directory: Navigate to: your_project_name /assets/images/ If assets or images folders do not exist, create them. your_project / └── assets/ └── images/ └── bg.jpg ← (your background image here)

Step 2: Update pubspec.yaml file Open pubspec.yaml and add this under flutter: section : flutter: assets: - assets/images/bg.jpg flutter: assets: - assets/images/bg.jpg Make sure: Indentation is correct (use 2 spaces ). The file is saved after editing. Get dependencies – clicl -its update pub file

import ' package:flutter / material.dart ’; void main() => runApp ( MaterialApp (home: BackgroundImageApp ())); class BackgroundImageApp extends StatelessWidget { @override Widget build( BuildContext context) { return Scaffold( body: Container( decoration: BoxDecoration ( image: DecorationImage ( image: AssetImage ("assets/images/flow.jpg"), fit: BoxFit.cover , // covers entire screen ), ), child: Center ( child: Text( "Hello Flutter!", style: TextStyle( color : Colors.white , fontSize : 24), ), ), ), ); } }

Part Meaning AssetImage(...) Loads image from your local folder fit: BoxFit.cover Makes image cover full screen child: Center(...) Allows you to place widgets on top of image

ImageButton

import ' package:flutter / material.dart '; void main() => runApp ( MaterialApp (home: ImageButton ())); class ImageButton extends StatelessWidget { @override Widget build( BuildContext context) { return Scaffold( body: Center ( child: InkWell ( onTap : () { print("Image button clicked"); }, child: Image.asset ("assets/images/ima.jpg", width: 100), ), ), ); } }

Clickable image icon (like a button)

import ' package:flutter / material.dart '; void main() => runApp ( MaterialApp (home: ImageIconButton ())); class ImageIconButton extends StatelessWidget { @override Widget build( BuildContext context) { return Scaffold( body: Center ( child: InkWell ( onTap : () { print("Image icon tapped"); }, child: Image.asset ("assets/images/face.jpg", width: 50), ), ), ); } }