Scaffold Widget and Attributes

Scaffold Widget and Attributes

ยท

2 min read

In Flutter, the Scaffold widget is a fundamental building block for creating the basic structure of an app. It provides a top-level container for the visual elements of a Material Design app, including the app bar, bottom navigation, floating action button, and body content. The Scaffold widget simplifies the creation of a standard app layout and incorporates various common UI components.

Now, let's go through the attributes and properties of the Scaffold widget in this example:

  1. appBar (AppBar):

    • Defines the top app bar, typically used for displaying the app's title and actions.
  2. body (Widget):

    • Specifies the main content of the app, which is displayed below the app bar.
  3. floatingActionButton (FloatingActionButton):

    • Adds a floating action button to the screen, commonly used for primary user actions.
  4. drawer (Widget):

    • Specifies a drawer that can be pulled from the left side of the screen, providing additional navigation options.
  5. bottomNavigationBar (BottomNavigationBar):

    • Defines a bottom navigation bar for switching between different views or sections in the app.
  6. bottomSheet (Widget):

    • Adds a persistent bottom sheet to the app, appearing above the main content.
  7. backgroundColor (Color):

    • Sets the background color of the Scaffold.
  8. resizeToAvoidBottomInset (bool):

    • Determines whether the body should resize when the on-screen keyboard is displayed.
  9. extendBody (bool):

    • Extends the body behind the bottom navigation bar, providing a seamless visual effect.
  10. extendBodyBehindAppBar (bool):

    • Extends the body behind the app bar, creating a visually immersive experience.

These are some of the key properties of the Scaffold widget. You can customize these attributes based on your app's requirements to create a polished and user-friendly interface.

Here's an example of how the Scaffold widget is typically used in a Flutter app:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My App'),
      ),
      body: Center(
        child: Text('Hello, Flutter!'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // Add your action here
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

Did you find this article valuable?

Support Vinit Mepani (Flutter Developer) by becoming a sponsor. Any amount is appreciated!

ย