// ignore_for_file: must_be_immutable import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:flutter/material.dart'; class FikoYTButton extends StatelessWidget { const FikoYTButton({ super.key, required this.text, this.onPressed, this.onLongPress, this.route, this.tema, }); final FikoYTButtonTheme? tema; final dynamic text; final String? route; final VoidCallback? onPressed; final VoidCallback? onLongPress; @override Widget build(BuildContext context) { final theme = Theme.of(context).extension(); final textColor = tema?.textColor ?? theme?.textColor; final textShadow = tema?.textShadow ?? theme?.textShadow; final fontSize = tema?.fontSize; final fontWeight = tema?.fontWeight; return TextButton( onLongPress: onLongPress, onPressed: route == null ? onPressed : () { onPressed?.call(); context.vRouter.to(route!); }, style: TextButtonTheme.of(context).style?.copyWith( backgroundColor: WidgetStateProperty.all(tema?.backgroundColor), textStyle: WidgetStateProperty.all( TextStyle( shadows: textShadow, color: textColor, fontSize: fontSize, fontWeight: fontWeight, ), ), shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: tema?.borderRadius ?? BorderRadius.circular(15.0), side: BorderSide(color: tema?.borderColor ?? Colors.transparent), ), ), ), child: text is String ? Padding( padding: tema?.edgePadding ?? EdgeInsets.zero, child: Text( text, textAlign: tema?.textAlign, style: TextStyle( fontSize: fontSize, fontWeight: fontWeight, shadows: textShadow, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = tema?.textStrokeWidth ?? 1.0 ..color = tema?.textStrokeColor ?? Colors.transparent, ).merge(TextStyle(color: textColor)), ), ) : text, ); } } class FikoYTIconButton extends StatefulWidget { FikoYTIconButton({ super.key, required this.text, this.onPressed, this.onLongPress, this.route, this.tema, this.icon, // Yeni eklenen ikon parametresi this.iconWidget, // Yeni eklenen ikon parametresi }); FikoYTButtonTheme? tema; final dynamic text; final String? route; final IconData? icon; // İkon desteği eklendi final Widget? iconWidget; // İkon desteği eklendi final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _FikoYTIconButtonState(); } class _FikoYTIconButtonState extends State with WidgetsBindingObserver { FikoYTButtonTheme? ilkTema; @override void initState() { super.initState(); ilkTema = widget.tema; WidgetsBinding.instance.addObserver(this); } @override void didChangePlatformBrightness() { super.didChangePlatformBrightness(); setState(() {}); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override Widget build(BuildContext context) { return TextButton( onLongPress: widget.onLongPress, onPressed: widget.route == null ? widget.onPressed : () { if (widget.onPressed != null) widget.onPressed!(); context.vRouter.to(widget.route!); }, style: TextButtonTheme.of(context).style?.copyWith( backgroundColor: WidgetStateProperty.all( widget.tema?.backgroundColor, ), textStyle: WidgetStateProperty.all( TextStyle( shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, color: widget.tema?.textColor ?? Theme.of(context).extension()?.textColor, fontSize: widget.tema?.fontSize, fontWeight: widget.tema?.fontWeight, ), ), shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: widget.tema?.borderRadius ?? BorderRadius.all(Radius.circular(widget.tema?.radius ?? 15.0)), side: BorderSide( color: widget.tema?.borderColor ?? Colors.transparent, ), ), ), ), child: widget.text is String ? Padding( padding: widget.tema?.edgePadding ?? EdgeInsets.zero, child: Row( mainAxisSize: MainAxisSize.min, children: [ if (widget.iconWidget != null) widget.iconWidget! else if (widget.icon != null) // Eğer ikon varsa önce ekleyelim Icon( widget.icon, color: widget.tema?.textColor ?? Theme.of(context).extension()?.tertiaryTextColor, size: widget.tema?.fontSize ?? 16.0, shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, ) else if (widget.icon != null) const SizedBox(width: 2), // Metin ve ikon arasında boşluk bırak Stack( children: [ Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, fontSize: widget.tema?.fontSize, fontWeight: widget.tema?.fontWeight, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = widget.tema?.textStrokeWidth ?? 1.0 ..color = widget.tema?.textStrokeColor ?? Colors.transparent, ), ), Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, color: widget.tema?.textColor ?? Theme.of(context).extension()?.textColor, fontSize: widget.tema?.fontSize, fontWeight: widget.tema?.fontWeight, ), ), ], ), ], ), ) : widget.text, ); } } class AnimatedFikoYTButton1 extends StatefulWidget { AnimatedFikoYTButton1({ super.key, required this.text, this.onPressed, this.onLongPress, this.tema, }); dynamic text; FikoYTButtonTheme? tema; final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _AnimatedFikoYTButton1State(); } class _AnimatedFikoYTButton1State extends State with WidgetsBindingObserver { FikoYTButtonTheme? ilkTema; @override void initState() { super.initState(); ilkTema = widget.tema; // widget.tema = FikoButtonTheme.karistir(FikoTheme.of(context).fikoButonTema, ilkTema ?? FikoTheme.of(context).fikoButonTema); WidgetsBinding.instance.addObserver(this); } // This callback is invoked every time the platform brightness changes. @override void didChangePlatformBrightness() { super.didChangePlatformBrightness(); setState(() { // print(FikoTheme.of(context).koyuMod); // widget.tema = FikoButtonTheme.karistir(FikoTheme.of(context).fikoButonTema, ilkTema ?? FikoTheme.of(context).fikoButonTema); }); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override Widget build(BuildContext context) { return TextButton( // icon: const Text("💡"), onLongPress: widget.onLongPress, onPressed: widget.onPressed, style: TextButtonTheme.of(context).style!.copyWith( backgroundColor: WidgetStateProperty.all(widget.tema?.backgroundColor ?? Colors.transparent), shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: widget.tema?.borderRadius ?? BorderRadius.all(Radius.circular(widget.tema?.radius ?? 15.0)), side: BorderSide( color: widget.tema?.borderColor ?? Colors.transparent, ), ), ), ), child: AnimatedSwitcher( duration: widget.tema?.animationDuration ?? const Duration(milliseconds: 750), transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: child, ); }, child: widget.text.runtimeType == String ? Padding( key: ValueKey(widget.text), padding: widget.tema?.edgePadding ?? EdgeInsets.zero, child: Stack( alignment: Alignment.center, children: [ Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, // color: widget.tema?.textColor, fontSize: widget.tema?.fontSize, fontWeight: widget.tema?.fontWeight, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = widget.tema?.textStrokeWidth ?? 1.0 ..color = widget.tema?.textStrokeColor ?? Colors.transparent, ), ), Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( shadows: widget.tema?.textShadow ?? Theme.of(context).extension()?.textShadow, color: widget.tema?.textColor, fontSize: widget.tema?.fontSize, fontWeight: widget.tema?.fontWeight, ), ), ], ), ) : widget.text, ), // animated Text True ise ); } } /// class AnimatedNumberFikoYTButton1 extends StatefulWidget { AnimatedNumberFikoYTButton1({ super.key, required this.text, this.textBuilder, this.onPressed, this.onLongPress, this.tema, }); double? text; dynamic Function(double? tweenValue)? textBuilder; FikoYTButtonTheme? tema; ///---> final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _AnimatedNumberFikoYTButton1State(); } class _AnimatedNumberFikoYTButton1State extends State with WidgetsBindingObserver { late double? _oldText; // Eski text değeri FikoYTButtonTheme? ilkTema; @override void initState() { super.initState(); ilkTema = widget.tema; // widget.tema = FikoButtonTheme.karistir(FikoTheme.of(context).fikoButonTema, ilkTema ?? FikoTheme.of(context).fikoButonTema); _oldText = widget.text; } @override void didUpdateWidget(covariant AnimatedNumberFikoYTButton1 oldWidget) { super.didUpdateWidget(oldWidget); // Eğer widget'ın text değeri değiştiyse, eski değeri sakla if (oldWidget.text != widget.text) { _oldText = oldWidget.text; } } @override void didChangePlatformBrightness() { super.didChangePlatformBrightness(); setState(() { // print(FikoTheme.of(context).koyuMod); // widget.tema = FikoButtonTheme.karistir(FikoTheme.of(context).fikoButonTema, ilkTema ?? FikoTheme.of(context).fikoButonTema); }); } @override Widget build(BuildContext context) { return TweenAnimationBuilder( tween: Tween( begin: _oldText ?? 0.0, // Başlangıç değeri end: widget.text ?? 0.0, ), // Bitiş değeri duration: widget.tema?.animationDuration ?? const Duration(milliseconds: 750), // Animasyon süresi builder: (context, value, child) { return FikoYTButton( // key: ValueKey("${toplamBrutEkUcretler$.value?.toPrecision(2) ?? 0.0} TL"), text: widget.textBuilder != null ? widget.textBuilder!((value.isNaN || value.isInfinite) ? 0.0 : value) : "${(value.isNaN || value.isInfinite) ? 0 : value.toPrecision(2).toStringAsFixed(2)}", onPressed: widget.onPressed, onLongPress: widget.onLongPress, tema: widget.tema, ); }, ); } }