enter image description here

appBar: AppBar(
title: Center(
child: SvgPicture.asset("assets/images/logo.svg",
height: 15, width: 15, color: Colors.white,),
),
backgroundColor: const Color.fromRGBO(91, 189, 146, 1),
),

如何在appbar底部添加如图所示的Wave?

推荐答案

下面的方法将会起到作用.它使用CustomPaint小工具在中间绘制半圆,并使用Transform.translate将"图标"向下移动一点.

这就是结果(也请勾选live demo on the DartPad)

Screenshot

minimal-reproducible-example个源代码

import 'dart:math';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 60,
        flexibleSpace: const CustomPaint(
          painter: MyCustomPainter(),
          size: Size.infinite,
        ),
        title: Center(
          child: Transform.translate(
            offset: const Offset(0, 5),
            child: const Center(
              child: Text(
                "Q",
                style: TextStyle(color: Colors.white, fontSize: 30),
              ),
            ),
          ),
        ),
        backgroundColor: Colors.transparent,
        elevation: 0,
      ),
    );
  }
}

class MyCustomPainter extends CustomPainter {
  const MyCustomPainter({Listenable? repaint}) : super(repaint: repaint);

  static const circleSize = 90.0;
  static const gap = 15.0;

  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..style = PaintingStyle.fill
      ..color = const Color.fromRGBO(91, 189, 146, 1);

    var shadow = Paint()
      ..style = PaintingStyle.fill
      ..color = const Color.fromARGB(255, 127, 127, 127)
      ..maskFilter = MaskFilter.blur(
        BlurStyle.normal,
        Shadow.convertRadiusToSigma(5),
      );

    var path = Path();
    path.lineTo(0, size.height - gap);
    path.lineTo(size.width / 2, size.height - gap);
    path.arcTo(
      Rect.fromLTWH(
        size.width / 2 - circleSize / 2,
        size.height - circleSize,
        circleSize,
        circleSize,
      ),
      pi,
      -pi,
      false,
    );
    path.lineTo(size.width / 2, size.height - gap);
    path.lineTo(size.width, size.height - gap);
    path.lineTo(size.width, 0);
    path.close();

    canvas.drawPath(path, shadow);
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(MyCustomPainter oldDelegate) {
    return false;
  }
}

Flutter相关问答推荐

无法在主屏幕视图中设置当前日期容器'

当键盘在抖动中打开时,如何才能看到包装在SingleChildScrollView中的列中的最后一个小工具?

缩短经常使用的行Theme.of(context).colorScheme

如何从DART中的事件列表中获取即将到来的日期

如果我使用搜索栏,如何在嵌套滚动视图中停止自动滚动?

Flutter-Riverpod:如何只从提供者读取一次值

如何将小部件代码移动到另一个文件以获得更好的可读性

没有固定宽度的小部件可以约束文本小部件吗?

Flutter - Riverpod 2.0 - 如何访问 onDispose 回调?

要禁用按钮上的通知声音,请点击Flutter

Flutter 使用扩展的 TextField 定位小部件

「Flutter」错误:没有名为'kind'的命名参数

文本溢出文本框 - Flutter

如何正确地将 PageView 设置为 AppBar 的标题?

如何设置行中项目之间的空格相等?

Flutter 动画页面计数器文本

在 Dart 中使用隔离时访问外部范围内的变量

如何验证位于 PageView 内不同页面的 TextFormFields

RangeError(索引):无效值:有效值范围为空:点击文章时为0

FLUTTER+SQL:在 ListViewBuilder 中显示数据库中的数据