Scaffold
Scaffold is a built-in widget in Flutter that provides a basic structure for implementing the Material Design visual language. It provides a framework to build the most common UI elements, such as app bars, navigation drawers, floating action buttons, and more.
For instance, creating a basic app in Flutter with a Scaffold widget would look like this:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Flutter App',
home: Scaffold(
appBar: AppBar(
title: Text('My App Bar'),
),
body: Center(
child: Text('Hello World!'),
),
),
);
}
}
This creates an app with an app bar and a centered text "Hello World!" as the body.
Attributes
Some common attributes that can be used with the Scaffold widget include:
appBar: The app bar displayed at the top of the screen.
body: The main content area of the screen.
floatingActionButton: A button that appears above thebodyand provides a call-to-action.
drawer: A panel that slides in from the left, usually used for navigation.
bottomNavigationBar: A navigation bar that appears at the bottom of the screen, usually used for switching between different views or tabs.
backgroundColor: The background color of the screen.