flutter 非常用组件整理 第三篇
warning:
这篇文章距离上次修改已过439天,其中的内容可能已经有所变动。
在Flutter中,有许多内置的组件可以用来构建应用程序。以下是一些常用的组件,以及它们的简单示例代码。
Text- 显示文本信息。
Text('Hello, World!')Container- 一个简单的容器,可以用来绘制装饰和背景色。
Container(
color: Colors.blue,
child: Text('Hello, World!'),
)Row和Column- 这些布局组件用于水平或垂直排列其子项。
Row(
children: <Widget>[
Text('Row Item 1'),
Text('Row Item 2'),
],
)
Column(
children: <Widget>[
Text('Column Item 1'),
Text('Column Item 2'),
],
)Image- 用于显示图片。
Image.network('https://example.com/image.png')RaisedButton和FlatButton- 这些按钮在用户交互时会有视觉效果。
RaisedButton(
onPressed: () {},
child: Text('Raised Button'),
)
FlatButton(
onPressed: () {},
child: Text('Flat Button'),
)ListView- 用于显示可滚动的列表。
ListView(
children: <Widget>[
ListTile(title: Text('List Item 1')),
ListTile(title: Text('List Item 2')),
],
)AppBar- 用于定义顶部的导航栏。
AppBar(
title: Text('AppBar Title'),
)Scaffold- 提供有用的布局结构,包括底部导航栏、侧边栏、顶部导航栏和主体内容。
Scaffold(
appBar: AppBar(title: Text('AppBar Title')),
body: Text('Main Content'),
)这些组件是Flutter应用程序的基础,每个应用程序都会用到这些组件。在实际开发中,你可能还会遇到更多的组件,如StatefulWidget、InheritedWidget、StreamBuilder等,这取决于你想要构建的应用类型和需要处理的复杂性。
评论已关闭