26/05/2023
Basics
In Flutter, Scaffold is a widget to provides a basic structure for implementing the visual layout and behavior of a typical mobile application screen. It serves as a container for various UI elements such as app bars, navigation drawers, floating action buttons, and body content.
The Scaffold widget offers several properties and options for customizing the appearance and functionality of the screen. Some of the key properties include:
appBar: Allows you to specify an app bar widget that typically contains the title of the screen, navigation buttons, and other controls.
body: Represents the main content of the screen. It can be any widget, such as a Container, ListView, Column, or GridView, which defines the layout and structure of the screen's body.
floatingActionButton: Enables you to add a floating action button, often used for primary actions within the screen. You can attach an onPressed callback to handle button taps.
drawer: Lets you include a navigation drawer widget that slides in from the side of the screen, usually used for accessing secondary app features or navigation options.
bottomNavigationBar: Allows you to add a bottom navigation bar widget, which is commonly used to switch between different sections or views within the app.
Additionally, the Scaffold widget provides other features like snackbar display, persistent application-wide headers, and more.
Here's an example of how a basic Scaffold can be used:
dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My App'),
),
body: Center(
child: Text('Hello, World!'),
),
),
);
}
}
In this example, the Scaffold widget is the main component of the app's home screen. It contains an AppBar widget with a title, and the body content is centered and displays the text "Hello, World!".