Flutter开发入门——Widget和常用组件

warning: 这篇文章距离上次修改已过280天,其中的内容可能已经有所变动。

在Flutter中,Widget是构建用户界面的基本单位。每个Widget都是一个类,可以根据需要创建自定义Widget。

以下是一些常用的Widget和它们的简单用法:

  1. Text:显示文本信息。



Text('Hello, Flutter!'),
  1. Container:一个简单的容器,可以用于布局和添加背景色、边框等。



Container(
  color: Colors.blue,
  child: Text('Hello, Flutter!'),
),
  1. Row和Column:用于水平或垂直排列子Widget。



Row(
  children: <Widget>[
    Text('Row Item 1'),
    Text('Row Item 2'),
  ],
),
 
Column(
  children: <Widget>[
    Text('Column Item 1'),
    Text('Column Item 2'),
  ],
),
  1. Image:显示图片。



Image.network('https://example.com/image.png'),
  1. RaisedButton和FlatButton:用于点击事件的按钮。



RaisedButton(
  onPressed: () { print('RaisedButton pressed'); },
  child: Text('Raised Button'),
),
 
FlatButton(
  onPressed: () { print('FlatButton pressed'); },
  child: Text('Flat Button'),
),
  1. ListView:创建一个可滚动的列表。



ListView(
  children: <Widget>[
    ListTile(title: Text('List Item 1')),
    ListTile(title: Text('List Item 2')),
    // ...更多列表项
  ],
),
  1. Stack:堆叠Widget,可以用于定位和叠加效果。



Stack(
  children: <Widget>[
    Text('Hello, Flutter!'),
    Positioned(
      right: 10.0,
      bottom: 10.0,
      child: Text('New Text'),
    ),
  ],
),
  1. AppBar:用于应用的顶部导航栏。



AppBar(
  title: Text('AppBar Title'),
),
  1. Expanded:可以用于Row或Column中,用于分配可用空间。



Row(
  children: <Widget>[
    Expanded(
      child: Container(color: Colors.red),
    ),
    Expanded(
      child: Container(color: Colors.blue),
    ),
  ],
),
  1. Scaffold:提供有默认参数的Material Design布局结构。



Scaffold(
  appBar: AppBar(title: Text('Sample App')),
  body: Text('Sample body'),
),

这些Widget是开发者在Flutter中最常接触和使用的。Flutter提供丰富的Widget库,可以根据需要创建自定义Widget。

none
最后修改于:2024年08月23日 20:52

评论已关闭

推荐阅读

DDPG 模型解析,附Pytorch完整代码
2024年11月24日
DQN 模型解析,附Pytorch完整代码
2024年11月24日
AIGC实战——Transformer模型
2024年12月01日
Socket TCP 和 UDP 编程基础(Python)
2024年11月30日
python , tcp , udp
如何使用 ChatGPT 进行学术润色?你需要这些指令
2024年12月01日
AI
最新 Python 调用 OpenAi 详细教程实现问答、图像合成、图像理解、语音合成、语音识别(详细教程)
2024年11月24日
ChatGPT 和 DALL·E 2 配合生成故事绘本
2024年12月01日
omegaconf,一个超强的 Python 库!
2024年11月24日
【视觉AIGC识别】误差特征、人脸伪造检测、其他类型假图检测
2024年12月01日
[超级详细]如何在深度学习训练模型过程中使用 GPU 加速
2024年11月29日
Python 物理引擎pymunk最完整教程
2024年11月27日
MediaPipe 人体姿态与手指关键点检测教程
2024年11月27日
深入了解 Taipy:Python 打造 Web 应用的全面教程
2024年11月26日
基于Transformer的时间序列预测模型
2024年11月25日
Python在金融大数据分析中的AI应用(股价分析、量化交易)实战
2024年11月25日
AIGC Gradio系列学习教程之Components
2024年12月01日
Python3 `asyncio` — 异步 I/O,事件循环和并发工具
2024年11月30日
llama-factory SFT系列教程:大模型在自定义数据集 LoRA 训练与部署
2024年12月01日
Python 多线程和多进程用法
2024年11月24日
Python socket详解,全网最全教程
2024年11月27日