feat(vault): pick a notebook vault folder on first run
Some checks failed
CI / Windows build (push) Has been cancelled
Some checks failed
CI / Windows build (push) Has been cancelled
Phase 0 of the file-based storage plan (docs/plans/ 2026-06-24-file-based-storage.md). Foundation only — no editor or DB change yet. - VaultService (SharedPreferences): stores the vault root path, vaultRootValid() = path set AND directory exists. - VaultSetupScreen: first-run folder picker (file_picker, Windows). - main.dart gates HomeScreen behind a valid vault, re-prompting if the saved folder is gone. - Settings: a Vault section to change the folder. Editors still use SQLite; later phases move annotations into per-file sidecars under the vault. analyze clean, tests green.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -6,6 +7,7 @@ import '../l10n/app_localizations.dart';
|
||||
import '../models/pen_tool.dart';
|
||||
import '../models/pressure_curve.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
import '../services/vault_service.dart';
|
||||
import '../utils/stroke_stabilizer.dart';
|
||||
|
||||
/// Material 3 settings screen for BadNote.
|
||||
@@ -282,6 +284,12 @@ class SettingsScreen extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
_SectionHeader(title: 'Vault', icon: Icons.folder_special),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: _VaultSettings(),
|
||||
),
|
||||
const Divider(),
|
||||
_SectionHeader(title: 'About', icon: Icons.info),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
@@ -320,6 +328,93 @@ class SettingsScreen extends ConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the current vault folder path and lets the user re-pick it. Re-uses
|
||||
/// the same `getDirectoryPath` flow as the first-run [VaultSetupScreen],
|
||||
/// persisting the choice through [VaultService.setVaultRoot].
|
||||
class _VaultSettings extends StatefulWidget {
|
||||
const _VaultSettings();
|
||||
|
||||
@override
|
||||
State<_VaultSettings> createState() => _VaultSettingsState();
|
||||
}
|
||||
|
||||
class _VaultSettingsState extends State<_VaultSettings> {
|
||||
VaultService? _vault;
|
||||
String? _path;
|
||||
bool _busy = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final vault = await VaultService.getInstance();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_vault = vault;
|
||||
_path = vault.vaultRoot;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _changeFolder() async {
|
||||
final vault = _vault;
|
||||
if (vault == null) return;
|
||||
final l = AppLocalizations.of(context);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
final path = await FilePicker.platform.getDirectoryPath(
|
||||
dialogTitle: l.vaultSetupTitle,
|
||||
lockParentWindow: true,
|
||||
);
|
||||
if (path != null) {
|
||||
await vault.setVaultRoot(path);
|
||||
if (!mounted) return;
|
||||
setState(() => _path = path);
|
||||
messenger.showSnackBar(SnackBar(content: Text(l.vaultUpdated)));
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text(l.vaultPickFailed(e.toString()))),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l = AppLocalizations.of(context);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l.vaultFolderLabel,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
(_path == null || _path!.isEmpty) ? l.vaultNoneSelected : _path!,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy ? null : _changeFolder,
|
||||
icon: const Icon(Icons.drive_folder_upload),
|
||||
label: Text(l.vaultChangeFolder),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final IconData icon;
|
||||
|
||||
Reference in New Issue
Block a user