[flutter专题]详解AppBar小部件
warning:
这篇文章距离上次修改已过221天,其中的内容可能已经有所变动。
AppBar是Flutter中用于构建应用栏的小部件,它通常位于顶部,并且可以显示标题、操作按钮、导航等。以下是一个简单的AppBar示例代码:
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('Flutter AppBar Example'),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () {
// 点击设置按钮时的操作
},
),
],
),
body: Center(
child: Text('AppBar Demo'),
),
),
);
}
}
在这个例子中,我们创建了一个包含AppBar的页面,其中title
属性设置了标题,centerTitle
属性设置标题是否居中,actions
属性添加了一个设置按钮,用于执行一些操作。body
属性则设置了主要页面内容。
评论已关闭