master #81
@ -0,0 +1,51 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class CardBackground extends StatefulWidget {
|
||||||
|
const CardBackground({super.key, this.background, this.cardKey});
|
||||||
|
|
||||||
|
final Widget? background;
|
||||||
|
final GlobalKey? cardKey;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CardBackground> createState() => _CardBackgroundState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CardBackgroundState extends State<CardBackground> {
|
||||||
|
Size _cardSize = Size.zero;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (widget.background != null) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_resizeCard();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant CardBackground oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.background != null) {
|
||||||
|
_resizeCard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _resizeCard() {
|
||||||
|
final RenderObject? renderBox =
|
||||||
|
widget.cardKey?.currentContext?.findRenderObject();
|
||||||
|
if (renderBox != null) {
|
||||||
|
setState(() {
|
||||||
|
_cardSize =
|
||||||
|
Size(renderBox.paintBounds.width, renderBox.paintBounds.height);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => SizedBox(
|
||||||
|
width: _cardSize.width,
|
||||||
|
height: _cardSize.height,
|
||||||
|
child: Center(child: widget.background),
|
||||||
|
);
|
||||||
|
}
|
@ -15,11 +15,12 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wyatt_ui_kit/src/components/cards/widgets/card_background.dart';
|
||||||
import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart';
|
import 'package:wyatt_ui_kit/src/components/gradients/gradient_box_border.dart';
|
||||||
import 'package:wyatt_ui_kit/src/domain/card_theme_extension.dart';
|
import 'package:wyatt_ui_kit/src/domain/card_theme_extension.dart';
|
||||||
|
|
||||||
class CardWrapper extends StatefulWidget {
|
class CardWrapper extends StatelessWidget {
|
||||||
const CardWrapper({
|
CardWrapper({
|
||||||
required this.child,
|
required this.child,
|
||||||
required this.backgroundColors,
|
required this.backgroundColors,
|
||||||
required this.borderColors,
|
required this.borderColors,
|
||||||
@ -40,54 +41,19 @@ class CardWrapper extends StatefulWidget {
|
|||||||
final Size? maxSize;
|
final Size? maxSize;
|
||||||
final double? padding;
|
final double? padding;
|
||||||
|
|
||||||
@override
|
|
||||||
State<CardWrapper> createState() => _CardWrapperState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CardWrapperState extends State<CardWrapper> {
|
|
||||||
Size _cardSize = Size.zero;
|
|
||||||
final GlobalKey _key = GlobalKey();
|
final GlobalKey _key = GlobalKey();
|
||||||
|
|
||||||
@override
|
Widget _buildChild(Widget child) => (background != null)
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
if (widget.background != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
_resizeCard();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(covariant CardWrapper oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (widget.background != null) {
|
|
||||||
_resizeCard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _resizeCard() {
|
|
||||||
final RenderObject? renderBox = _key.currentContext?.findRenderObject();
|
|
||||||
if (renderBox != null) {
|
|
||||||
setState(() {
|
|
||||||
_cardSize =
|
|
||||||
Size(renderBox.paintBounds.width, renderBox.paintBounds.height);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildChild(Widget child) => (widget.background != null)
|
|
||||||
? Stack(
|
? Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
CardBackground(
|
||||||
width: _cardSize.width,
|
cardKey: _key,
|
||||||
height: _cardSize.height,
|
background: background,
|
||||||
child: Center(child: widget.background),
|
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(
|
padding: EdgeInsets.all(
|
||||||
widget.padding ?? 25,
|
padding ?? 25,
|
||||||
),
|
),
|
||||||
child: child,
|
child: child,
|
||||||
),
|
),
|
||||||
@ -95,15 +61,14 @@ class _CardWrapperState extends State<CardWrapper> {
|
|||||||
)
|
)
|
||||||
: Padding(
|
: Padding(
|
||||||
padding: EdgeInsets.all(
|
padding: EdgeInsets.all(
|
||||||
widget.padding ?? 25,
|
padding ?? 25,
|
||||||
),
|
),
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
|
|
||||||
Gradient? _cardGradient(BuildContext context) {
|
Gradient? _cardGradient(BuildContext context) {
|
||||||
if (widget.backgroundColors != null &&
|
if (backgroundColors != null && backgroundColors!.length >= 2) {
|
||||||
widget.backgroundColors!.length >= 2) {
|
return LinearGradient(colors: backgroundColors!);
|
||||||
return LinearGradient(colors: widget.backgroundColors!);
|
|
||||||
} else {
|
} else {
|
||||||
final extensionCardColor =
|
final extensionCardColor =
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
Theme.of(context).extension<CardThemeExtension>();
|
||||||
@ -120,9 +85,8 @@ class _CardWrapperState extends State<CardWrapper> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Color? _cardColor(BuildContext context) {
|
Color? _cardColor(BuildContext context) {
|
||||||
if (widget.backgroundColors != null &&
|
if (backgroundColors != null && backgroundColors!.length == 1) {
|
||||||
widget.backgroundColors!.length == 1) {
|
return backgroundColors!.first;
|
||||||
return widget.backgroundColors!.first;
|
|
||||||
} else {
|
} else {
|
||||||
final extensionCardColor =
|
final extensionCardColor =
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
Theme.of(context).extension<CardThemeExtension>();
|
||||||
@ -136,16 +100,16 @@ class _CardWrapperState extends State<CardWrapper> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoxBorder? _boxBorder(BuildContext context) {
|
BoxBorder? _boxBorder(BuildContext context) {
|
||||||
if (widget.borderColors != null) {
|
if (borderColors != null) {
|
||||||
if (widget.borderColors!.length >= 2) {
|
if (borderColors!.length >= 2) {
|
||||||
return CustomGradientBoxBorder(
|
return CustomGradientBoxBorder(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
colors: widget.borderColors!,
|
colors: borderColors!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (widget.borderColors!.isNotEmpty) {
|
} else if (borderColors!.isNotEmpty) {
|
||||||
return Border.all(
|
return Border.all(
|
||||||
color: widget.borderColors!.first,
|
color: borderColors!.first,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -171,8 +135,8 @@ class _CardWrapperState extends State<CardWrapper> {
|
|||||||
|
|
||||||
List<BoxShadow> _shadow(BuildContext context) {
|
List<BoxShadow> _shadow(BuildContext context) {
|
||||||
final shadows = List<BoxShadow>.empty(growable: true);
|
final shadows = List<BoxShadow>.empty(growable: true);
|
||||||
if (widget.shadow != null) {
|
if (shadow != null) {
|
||||||
shadows.add(widget.shadow!);
|
shadows.add(shadow!);
|
||||||
} else {
|
} else {
|
||||||
final extensionCardColor =
|
final extensionCardColor =
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
Theme.of(context).extension<CardThemeExtension>();
|
||||||
@ -195,17 +159,17 @@ class _CardWrapperState extends State<CardWrapper> {
|
|||||||
border: _boxBorder(context),
|
border: _boxBorder(context),
|
||||||
boxShadow: _shadow(context),
|
boxShadow: _shadow(context),
|
||||||
),
|
),
|
||||||
child: (widget.minSize != null && widget.maxSize != null)
|
child: (minSize != null && maxSize != null)
|
||||||
? ConstrainedBox(
|
? ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
minWidth: widget.minSize!.width,
|
minWidth: minSize!.width,
|
||||||
minHeight: widget.minSize!.height,
|
minHeight: minSize!.height,
|
||||||
maxWidth: widget.maxSize!.width,
|
maxWidth: maxSize!.width,
|
||||||
maxHeight: widget.maxSize!.height,
|
maxHeight: maxSize!.height,
|
||||||
),
|
),
|
||||||
child: _buildChild(widget.child),
|
child: _buildChild(child),
|
||||||
)
|
)
|
||||||
: _buildChild(widget.child),
|
: _buildChild(child),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user