Hey there, I need a bit of assistance. In my application, I've added a function that allows users to switch between light and dark themes when they press a button. Everything seems to be working fine, except for one thing - whenever the application is restarted, the theme defaults back to light. Any ideas on how I can use Ionic's native storage to save the theme preference?
import { Component } from '@angular/core';
import { NativeStorage } from '@ionic-native/native-storage/ngx'
import { EmailComposer } from '@ionic-native/email-composer/ngx';
@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
theme:string = "light";
constructor(public nativeStorage:NativeStorage, private emailComposer: EmailComposer) {}
switchTheme(){
if(this.theme=='light'){
document.body.classList.add("dark");
this.theme="dark";
console.log(this.theme)
} else {
document.body.classList.remove("dark");
this.theme='light';
console.log(this.theme)
}
}
sendEmail() {
let email = {
to:'my-mail',
subject: 'My Feedback',
isHtml: true
};
this.emailComposer.open(email);
}
}
Thank you in advance!