dbBackUp static method
Implementation
static dbBackUp(BuildContext context) async {
String dbname = await Libs.pref.getString(ConstRF.dbName);
String userName = await Libs.pref.getString('UserName');
Map<String, dynamic> systemInfo = await SystemRF.deviceInfo();
DialogRF(
context,
title: Libs.config.app.title!,
height: 120,
avatarIcon: Icons.backup,
avatarBackground: Colors.grey,
blurAmount: 5,
subTitle: "Database Backup",
body: Container(
margin: const EdgeInsets.symmetric(vertical: 20),
child: Center(
child: TextRF(
"Do you want to backup your database ?",
align: TextAlign.center,
color: Colors.black,
size: 18,
)),
),
type: DialogType.popup,
hideDefaultControls: false,
onAccept: () async {
bool isInternet = await SystemRF.network.hasInternet();
if (isInternet) {
var pdlg = ProgressDialog(Libs.context!,
type: ProgressDialogType.download, isDismissible: true);
pdlg.update(message: 'Backuping DB ...');
pdlg.show();
var documentDirectory = await getApplicationDocumentsDirectory();
String email = 'rapidfire.sci@gmail.com';
String pass = '@abc@123@';
String path = documentDirectory.path;
path = path + '/' + dbname;
print(path);
final smtpServer = smtp.gmail(email, pass);
String htmlData =
'<h1>RF Backup Database</h1>\n<p>This is a backup database from RapidFire Mobile (a product of SCI BD IT)</p>';
systemInfo.forEach((key, value) {
htmlData = htmlData + '\n<p>${key} : ${value.toString()} </p>';
});
// Create our message.
final message = mailer.Message()
..from = mailer.Address(email, Libs.config.app.title)
..recipients.add(Libs.config.db.backUpMail)
..subject = ' DB of ' + userName
..text =
'This is a backup database from RapidFire Mobile (a product of SCI BD IT)'
..attachments.add(mailer.FileAttachment(File(path)))
..html = htmlData;
try {
final sendReport = await mailer.send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
pdlg.hide();
} on mailer.MailerException catch (e) {
pdlg.hide();
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
} else {
rf.msg(rf.context, 'No Internet connection');
}
},
);
}