You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter实现四按钮组合成圆形的单个圆角按钮样式设置咨询

实现Flutter圆形四切片按钮组合

嘿,我完全懂你想要的那种披萨切片式圆形按钮效果!其实在Flutter里给单个按钮设置指定圆角一点都不难,核心就是用BorderRadius.only()这个方法,配合简单的Row+Column布局就能搞定,我给你一步步拆解:

核心思路:精准控制单个圆角

不管你用InkWell(带水波纹点击效果)还是ElevatedButton(带阴影的按钮),都可以通过BorderRadius.only()单独设置某一个角的圆角,比如左上角按钮就只设置topLeft的圆角,其余三个按钮对应设置topRight、bottomLeft、bottomRight的圆角,而且圆角半径要和整个圆形的半径一致,这样拼起来才会完美贴合。

完整代码示例

下面是直接能用的代码,你可以直接复制到项目里测试:

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('圆形切片按钮')),
        body: const CircleButtonGroup(),
      ),
    );
  }
}

class CircleButtonGroup extends StatelessWidget {
  const CircleButtonGroup({super.key});

  @override
  Widget build(BuildContext context) {
    // 整个圆形的半径,可根据需求调整
    const double circleRadius = 120;

    return Center(
      // 固定圆形的大小:宽高都是半径的2倍,确保是正圆
      child: SizedBox(
        width: circleRadius * 2,
        height: circleRadius * 2,
        child: Column(
          children: [
            // 上半部分:左上角 + 右上角按钮
            Expanded(
              child: Row(
                children: [
                  // 左上角按钮
                  Expanded(
                    child: InkWell(
                      onTap: () => debugPrint('左上角按钮被点击'),
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.lightBlueAccent,
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(circleRadius),
                          ),
                        ),
                        child: const Center(child: Text('按钮1')),
                      ),
                    ),
                  ),
                  // 右上角按钮
                  Expanded(
                    child: InkWell(
                      onTap: () => debugPrint('右上角按钮被点击'),
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.greenAccent,
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(circleRadius),
                          ),
                        ),
                        child: const Center(child: Text('按钮2')),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            // 下半部分:左下角 + 右下角按钮
            Expanded(
              child: Row(
                children: [
                  // 左下角按钮
                  Expanded(
                    child: InkWell(
                      onTap: () => debugPrint('左下角按钮被点击'),
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.orangeAccent,
                          borderRadius: const BorderRadius.only(
                            bottomLeft: Radius.circular(circleRadius),
                          ),
                        ),
                        child: const Center(child: Text('按钮3')),
                      ),
                    ),
                  ),
                  // 右下角按钮
                  Expanded(
                    child: InkWell(
                      onTap: () => debugPrint('右下角按钮被点击'),
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.pinkAccent,
                          borderRadius: const BorderRadius.only(
                            bottomRight: Radius.circular(circleRadius),
                          ),
                        ),
                        child: const Center(child: Text('按钮4')),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

用ElevatedButton实现的版本(可选)

如果你更喜欢用Flutter自带的ElevatedButton,只需要把InkWell+Container换成ElevatedButton,在style里设置shape即可:

// 左上角ElevatedButton示例
Expanded(
  child: ElevatedButton(
    onPressed: () => debugPrint('左上角按钮被点击'),
    style: ElevatedButton.styleFrom(
      backgroundColor: Colors.lightBlueAccent,
      minimumSize: const Size.infinite, // 让按钮占满父容器
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(topLeft: Radius.circular(circleRadius)),
      ),
    ),
    child: const Text('按钮1'),
  ),
),

小提示

  • 调整circleRadius的值可以改变整个圆形的大小,按钮会自动适配。
  • 如果需要按钮之间有细微的分割线,可以在Row/Column里加入SizedBox(width: 1, height: 1)并设置背景色,比如SizedBox(width:1, color: Colors.white)。
  • 点击效果方面,InkWell的水波纹会在整个按钮区域扩散,ElevatedButton自带阴影变化,根据你的UI需求选择就行。

这样应该就能完美实现你想要的效果啦!

内容的提问来源于stack exchange,提问作者F.M.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 07:47:51