Skip to content

Space 间距

设置组件之间的间距。

何时使用

当需要在多个组件之间添加统一的间距时使用,可以快速实现水平或垂直排列布局。

代码演示

import 'package:antd_flutter_example/demo_block.dart';
import 'package:flutter/widgets.dart';
import 'package:trionesdev_antd_mobile/trionesdev_antd_mobile.dart';

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

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

class _SpacePageState extends State<SpacePage> {
  @override
  Widget build(BuildContext context) {
    return AntScaffold(
      appBar: AntAppBar(
        title: const Text("Space"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            DemoBlock(
              title: "基本使用",
              child: Column(
                spacing: 10,
                children: [
                  AntSpace(spacing: 10, children: [
                    AntButton(
                      text: "Button",
                    ),
                    AntButton(
                      text: "Button",
                    )
                  ]),
                ],
              ),
            ),
            DemoBlock(
              title: "纵向排列",
              child: Column(
                children: [
                  AntSpace(
                      spacing: 10,
                      direction: AntSpaceDirection.vertical,
                      children: [
                        AntButton(
                          text: "Button",
                        ),
                        AntButton(
                          text: "Button",
                        )
                      ])
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

API

间距组件的属性说明如下:

属性说明类型默认值
style样式StateStyle?null
decoration装饰BoxDecoration?null
direction排列方向AntSpaceDirection?horizontal
children子项List<Widget>?null
spacing间隔double?2
split分割线Widget?null

AntSpaceDirection 枚举值

说明
vertical垂直排列
horizontal水平排列