fix: server page empty by default, https prefix non-editable, StateProvider for instant redirect

This commit is contained in:
Bernd Steckmeister
2026-04-19 20:22:30 +02:00
parent 0f6dda7bb9
commit 85cf7cdf13
5 changed files with 50 additions and 53 deletions
+30 -36
View File
@@ -12,18 +12,18 @@ class ServerPage extends ConsumerStatefulWidget {
class _ServerPageState extends ConsumerState<ServerPage> {
final _formKey = GlobalKey<FormState>();
final _ctrl = TextEditingController(text: 'matrix.org');
final _ctrl = TextEditingController();
bool _loading = false;
String? _error;
@override
void initState() {
super.initState();
ref.read(homeserverProvider.future).then((saved) {
if (saved != null && mounted) {
_ctrl.text = saved.replaceAll(RegExp(r'^https?://'), '');
}
});
// Gespeicherten Server vorausfüllen (falls vorhanden)
final saved = ref.read(homeserverProvider);
if (saved != null) {
_ctrl.text = saved.replaceAll(RegExp(r'^https?://'), '');
}
}
@override
@@ -38,7 +38,7 @@ class _ServerPageState extends ConsumerState<ServerPage> {
final input = _ctrl.text.trim().replaceAll(RegExp(r'^https?://'), '');
try {
await saveHomeserver(input);
await saveHomeserver(ref, input);
if (mounted) context.go('/login');
} catch (e) {
setState(() => _error = e.toString());
@@ -63,11 +63,8 @@ class _ServerPageState extends ConsumerState<ServerPage> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Icon(
Icons.change_history_rounded,
size: 72,
color: theme.colorScheme.primary,
),
Icon(Icons.change_history_rounded,
size: 72, color: theme.colorScheme.primary),
const SizedBox(height: 8),
Text(
'Pyramid',
@@ -76,45 +73,42 @@ class _ServerPageState extends ConsumerState<ServerPage> {
?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 32),
Text(
'Server',
style: theme.textTheme.titleMedium,
),
Text('Server', style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
TextFormField(
controller: _ctrl,
decoration: const InputDecoration(
hintText: 'matrix.org',
prefixText: 'https://',
prefixIcon: Icon(Icons.dns_outlined),
border: OutlineInputBorder(),
autofocus: true,
decoration: InputDecoration(
hintText: 'dein-server.de',
prefixIcon: const Icon(Icons.dns_outlined),
border: const OutlineInputBorder(),
// https:// als nicht-editierbares Prefix
prefix: Text(
'https://',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
),
keyboardType: TextInputType.url,
validator: (v) {
if (v == null || v.trim().isEmpty) {
return 'Server-Adresse eingeben';
}
return null;
},
validator: (v) => (v == null || v.trim().isEmpty)
? 'Server-Adresse eingeben'
: null,
onFieldSubmitted: (_) => _continue(),
),
if (_error != null) ...[
const SizedBox(height: 12),
Text(
_error!,
style: TextStyle(color: theme.colorScheme.error),
textAlign: TextAlign.center,
),
Text(_error!,
style: TextStyle(color: theme.colorScheme.error),
textAlign: TextAlign.center),
],
const SizedBox(height: 24),
FilledButton(
onPressed: _loading ? null : _continue,
child: _loading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
height: 20, width: 20,
child: CircularProgressIndicator(strokeWidth: 2))
: const Text('Weiter'),
),
],