utils/sync_settings_ui/lib/src/sync_settings_sections.dart
Krzysztof kuhy Rudnicki 06ca32ce6d sync_settings_ui: split sync_settings_screen.dart 382 -> 192
sync_settings_widget.dart   68  — the public StatefulWidget and its callbacks
  sync_settings_sections.dart 132 — the two sections the screen composes
  sync_settings_screen.dart   192 — the State: loading, connecting, build

Uses `part`/`part of`, not imports: _FirebaseSection and _BackupSection are
library-private, so a sibling file cannot import them at all — extracting them
as ordinary files would not compile.

Two shapes tried and rejected on the way: an `extension _BackupActions` on the
State (an extension cannot call the protected setState), and moving build()
out of the class (it is an @override and has to stay). Both reverted from HEAD
rather than patched around.

flutter analyze clean, 29 tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFSGeWxHPY5rHUGrPqhcmG
2026-08-22 15:38:58 +02:00

133 lines
3.8 KiB
Dart

part of 'sync_settings_screen.dart';
/// The two sections the screen composes.
///
/// Split from sync_settings_screen.dart for the 250-line cap;
/// a `part` rather than an import because both sections are
/// library-private and could not be imported at all.
class _FirebaseSection extends StatelessWidget {
const _FirebaseSection({
required this.connected,
required this.busy,
required this.googleAvailable,
required this.emailController,
required this.passwordController,
required this.onConnectPassword,
required this.onConnectGoogle,
required this.onDisconnect,
});
final bool connected;
final bool busy;
final bool googleAvailable;
final TextEditingController emailController;
final TextEditingController passwordController;
final VoidCallback onConnectPassword;
final VoidCallback onConnectGoogle;
final VoidCallback onDisconnect;
@override
Widget build(BuildContext context) {
if (connected) {
return Row(
children: [
const Icon(Icons.cloud_done, size: 20),
const SizedBox(width: 8),
Expanded(child: Text(emailController.text)),
TextButton(
onPressed: busy ? null : onDisconnect,
child: const Text('Disconnect'),
),
],
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (googleAvailable) ...[
Align(
alignment: Alignment.centerLeft,
child: FilledButton.icon(
onPressed: busy ? null : onConnectGoogle,
icon: const Icon(Icons.account_circle),
label: const Text('Sign in with Google'),
),
),
const SizedBox(height: 12),
],
ExpansionTile(
initiallyExpanded: !googleAvailable,
title: const Text('Use the account password instead'),
tilePadding: EdgeInsets.zero,
childrenPadding: const EdgeInsets.only(bottom: 8),
children: [
TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
autocorrect: false,
decoration: const InputDecoration(
labelText: 'Sync account email',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
TextField(
controller: passwordController,
obscureText: true,
autocorrect: false,
decoration: const InputDecoration(
labelText: 'Sync account password',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
Align(
alignment: Alignment.centerLeft,
child: FilledButton.icon(
onPressed: busy ? null : onConnectPassword,
icon: const Icon(Icons.cloud_done),
label: const Text('Connect Firebase'),
),
),
],
),
],
);
}
}
class _BackupSection extends StatelessWidget {
const _BackupSection({
required this.backup,
required this.onExport,
required this.onImport,
});
final BackupSlot backup;
final VoidCallback onExport;
final VoidCallback onImport;
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: OutlinedButton.icon(
onPressed: onExport,
icon: const Icon(Icons.upload),
label: Text('Export ${backup.label}'),
),
),
const SizedBox(width: 12),
Expanded(
child: OutlinedButton.icon(
onPressed: onImport,
icon: const Icon(Icons.download),
label: Text('Import ${backup.label}'),
),
),
],
);
}
}