Files
tatuchat/lib/pages/intro/flows/restore_backup_flow.dart
Welton Moura 0037b0b9cf
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Initial commit
2026-09-11 15:59:56 -03:00

39 lines
1.2 KiB
Dart

// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:tatchat/utils/file_selector.dart';
import 'package:tatchat/widgets/future_loading_dialog.dart';
import 'package:tatchat/widgets/matrix.dart';
import 'package:go_router/go_router.dart';
import 'package:material_ui/material_ui.dart';
Future<void> restoreBackupFlow(BuildContext context) async {
final matrix = Matrix.of(context);
final picked = await selectFiles(context);
final file = picked.firstOrNull;
if (file == null) return;
if (!context.mounted) return;
final result = await showFutureLoadingDialog(
context: context,
future: () async {
final client = await matrix.getLoginClient();
await client.database.importDump(
String.fromCharCodes(await file.readAsBytes()),
);
await client.init(
waitForFirstSync: false,
waitUntilLoadCompletedLoaded: false,
);
matrix.initMatrix();
return client.isLogged();
},
);
if (result.result == true && context.mounted) {
context.go('/rooms');
}
}