Junior — Middle
Can you give an example of applying the Scaffold pattern in interface development?
sobes.tech AI
Answer from AI
The Scaffold pattern in Flutter is used to create the basic visual layout structure of an app screen, including elements like AppBar, Drawer, FloatingActionButton, etc.
Example of using Scaffold:
import 'package:flutter/material.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Scaffold Example'),
),
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
child: Text('Menu'),
decoration: BoxDecoration(color: Colors.blue),
),
ListTile(
title: Text('Item 1'),
onTap: () {},
),
],
),
),
body: Center(
child: Text('Main content of the screen'),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
);
}
}
Here, Scaffold provides a standard framework for the screen with a top app bar, a drawer menu, main content, and a floating action button.