halkyon/halkyon_learn_flutter/lib/screens/sign_in_screen.dart
Tizian 「ティツィアーン」 e17d99fa51
chore: scaffold the Serverpod 4 build
Deviations from a stock `serverpod create`:
- Dropped Flutter web support, for two reasons:
  - Appflowy editor had issues in the past, potentially related to the
    Flutter-Web IME bridge. Upstream has also open bugs in relation to
that:
    - AppFlowy-IO/appflowy-editor#1029 [Bug][Web] Unwanted space on click
       and overall space bugs (open)
    - AppFlowy-IO/appflowy-editor#782 [Bug] Editor auto-scrolling when
       pressing space too quickly if placed inside a scrollable (open)
  - Offline-first is a required feature. serverpod_offline_sync's SQLite
    support in browsers, maybe via sqlite3.wasm + OPFS, is not
documented.
- SDK constraints raised to ^3.13.0, instead of ^3.12.2, so enjoy the
  newest language features.
- Pinned to Flutter 3.47.4 via FVM.

Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-09-24 15:32:29 +02:00

78 lines
2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:serverpod_auth_idp_flutter/serverpod_auth_idp_flutter.dart';
import '../client.dart';
class SignInScreen extends StatefulWidget {
final Widget child;
const SignInScreen({super.key, required this.child});
@override
State<SignInScreen> createState() => _SignInScreenState();
}
class _SignInScreenState extends State<SignInScreen> {
bool _isSignedIn = false;
@override
void initState() {
super.initState();
client.auth.authInfoListenable.addListener(_updateSignedInState);
_isSignedIn = client.auth.isAuthenticated;
}
@override
void dispose() {
client.auth.authInfoListenable.removeListener(_updateSignedInState);
super.dispose();
}
void _updateSignedInState() {
setState(() {
_isSignedIn = client.auth.isAuthenticated;
});
}
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return _isSignedIn
? widget.child
: Center(
child: SignInWidget(
client: client,
onAuthenticated: () {
context.showSnackBar(
message: 'User authenticated.',
backgroundColor: colors.primaryContainer,
foregroundColor: colors.onPrimaryContainer,
);
},
onError: (error) {
context.showSnackBar(
message: 'Authentication failed: $error',
backgroundColor: colors.errorContainer,
foregroundColor: colors.onErrorContainer,
);
},
),
);
}
}
extension on BuildContext {
void showSnackBar({
required String message,
required Color backgroundColor,
required Color foregroundColor,
}) {
ScaffoldMessenger.of(this).showSnackBar(
SnackBar(
content: Text(message, style: TextStyle(color: foregroundColor)),
backgroundColor: backgroundColor,
duration: const Duration(seconds: 5),
),
);
}
}