// ignore_for_file: must_be_immutable import 'package:fikoyt_ui/ui/tema/fikoyt_tema.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vrouter/vrouter.dart'; class FikoButton extends StatefulWidget { FikoButton({ super.key, required this.text, this.onPressed, this.onLongPress, this.route, this.tema, }); FikoButtonTema? tema; dynamic text; String? route; final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _FikoButtonState(); } class _FikoButtonState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); 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 = FikoButtonTema.karistir(FikoTheme.of(context).fikoButonTema, widget.tema ?? 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?.arkaRenk, ), shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: widget.tema?.borderRadius ?? const BorderRadius.all(Radius.circular(15.0)), side: BorderSide( color: widget.tema?.sinirRengi ?? 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?.boyutYazi, fontWeight: widget.tema?.fontWeight, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = widget.tema?.boyutYaziSinir ?? 1.0 ..color = widget.tema?.yaziSinirRengi ?? Colors.transparent, ), ), ), Align( alignment: Alignment.center, child: Text( widget.text, textAlign: widget.tema?.textAlign, style: TextStyle( color: widget.tema?.yaziRengi, fontSize: widget.tema?.boyutYazi, fontWeight: widget.tema?.fontWeight, ), ), ), ], ), ) : widget.text, ); } } class AnimatedFikoButton1 extends StatelessWidget { AnimatedFikoButton1({ super.key, required this.text, this.onPressed, this.onLongPress, FikoButtonTema? tema, }) : tema = tema ?? FikoButtonTema(); dynamic text; final FikoButtonTema tema; final VoidCallback? onPressed; final VoidCallback? onLongPress; @override Widget build(BuildContext context) { return TextButton( // icon: const Text("💡"), onLongPress: onLongPress, onPressed: onPressed, style: TextButtonTheme.of(context).style!.copyWith( backgroundColor: WidgetStateProperty.all(tema.arkaRenk), shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: tema.borderRadius ?? const BorderRadius.all(Radius.circular(15.0)), side: BorderSide( color: tema.sinirRengi ?? Colors.transparent, ), ), ), ), child: AnimatedSwitcher( duration: tema.animasyonSuresi ?? const Duration(milliseconds: 750), transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: child, ); }, child: text.runtimeType == String ? Padding( key: ValueKey(text), padding: tema.edgePadding ?? EdgeInsets.zero, child: Stack( alignment: Alignment.center, children: [ Align( alignment: Alignment.center, child: Text( text, textAlign: tema.textAlign, style: TextStyle( // color: Colors.amberAccent, fontSize: tema.boyutYazi, fontWeight: tema.fontWeight, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = tema.boyutYaziSinir ?? 1.0 ..color = tema.yaziSinirRengi ?? Colors.transparent, ), ), ), Align( alignment: Alignment.center, child: Text( text, textAlign: tema.textAlign, style: TextStyle( color: tema.yaziRengi, fontSize: tema.boyutYazi, fontWeight: tema.fontWeight, ), ), ), ], ), ) : text, ), // animated Text True ise ); } } /** * */ class AnimatedNumberFikoButton1 extends StatefulWidget { AnimatedNumberFikoButton1({ super.key, required this.text, this.textBuilder, this.onPressed, this.onLongPress, FikoButtonTema? tema, }) : tema = tema ?? FikoButtonTema(); double? text; dynamic Function(double tweenValue)? textBuilder; final FikoButtonTema tema; ///---> final VoidCallback? onPressed; final VoidCallback? onLongPress; @override State createState() => _AnimatedNumberFikoButton1State(); } class _AnimatedNumberFikoButton1State extends State { late double? _oldText; // Eski text değeri @override void initState() { super.initState(); _oldText = widget.text; // Başlangıçta eski değeri constructor'dan alıyoruz } @override void didUpdateWidget(covariant AnimatedNumberFikoButton1 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 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?.animasyonSuresi ?? const Duration(milliseconds: 750), // Animasyon süresi builder: (context, value, child) { return FikoButton( // 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 FikoButtonTema { FikoButtonTema({ this.yaziRengi, this.yaziSinirRengi, this.arkaRenk, this.sinirRengi, this.boyutYaziSinir, this.boyutYazi, this.radius, borderRadius, this.edgePadding, this.textAlign, this.fontWeight, animasyonSuresi, }); Color? yaziRengi; Color? yaziSinirRengi; Color? arkaRenk; Color? sinirRengi; double? boyutYaziSinir; double? boyutYazi; double? radius; Duration? animasyonSuresi; BorderRadiusGeometry? borderRadius; EdgeInsetsGeometry? edgePadding; TextAlign? textAlign; FontWeight? fontWeight; FikoButtonTema copyWith({ Color? yaziRengi, Color? yaziSinirRengi, Color? arkaRenk, Color? sinirRengi, double? boyutYaziSinir, double? boyutYazi, double? radius, Duration? animasyonSuresi, BorderRadiusGeometry? borderRadius, EdgeInsetsGeometry? edgePadding, TextAlign? textAlign, FontWeight? fontWeight, }) { return FikoButtonTema( yaziRengi: yaziRengi ?? this.yaziRengi, yaziSinirRengi: yaziSinirRengi ?? this.yaziSinirRengi, arkaRenk: arkaRenk ?? this.arkaRenk, animasyonSuresi: animasyonSuresi ?? this.animasyonSuresi, borderRadius: borderRadius ?? this.borderRadius, boyutYazi: boyutYazi ?? this.boyutYazi, boyutYaziSinir: boyutYaziSinir ?? this.boyutYaziSinir, edgePadding: edgePadding ?? this.edgePadding, fontWeight: fontWeight ?? this.fontWeight, radius: radius ?? this.radius, sinirRengi: sinirRengi ?? this.sinirRengi, textAlign: textAlign ?? this.textAlign, ); } static FikoButtonTema karistir(FikoButtonTema gecerliTema, FikoButtonTema tema1) { FikoButtonTema rslt = FikoButtonTema(); rslt.yaziRengi = gecerliTema.yaziRengi ?? tema1.yaziRengi; rslt.yaziSinirRengi = gecerliTema.yaziSinirRengi ?? tema1.yaziSinirRengi; rslt.arkaRenk = gecerliTema.arkaRenk ?? tema1.arkaRenk; rslt.animasyonSuresi = gecerliTema.animasyonSuresi ?? tema1.animasyonSuresi; rslt.borderRadius = gecerliTema.borderRadius ?? tema1.borderRadius; rslt.boyutYazi = gecerliTema.boyutYazi ?? tema1.boyutYazi; rslt.boyutYaziSinir = gecerliTema.boyutYaziSinir ?? tema1.boyutYaziSinir; rslt.edgePadding = gecerliTema.edgePadding ?? tema1.edgePadding; rslt.fontWeight = gecerliTema.fontWeight ?? tema1.fontWeight; rslt.radius = gecerliTema.radius ?? tema1.radius; rslt.sinirRengi = gecerliTema.sinirRengi ?? tema1.sinirRengi; rslt.textAlign = gecerliTema.textAlign ?? tema1.textAlign; return rslt; } }