72 lines
1.8 KiB
Dart
72 lines
1.8 KiB
Dart
import 'dart:ui';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class GlassContainer extends StatelessWidget {
|
|
final Widget child;
|
|
final double? width;
|
|
final double? height;
|
|
final EdgeInsetsGeometry? padding;
|
|
final EdgeInsetsGeometry? margin;
|
|
final double borderRadius;
|
|
final List<Color>? gradientColors;
|
|
final double blur;
|
|
|
|
const GlassContainer({
|
|
super.key,
|
|
required this.child,
|
|
this.width,
|
|
this.height,
|
|
this.padding,
|
|
this.margin,
|
|
this.borderRadius = 16.0,
|
|
this.gradientColors,
|
|
this.blur = 10.0,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final defaultGradient = [
|
|
Colors.white.withOpacity(0.1),
|
|
Colors.white.withOpacity(0.05),
|
|
];
|
|
|
|
return Container(
|
|
width: width,
|
|
height: height,
|
|
margin: margin,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.1),
|
|
blurRadius: 20,
|
|
spreadRadius: 1,
|
|
)
|
|
],
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
|
|
child: Container(
|
|
padding: padding,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
border: Border.all(
|
|
color: Colors.white.withOpacity(0.2),
|
|
width: 1.5,
|
|
),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: gradientColors ?? defaultGradient,
|
|
),
|
|
),
|
|
child: child,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|