Search packages, repositories and app categories

flutter_inset_shadow cover
Package detailsv2.0.3

flutter_inset_shadow

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

AndroidiOSWebmacOSWindowsLinux
30-day downloads
22.3K
Likes
38
Pub points
150

Install package

flutter pub add flutter_inset_shadow

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The flutter_inset_shadow package enhances Flutter's BoxShadow and BoxDecoration classes by adding support for the inset property, allowing developers to create shadows that appear inside a widget's boundaries rather than outside. This is particularly useful for creating depth effects like inner glow or recessed designs. The package integrates seamlessly with existing Flutter UI components and supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux. It simplifies the implementation of subtle, modern UI elements without requiring custom painting or complex workarounds.

Use cases

  • Creating inner shadows for cards and containers
  • Designing recessed or sunken UI elements
  • Adding subtle depth effects in modern interfaces
  • Implementing glowing or inset border effects
  • Enhancing visual hierarchy with internal shadows

Key features

  • Supports inset shadows via BoxShadow extension
  • Extends BoxDecoration for inner shadow rendering
  • Cross-platform compatibility
  • Simple integration with existing widgets
  • Minimal boilerplate required

Suitable for

  • UI designers seeking advanced shadow effects
  • Developers building modern, flat-design apps
  • Projects requiring subtle depth without external libraries
  • Teams using Flutter for multi-platform apps

Considerations

  • May impact performance on complex layouts
  • Limited to basic shadow styling
  • Not suitable for highly dynamic or animated shadows
  • Requires careful testing across different screen densities

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package