I am getting blank value after wraping Text widget in AutoLocalBuilder widget

Viewed 22

I am using AutoLocalBuilder widget by using package auto_localization: ^1.2.0 in my project for translating text in selected langauge. The Problem I am facing that after wraping my Text widget inside AutoLocalBuilder widget,i am getting blank value.

I have mentioned my code in steps:

Step1. I have declared a variable called drugInteractionValue of type String as given below

String? drugInteractionValue;

Step2. I have fetched data from api as given below

void getDrugInteractionResult()
  {
    getDrugInteractionFromAPI().then((value)
                            {
                              if(value.data!.isNotEmpty)
                              {
                                for(int i=0;i<value.data!.length;i++)
                                {
                                  setState(() {
                                  drugInteractionValue = value.data![i].interaction;  
                                  });
                               }
                               print("Drug Interaction value = ${drugInteractionValue??""}");
                              }else
                              {
                                setState(() {
                                  drugInteractionValue = "No Interactions Found";
                                });
                              }
                              
                            });
                             
  }

Step3. I have called getDrugInteractionResult() method on click of submit button, code written is as given below:

InkWell(
         onTap: ()
         {
            if(drug1Value!=null&&drug2Value!=null)
              {
               getDrugInteractionResult();
                              
              }else if(drug1Value==null)
                {
                  Fluttertoast.showToast(msg:"Select Drug1 From DropDown");
                }else
                  {
                     Fluttertoast.showToast(msg:"Select Drug2 From DropDown");
                  }
         },
    child: Container(
                     alignment: Alignment.center,
                     height: 6 * SizeConfig.heightMultiplier,
                     width: 50 * SizeConfig.widthMultiplier,
                     decoration: const BoxDecoration(
                     color:  MyColors.secondaryAppColor,
                     borderRadius:BorderRadius.all(Radius.circular(25))),
                     child:AutoLocalBuilder
                    (
                      text: ["Submit"],
                      builder: (text, percentage) 
                      {
                        return Text
                        (
                        text[0],
                        style: TextStylewhiteProximaNova()
                               .pMediumTextStyle
                               .copyWith
                                (
                                 fontWeight:
                                 semiBoldFontWeight
                                )
                      );
                     }
                 ),
            ),
         ),
  1. After that I have wrapped my Text widget inside AutoLocalBuilder widget, code written is as given below:

    AutoLocalBuilder ( text: [drugInteractionValue??""], builder: (text, percentage) { return Text ( text[0], style: const TextStyle ( fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black54 ),
    ); } )

Note: While printing value I am getting value updated in variable called drugInteractionValue but when I am using drugInteractionValue variable in Text widget which is wrapped in AutoLocalBuilder widget I am getting blank value.

So please help me to solve this issue.

0 Answers
Related