搜索插件、代码仓与 APP 分类

flutter_inset_shadow 封面
插件详情v2.0.3

flutter_inset_shadow

此包扩展了 BoxShadow 和 BoxDecoration 以支持 inset 属性。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2.2万
喜欢数
38
Pub 分数
150

安装插件

flutter pub add flutter_inset_shadow

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_inset_shadow 包通过添加 inset 属性支持,增强了 Flutter 的 BoxShadow 和 BoxDecoration 类,使开发者能够创建出现在控件边界内部的阴影,而非外部。这特别适用于创建内发光或凹陷设计等深度效果。该包可与现有的 Flutter UI 组件无缝集成,并支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它简化了微妙且现代的 UI 元素的实现,无需自定义绘制或复杂的变通方法。

适合场景

  • 为卡片和容器创建内阴影
  • 设计凹陷或嵌入式用户界面元素
  • 在现代界面中添加微妙的深度效果
  • 实现发光或内嵌边框效果
  • 通过内部阴影增强视觉层次

主要特点

  • 通过 BoxShadow 扩展支持内阴影
  • 扩展 BoxDecoration 以实现内部阴影渲染
  • 跨平台兼容性
  • 与现有控件的简单集成
  • 所需的样板代码最少

适合对象

  • 寻求高级阴影效果的UI设计师
  • 开发现代扁平化设计应用的开发者
  • 需要细微深度但不依赖外部库的项目
  • 使用 Flutter 开发多平台应用的团队

使用建议

  • 可能会影响复杂布局的性能
  • 仅限基本阴影样式
  • 不适合高度动态或动画阴影
  • 需要在不同屏幕密度上进行仔细测试

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Inset Shadow

Flutter currently does not support the inset property for shadows. This type of shadow is for example used in Neumorphism.

This package extends BoxShadow and BoxDecoration to support the inset property.

[!IMPORTANT]

What happened to flutter_inset_box_shadow?

Previously, this package was called flutter_inset_box_shadow.

Unfortunately, I've lost access to the verified publisher, allowing me to publish updates to the package.

So I decided to publish the package under a new name.

For more information, you can read https://github.com/chitochi/flutter_inset_shadow/issues/7. 😄

Features

  • All properties of BoxShadow are supported.
  • If the property of a BoxShadow changes during a transition, we first make the old shadow disappear before making the new one appear.

Example

A simple neumorphic container

import 'package:flutter/material.dart' hide BoxDecoration, BoxShadow;
import 'package:flutter_inset_shadow/flutter_inset_shadow.dart';

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

const primaryColor = Color(0xFFE0E0E0);

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: primaryColor,
        body: Center(
          child: Container(
            width: 150,
            height: 150,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(50),
              color: primaryColor,
              boxShadow: const [
                BoxShadow(
                  offset: Offset(-20, -20),
                  blurRadius: 60,
                  color: Colors.white,
                  inset: true,
                ),
                BoxShadow(
                  offset: Offset(20, 20),
                  blurRadius: 60,
                  color: Color(0xFFBEBEBE),
                  inset: true,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Usage

First, add the package:

flutter pub add flutter_inset_shadow

Then, import it as follows:

import 'package:flutter/material.dart' hide BoxDecoration, BoxShadow;
import 'package:flutter_inset_shadow/flutter_inset_shadow.dart';

It is necessary to hide BoxDecoration and BoxShadow because this library replaces them.

BoxShadow now has a boolean inset property, which is set to false by default.

return Container(
  decoration: BoxDecoration(
    boxShadow: [
      BoxShadow(
        blurRadius: 5,
        color: Colors.red,
      ),
      BoxShadow(
        offset: Offset(1, 2),
        blurRadius: 5,
        spreadRadius: 2,
        color: Colors.green,
        inset: true,
      ),
    ],
  ),
);

How does it work?

The algorithm used is the same as that of Blink, the Chromium rendering engine.

The idea is that we draw a rectangle hollowed out by another rounded rectangle inside, then we blur this hollowed rectangle.

所属分类

源码仓库

使用此插件的项目