@@ -63,6 +63,8 @@ class _HomeScreenState extends State<HomeScreen>
6363 final TextEditingController inlineimagecontroller =
6464 GetIt .instance.get <InlineImageProvider >().getController ();
6565
66+ final Converters _converters = Converters ();
67+
6668 bool isPrefixIconClicked = false ;
6769 bool isDialInteracting = false ;
6870 String previousText = '' ;
@@ -79,7 +81,6 @@ class _HomeScreenState extends State<HomeScreen>
7981 _setPortraitOrientation ();
8082 animationProvider = context.read <AnimationBadgeProvider >();
8183 speedDialProvider = context.read <SpeedDialProvider >();
82- inlineimagecontroller.addListener (_controllerListner);
8384
8485 if (widget.initialSpeed != null ) {
8586 speedDialProvider.setDialValue (widget.initialSpeed! );
@@ -132,8 +133,8 @@ class _HomeScreenState extends State<HomeScreen>
132133
133134 ToastUtils ().showToast (
134135 "Editing badge: ${badgeFilename .substring (0 , badgeFilename .length - 5 )}" );
135- } catch (e) {
136- print ("Failed to load badge data: $e " );
136+ } catch (e, st ) {
137+ debugPrint ("Failed to load badge data: $e \n $ st " );
137138 ToastUtils ().showToast ("Failed to load badge data" );
138139 }
139140 }
@@ -188,7 +189,6 @@ class _HomeScreenState extends State<HomeScreen>
188189 _vectorScrollController.dispose ();
189190 WidgetsBinding .instance.removeObserver (this );
190191 inlineimagecontroller.removeListener (handleTextChange);
191- inlineimagecontroller.removeListener (_controllerListner);
192192 _tabController.dispose ();
193193 super .dispose ();
194194 }
@@ -203,7 +203,7 @@ class _HomeScreenState extends State<HomeScreen>
203203 }
204204 animationProvider.badgeAnimation (
205205 inlineimagecontroller.text,
206- Converters () ,
206+ _converters ,
207207 animationProvider.isEffectActive (InvertLEDEffect ()),
208208 );
209209 if (mounted) setState (() {});
@@ -250,7 +250,6 @@ class _HomeScreenState extends State<HomeScreen>
250250 borderRadius: BorderRadius .circular (10. r),
251251 elevation: 4 ,
252252 child: ExtendedTextField (
253- onChanged: (value) {},
254253 controller: inlineimagecontroller,
255254 specialTextSpanBuilder: ImageBuilder (),
256255 style: Provider .of <FontProvider >(context)
@@ -439,7 +438,7 @@ class _HomeScreenState extends State<HomeScreen>
439438 fontProvider.changeFont (newFont);
440439 animationProvider.badgeAnimation (
441440 inlineimagecontroller.text,
442- Converters () ,
441+ _converters ,
443442 animationProvider.isEffectActive (
444443 InvertLEDEffect ()),
445444 );
@@ -617,6 +616,7 @@ class _HomeScreenState extends State<HomeScreen>
617616
618617 ToastUtils ().showToast (
619618 "Badge Updated Successfully" );
619+ if (! context.mounted) return ;
620620 Navigator .pushNamedAndRemoveUntil (
621621 context,
622622 '/savedBadge' ,
@@ -701,47 +701,45 @@ class _HomeScreenState extends State<HomeScreen>
701701
702702 void handleTextChange () {
703703 final currentText = inlineimagecontroller.text;
704- final selection = inlineimagecontroller.selection;
705-
706- // Always reset to text animation if a special animation is selected and user types
707- if (animationProvider.isSpecialAnimationSelected () &&
708- currentText.isNotEmpty) {
709- animationProvider.resetToTextAnimation ();
710- animationProvider.badgeAnimation (currentText, Converters (),
711- animationProvider.isEffectActive (InvertLEDEffect ()));
712- setState (() {}); // Ensure UI updates
713- }
714704
715- if (previousText.length > currentText.length) {
716- final deletionIndex = selection.baseOffset;
717- final regex = RegExp (r'<<\d+>>' );
718- final matches = regex.allMatches (previousText);
719-
720- bool placeholderDeleted = false ;
721- for (final match in matches) {
722- if (deletionIndex > match.start && deletionIndex < match.end) {
723- inlineimagecontroller.text =
724- previousText.replaceRange (match.start, match.end, '' );
725- inlineimagecontroller.selection =
726- TextSelection .collapsed (offset: match.start);
727- placeholderDeleted = true ;
728- break ;
729- }
705+ if (currentText != previousText) {
706+ if (animationProvider.isSpecialAnimationSelected () &&
707+ currentText.isNotEmpty) {
708+ animationProvider.resetToTextAnimation ();
730709 }
731- if (! placeholderDeleted) {
732- previousText = inlineimagecontroller.text;
710+
711+ final selection = inlineimagecontroller.selection;
712+ if (previousText.length > currentText.length) {
713+ final deletionIndex = selection.baseOffset;
714+ final regex = RegExp (r'<<\d+>>' );
715+ final matches = regex.allMatches (previousText);
716+
717+ bool placeholderDeleted = false ;
718+ for (final match in matches) {
719+ if (deletionIndex > match.start && deletionIndex < match.end) {
720+ inlineimagecontroller.text =
721+ previousText.replaceRange (match.start, match.end, '' );
722+ inlineimagecontroller.selection =
723+ TextSelection .collapsed (offset: match.start);
724+ placeholderDeleted = true ;
725+ break ;
726+ }
727+ }
728+ if (! placeholderDeleted) {
729+ previousText = inlineimagecontroller.text;
730+ }
731+ } else {
732+ previousText = currentText;
733733 }
734- } else {
735- previousText = currentText;
736- }
737- }
738734
739- void _controllerListner () {
740- animationProvider.badgeAnimation (
741- inlineImageProvider.getController ().text,
742- Converters (),
743- animationProvider.isEffectActive (InvertLEDEffect ()),
744- );
735+ animationProvider.badgeAnimation (
736+ inlineimagecontroller.text,
737+ _converters,
738+ animationProvider.isEffectActive (InvertLEDEffect ()),
739+ );
740+
741+ setState (() {});
742+ }
745743 }
746744
747745 @override
0 commit comments