87 lines
2.4 KiB
Dart
87 lines
2.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import '../l10n/app_localizations.dart';
|
|
import '../service/notifying.dart';
|
|
import '../service/permission_service.dart';
|
|
import '../service/storage.dart';
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
static const routeName = '/settings';
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
State<SettingsPage> createState() => _SettingsPageState();
|
|
}
|
|
|
|
class _SettingsPageState extends State<SettingsPage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
|
body: SizedBox(
|
|
width: MediaQuery.of(context).size.width * 0.9,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context)!.appData,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => onActivateJsonImportPressed(),
|
|
child: Text(AppLocalizations.of(context)!.import),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => onActivateJsonExportPressed(),
|
|
child: Text(AppLocalizations.of(context)!.export),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void onActivateJsonExportPressed() async {
|
|
if (!await checkStoragePermission) return;
|
|
|
|
Storage.exportToJsonFile().then(showExportInfo);
|
|
}
|
|
|
|
void onActivateJsonImportPressed() async {
|
|
if (!await checkStoragePermission) return;
|
|
Storage.importFromJsonFile().then(showImportInfo);
|
|
}
|
|
|
|
Future<bool> get checkStoragePermission async {
|
|
if (!(await PermissionService.requestStoragePermission).isGranted) {
|
|
if (mounted) {
|
|
Notifying.showErrorSnackbar(
|
|
context,
|
|
AppLocalizations.of(context)!.errorStoragePermisson,
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void showExportInfo(bool success) => Notifying.showSnackbar(
|
|
context,
|
|
text: success
|
|
? AppLocalizations.of(context)!.exportSuccess
|
|
: AppLocalizations.of(context)!.exportFailed,
|
|
isError: success,
|
|
);
|
|
|
|
void showImportInfo(bool success) => Notifying.showSnackbar(
|
|
context,
|
|
text: success
|
|
? AppLocalizations.of(context)!.importSuccess
|
|
: AppLocalizations.of(context)!.importFailed,
|
|
isError: success,
|
|
);
|
|
}
|