Skip to content

Empty 空状态

空状态组件用于在没有数据或内容时展示提示信息,通常在列表为空或页面无内容时使用。

何时使用

  • 列表数据为空时提供友好的提示
  • 页面初始化但无内容时展示占位符
  • 搜索无结果时显示提示信息
  • 网络错误或加载失败时展示错误状态

代码演示

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:trionesdev_antd_mobile/trionesdev_antd_mobile.dart';

import '../demo_block.dart';

class EmptyPage extends StatefulWidget {
  const EmptyPage({super.key});

  @override
  State<StatefulWidget> createState() => _EmptyPageState();
}

class _EmptyPageState extends State<EmptyPage> {
  @override
  Widget build(BuildContext context) {
    return AntScaffold(
        appBar: AntAppBar(
          title: const Text('Empty 空页面'),
        ),
        body: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Column(children: [
              DemoBlock(
                title: "基本使用",
                child: AntEmpty(),
              ),
              DemoBlock(
                title: "自定义内容",
                child: AntEmpty(
                  image: Icon(
                    Icons.hourglass_empty,
                    color: Colors.grey,
                  ),
                ),
              )
            ])));
  }
}

API

AntEmpty 组件参数

属性说明类型默认值
image图片Widget?null
description描述Text?null
descriptionText描述文本String?null

组件特性

  1. 支持自定义图片和描述信息
  2. 提供默认的空状态图标和"暂无数据"文本
  3. 支持通过 description 或 descriptionText 设置描述文本
  4. 图片和描述均支持自定义
  5. 默认使用垂直布局展示图片和描述

使用说明

  • 当 image 未设置时,使用默认的空状态图标
  • 当 description 和 descriptionText 均未设置时,显示默认的"暂无数据"文本
  • 优先使用 description 属性,如果未设置则使用 descriptionText
  • 可以通过 image 属性完全自定义空状态的图片部分
  • 组件会自动居中显示内容