Flutter开发之——ProgressIndicator
warning:
这篇文章距离上次修改已过442天,其中的内容可能已经有所变动。
在Flutter中,ProgressIndicator是一个用于显示进度的小部件。它在加载数据或处理任务时显示一个进度的视图,给用户一个视觉上的反馈。
以下是一些使用ProgressIndicator的示例:
- 使用
CircularProgressIndicator创建一个圆形进度指示器:
CircularProgressIndicator()- 使用
CircularProgressIndicator并自定义其颜色:
CircularProgressIndicator(
color: Colors.blue,
)- 使用
CircularProgressIndicator并添加一个方法,在数据加载时显示进度指示器,数据加载完成后隐藏:
bool isLoading = true;
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
)
// 假设有一个数据加载的方法
Future<void> loadData() async {
// 数据加载的代码
// ...
// 数据加载完成后,将isLoading设置为false
setState(() {
isLoading = false;
});
}
// 在initState中调用loadData
@override
void initState() {
super.initState();
loadData();
}
// 根据isLoading来判断是否显示进度指示器
if (isLoading) {
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
)
}- 使用
LinearProgressIndicator创建一个线性进度指示器:
LinearProgressIndicator()- 使用
RefreshProgressIndicator创建一个下拉刷新进度指示器,这个指示器通常与ListView或CustomScrollView一起使用:
RefreshIndicator(
onRefresh: () async {
// 数据刷新的代码
},
child: ListView(
children: <Widget>[
// 子widget列表
],
),
)这些是使用ProgressIndicator的基本示例。根据需求,你可以自由地调整这些示例,或者创建其他类型的进度指示器。
评论已关闭