Parameter of type 'DocumentDirection' Cannot read property ‘dir’ of undefined

Hi I just make a multi language app with RTL for the menu

here’s my code in my Settings Page ts where the change language bottom there

export class SettingsPage {
  languageSelected : any = 'en';
  languages : Array<LanguageModel>;
  dir: string;
  
  constructor (
    public navCtrl: NavController,
    public translate: TranslateService,
    public languageService: LanguageService,
    public platform:Platform
 
  ) 
 

  {
    this.languages = this.languageService.getLanguages();
    this.setLanguage();
  }

  
  changeLanguage(languageId) {
    if (languageId === 'ar') {
      this.platform.setDir('rtl', true);
      this.translate.setDefaultLang(languageId);
      
    } else {
      this.platform.setDir('ltr', true);
      this.translate.setDefaultLang(languageId);
    }
  }

  
  setLanguage(){
    this.dir = this.dir == 'ltr' ? 'rtl' : 'ltr';
    this.platform.setDir(this.dir,true); 
    let defaultLanguage = this.translate.getDefaultLang();
    if(this.languageSelected){
      this.translate.setDefaultLang(this.languageSelected);
      this.translate.use(this.languageSelected);
      
    }else{
      this.languageSelected = defaultLanguage;
      this.translate.use(defaultLanguage);
    }
  } 
  
}

and I get error Cannot read property ‘dir’ of undefined

I found the solution but i’m sure the app is corrupted after that all changes and try in codes, I hate when something goes wrong it make all things unstable after all.