// ignore_for_file: must_be_immutable import 'dart:ui'; import 'package:fikoyt_ui/ui/themes/fikoyt_theme.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vrouter/vrouter.dart'; class FikoYTButton extends StatefulWidget { FikoYTButton({ super.key, required this.text, this.onPressed, this.onLongPress, this.route, this.tema, }); FikoYTButtonTheme? tema; dynamic text; String? route; final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _FikoYTButtonState(); } class _FikoYTButtonState 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.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, ), 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.runtimeType == String ? Padding( padding: widget.tema?.edgePadding ?? EdgeInsets.zero, child: Stack( alignment: Alignment.center, children: [ Align( alignment: Alignment.center, child: Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( // color: Colors.amberAccent, 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, ), ), ), Align( alignment: Alignment.center, child: Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( color: widget.tema?.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: [ Align( alignment: Alignment.center, child: Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( // 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, ), ), ), Align( alignment: Alignment.center, child: Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( 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, ); }, ); } } class FikoYTButtonTheme extends ThemeExtension { FikoYTButtonTheme({ this.textColor, this.textStrokeColor, this.backgroundColor, this.borderColor, this.textStrokeWidth, this.fontSize, this.radius, borderRadius, this.edgePadding, this.textAlign, this.fontWeight, animationDuration, this.textShadow, }); Color? textColor; Color? textStrokeColor; Color? backgroundColor; Color? borderColor; double? textStrokeWidth; double? fontSize; double? radius; Duration? animationDuration; Shadow? textShadow; BorderRadiusGeometry? borderRadius; EdgeInsetsGeometry? edgePadding; TextAlign? textAlign; FontWeight? fontWeight; @override FikoYTButtonTheme copyWith({ Color? textColor, Color? textStrokeColor, Color? backgroundColor, Color? borderColor, double? textStrokeWidth, double? fontSize, double? radius, Duration? animationDuration, BorderRadiusGeometry? borderRadius, EdgeInsetsGeometry? edgePadding, TextAlign? textAlign, FontWeight? fontWeight, }) { return FikoYTButtonTheme( textColor: textColor ?? this.textColor, textStrokeColor: textStrokeColor ?? this.textStrokeColor, backgroundColor: backgroundColor ?? this.backgroundColor, animationDuration: animationDuration ?? this.animationDuration, borderRadius: borderRadius ?? this.borderRadius, fontSize: fontSize ?? this.fontSize, textStrokeWidth: textStrokeWidth ?? this.textStrokeWidth, edgePadding: edgePadding ?? this.edgePadding, fontWeight: fontWeight ?? this.fontWeight, radius: radius ?? this.radius, borderColor: borderColor ?? this.borderColor, textAlign: textAlign ?? this.textAlign, ); } static FikoYTButtonTheme karistir( FikoYTButtonTheme tema1, FikoYTButtonTheme gecerliTema, ) { FikoYTButtonTheme rslt = FikoYTButtonTheme(); rslt.textColor = gecerliTema.textColor ?? tema1.textColor; rslt.textStrokeColor = gecerliTema.textStrokeColor ?? tema1.textStrokeColor; rslt.backgroundColor = gecerliTema.backgroundColor ?? tema1.backgroundColor; rslt.animationDuration = gecerliTema.animationDuration ?? tema1.animationDuration; rslt.borderRadius = gecerliTema.borderRadius ?? tema1.borderRadius; rslt.fontSize = gecerliTema.fontSize ?? tema1.fontSize; rslt.textStrokeWidth = gecerliTema.textStrokeWidth ?? tema1.textStrokeWidth; rslt.edgePadding = gecerliTema.edgePadding ?? tema1.edgePadding; rslt.fontWeight = gecerliTema.fontWeight ?? tema1.fontWeight; rslt.radius = gecerliTema.radius ?? tema1.radius; rslt.borderColor = gecerliTema.borderColor ?? tema1.borderColor; rslt.textAlign = gecerliTema.textAlign ?? tema1.textAlign; return rslt; } @override FikoYTButtonTheme lerp(ThemeExtension other, double t) { if (other is! FikoYTButtonTheme) { return this; } return FikoYTButtonTheme( textColor: Color.lerp(textColor, other.textColor, t), textStrokeColor: Color.lerp(textStrokeColor, other.textStrokeColor, t), backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t), animationDuration: lerpDuration(animationDuration ?? Duration.zero, other.animationDuration ?? Duration.zero, t), borderRadius: BorderRadius.lerp(borderRadius?.resolve(TextDirection.ltr), other.borderRadius?.resolve(TextDirection.ltr), t), fontSize: lerpDouble(fontSize, other.fontSize, t), textStrokeWidth: lerpDouble(textStrokeWidth, other.textStrokeWidth, t), edgePadding: EdgeInsets.lerp(edgePadding?.resolve(TextDirection.ltr), other.edgePadding?.resolve(TextDirection.ltr), t), fontWeight: FontWeight.lerp(fontWeight, other.fontWeight, t), radius: lerpDouble(radius, other.radius, t), borderColor: Color.lerp(borderColor, other.borderColor, t), textAlign: textAlign, ); } }