sign in with pocketbase working
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/// Signed-in account details and sign-out.
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../providers/auth_provider.dart';
|
||||
import '../utils/constants.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
|
||||
class AccountScreen extends StatelessWidget {
|
||||
const AccountScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = context.watch<AuthController>();
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Account')),
|
||||
body: ResponsiveBody(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 32),
|
||||
children: [
|
||||
Center(
|
||||
child: CircleAvatar(
|
||||
radius: 36,
|
||||
backgroundColor: colors.primaryContainer,
|
||||
child: Text(
|
||||
auth.initials,
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
color: colors.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
auth.displayName,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.headlineSmall,
|
||||
),
|
||||
if (auth.email case final email?)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
email,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.cloud_outlined),
|
||||
title: const Text('PocketBase server'),
|
||||
subtitle: Text(kPocketBaseUrl),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.phone_android_outlined),
|
||||
title: const Text('Local data'),
|
||||
subtitle: const Text(
|
||||
'Labels, notes, and bank cache remain on this device.',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
await auth.logout();
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Sign out'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/// Email/password sign-in against PocketBase.
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../providers/auth_provider.dart';
|
||||
import '../utils/constants.dart';
|
||||
import '../widgets/app_text_field.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _busy = false;
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (_busy) return;
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
|
||||
setState(() => _busy = true);
|
||||
final auth = context.read<AuthController>();
|
||||
try {
|
||||
await auth.login(
|
||||
email: _emailController.text,
|
||||
password: _passwordController.text,
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop(true);
|
||||
} on ClientException catch (error) {
|
||||
if (!mounted) return;
|
||||
final message = error.response['message'] as String? ??
|
||||
'Sign-in failed. Check email and password.';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message)),
|
||||
);
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Could not reach $kPocketBaseUrl')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Sign in')),
|
||||
body: ResponsiveBody(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 32),
|
||||
children: [
|
||||
Text(
|
||||
'Sync account',
|
||||
style: theme.textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Sign in to link this device with PocketBase. Your labels, '
|
||||
'notes, and bank cache stay on this phone until sync is added.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
AppTextField(
|
||||
controller: _emailController,
|
||||
label: 'Email',
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
autofocus: true,
|
||||
validator: (value) {
|
||||
final text = value?.trim() ?? '';
|
||||
if (text.isEmpty) return 'Enter your email';
|
||||
if (!text.contains('@')) return 'Enter a valid email';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
suffixIcon: IconButton(
|
||||
tooltip: _obscurePassword
|
||||
? 'Show password'
|
||||
: 'Hide password',
|
||||
onPressed: () => setState(
|
||||
() => _obscurePassword = !_obscurePassword,
|
||||
),
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
onPressed: _busy ? null : _submit,
|
||||
icon: _busy
|
||||
? SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.login),
|
||||
label: Text(_busy ? 'Signing in…' : 'Sign in'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class _OverviewScreenState extends State<OverviewScreen> {
|
||||
Map<DateTime, Map<String, double>> labelAmountByPeriod = const {};
|
||||
|
||||
if (_metric == _MetricMode.flow) {
|
||||
monthly = _flowTotals(txs, periods, _period);
|
||||
monthly = _flowTotals(txs, meta, periods, _period);
|
||||
} else {
|
||||
final labels = _labelAggregates(
|
||||
txs,
|
||||
@@ -478,6 +478,7 @@ String _periodAxisLabel(DateTime period, _PeriodMode mode) {
|
||||
|
||||
Map<DateTime, _MonthBucket> _flowTotals(
|
||||
List<BankTransaction> txs,
|
||||
TxMetaController meta,
|
||||
List<DateTime> periods,
|
||||
_PeriodMode mode,
|
||||
) {
|
||||
@@ -486,6 +487,7 @@ Map<DateTime, _MonthBucket> _flowTotals(
|
||||
for (final key in keys) key: (income: 0.0, expense: 0.0),
|
||||
};
|
||||
for (final tx in txs) {
|
||||
if (meta.metaFor(tx).internalTransfer) continue;
|
||||
final date = _txDate(tx);
|
||||
if (date == null) continue;
|
||||
final key = _periodKey(date, mode);
|
||||
@@ -545,6 +547,7 @@ _LabelAggregates _labelAggregates(
|
||||
final filtering = includedLabelIds.isNotEmpty;
|
||||
|
||||
for (final tx in txs) {
|
||||
if (meta.metaFor(tx).internalTransfer) continue;
|
||||
if (!txMatchesFlow(tx, flow)) continue;
|
||||
final date = _txDate(tx);
|
||||
if (date == null) continue;
|
||||
|
||||
@@ -397,6 +397,22 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
context.read<TxMetaController>().setRecurring(tx, value);
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
secondary: const Icon(Icons.swap_horiz),
|
||||
title: const Text('Internal transfer'),
|
||||
subtitle: const Text(
|
||||
'Between your own accounts — excluded from income/expense',
|
||||
),
|
||||
value: meta.internalTransfer,
|
||||
onChanged: _busy
|
||||
? null
|
||||
: (value) {
|
||||
context
|
||||
.read<TxMetaController>()
|
||||
.setInternalTransfer(tx, value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
|
||||
@@ -354,6 +354,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
var moneyOut = 0.0;
|
||||
var moneyIn = 0.0;
|
||||
for (final tx in filtered) {
|
||||
if (metaController.metaFor(tx).internalTransfer) continue;
|
||||
if (tx.amount < 0) {
|
||||
moneyOut += tx.amount.abs();
|
||||
} else if (tx.amount > 0) {
|
||||
@@ -952,6 +953,7 @@ class _CompactTransactionTile extends StatelessWidget {
|
||||
if (labels.isNotEmpty)
|
||||
labels.map((l) => l.name).join(', '),
|
||||
if (meta.recurring) 'Recurring',
|
||||
if (meta.internalTransfer) 'Transfer',
|
||||
if (meta.hasNotes) 'Note',
|
||||
if (tx.pending) 'Pending',
|
||||
].join(' · '),
|
||||
|
||||
Reference in New Issue
Block a user