搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案