Skip to content
Snippets Groups Projects
Select Git revision
  • 8e390a56fde21bf0695d7082a3cddfe79f5c13f0
  • master default protected
  • 100-upgrade-framework-and-dependencies
  • 65-improve-app-metadata
  • Release_1.8.0_80 protected
  • Release_1.7.2_79 protected
  • Release_1.7.1_78 protected
  • Release_1.7.0_77 protected
  • Release_1.6.0_76 protected
  • Release_1.5.0_75 protected
  • Release_1.4.0_74 protected
  • Release_1.3.2_73 protected
  • Release_1.3.1_72 protected
  • Release_1.3.0_71 protected
  • Release_1.2.1_70 protected
  • Release_1.2.0_69 protected
  • Release_1.1.3_68 protected
  • Release_1.1.2_67 protected
  • Release_1.1.1_66 protected
  • Release_1.1.0_65 protected
  • Release_1.0.63_64 protected
  • Release_1.0.62_63 protected
  • Release_1.0.61_62 protected
  • Release_1.0.60_61 protected
24 results

styled_container.dart

Blame
  • styled_container.dart 1.72 KiB
    import 'package:flutter/material.dart';
    
    class StyledContainer extends StatelessWidget {
      const StyledContainer({
        super.key,
        required this.child,
        this.borderWidth = 20,
        this.borderRadius = 6,
        this.depth = 7,
        this.lowerColor,
        this.upperColor,
      });
    
      final Widget child;
      final double borderWidth;
      final double borderRadius;
      final int depth;
      final Color? lowerColor;
      final Color? upperColor;
    
      Widget nestedContainers({
        required Widget child,
        required int containerDepth,
        required Color lowerColor,
        required Color upperColor,
      }) {
        final double singleBorderWidth = borderWidth / depth;
        final Color borderColor =
            Color.lerp(upperColor, lowerColor, (containerDepth / depth - 0.5).abs() * 2) ??
                Colors.white;
    
        final double radius = borderRadius + borderRadius * (containerDepth / depth);
    
        return Container(
          decoration: BoxDecoration(
            color: borderColor,
            border: Border.all(
              color: borderColor,
              width: singleBorderWidth,
            ),
            borderRadius: BorderRadius.circular(radius),
          ),
          child: containerDepth == 0
              ? Padding(
                  padding: const EdgeInsets.all(8),
                  child: child,
                )
              : nestedContainers(
                  child: child,
                  containerDepth: containerDepth - 1,
                  lowerColor: lowerColor,
                  upperColor: upperColor,
                ),
        );
      }
    
      @override
      Widget build(BuildContext context) {
        return nestedContainers(
          child: child,
          containerDepth: depth,
          lowerColor: lowerColor ?? Theme.of(context).colorScheme.surface,
          upperColor: upperColor ?? Theme.of(context).colorScheme.onSurface,
        );
      }
    }