134 lines
3.3 KiB
Dart
134 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:rasadyar_app/presentation/common/app_color.dart';
|
|
import 'package:vector_graphics/vector_graphics.dart';
|
|
|
|
SvgPicture vecWidget(
|
|
String assets, {
|
|
double? width,
|
|
double? height,
|
|
BoxFit? fit,
|
|
Color? color,
|
|
}) {
|
|
return SvgPicture(
|
|
AssetBytesLoader(assets),
|
|
width: width,
|
|
height: height,
|
|
fit: fit ?? BoxFit.contain,
|
|
colorFilter:
|
|
color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
|
|
);
|
|
}
|
|
|
|
SvgPicture svgWidget(
|
|
String assets, {
|
|
double? width,
|
|
double? height,
|
|
BoxFit? fit,
|
|
Color? color,
|
|
}) {
|
|
return SvgPicture.asset(
|
|
assets,
|
|
width: width,
|
|
height: height,
|
|
fit: fit ?? BoxFit.contain,
|
|
colorFilter:
|
|
color != null ? ColorFilter.mode(color, BlendMode.srcIn) : null,
|
|
);
|
|
}
|
|
|
|
|
|
Widget vecWidget2(
|
|
String assets, {
|
|
double? width,
|
|
double? height,
|
|
BoxFit? fit,
|
|
Color? color,
|
|
}) {
|
|
final resolvedColor = WidgetStateProperty.resolveWith<Color?>((states) {
|
|
if (states.contains(WidgetState.pressed)) {
|
|
return Colors.white;
|
|
}
|
|
return color;
|
|
}).resolve({}); // You can pass actual states if needed
|
|
|
|
return IconTheme(
|
|
data: IconThemeData(color: resolvedColor),
|
|
child: SvgPicture(
|
|
AssetBytesLoader(assets),
|
|
width: width,
|
|
height: height,
|
|
fit: fit ?? BoxFit.contain,
|
|
colorFilter: resolvedColor != null
|
|
? ColorFilter.mode(resolvedColor, BlendMode.srcIn)
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
class ColoredSvgButton extends StatefulWidget {
|
|
final String svgPath;
|
|
final String text;
|
|
final VoidCallback? onPressed;
|
|
|
|
const ColoredSvgButton({
|
|
required this.svgPath,
|
|
required this.text,
|
|
this.onPressed,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
State<ColoredSvgButton> createState() => _ColoredSvgButtonState();
|
|
}
|
|
|
|
class _ColoredSvgButtonState extends State<ColoredSvgButton> {
|
|
bool _isPressed = false;
|
|
bool _isHovered = false;
|
|
|
|
Color _getIconColor() {
|
|
if (_isPressed) return Colors.white;
|
|
if (_isHovered) return AppColor.blueNormal.withAlpha(50);
|
|
return AppColor.blueNormal;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MouseRegion(
|
|
onEnter: (_) => setState(() => _isHovered = true),
|
|
onExit: (_) => setState(() {
|
|
_isHovered = false;
|
|
_isPressed = false;
|
|
}),
|
|
child: GestureDetector(
|
|
onTapDown: (_) => setState(() => _isPressed = true),
|
|
onTapUp: (_) => setState(() => _isPressed = false),
|
|
onTapCancel: () => setState(() => _isPressed = false),
|
|
child: OutlinedButton.icon(
|
|
icon: SvgPicture.asset(
|
|
widget.svgPath,
|
|
width: 24,
|
|
height: 24,
|
|
color: _getIconColor(),
|
|
),
|
|
label: Text(widget.text),
|
|
onPressed: widget.onPressed,
|
|
style: OutlinedButton.styleFrom(
|
|
side: BorderSide(
|
|
color: AppColor.blueNormal,
|
|
width: 2,
|
|
),
|
|
foregroundColor: AppColor.blueNormal,
|
|
backgroundColor: _isPressed ? AppColor.blueNormal : null,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|