पेज·मुफ़्त
साइन-इन स्क्रीन (Flutter)
Flutter के लिए Material 3 साइन-इन स्क्रीन: ईमेल और पासवर्ड की जाँच, दिखाएँ/छिपाएँ बटन, ऑटोफ़िल और साइन इन होते समय स्पिनर। यह रंग आपके ऐप की थीम से लेती है और इसे सिर्फ़ Flutter SDK चाहिए।
मुफ़्त में इंस्टॉल करें।
अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।
प्रीव्यू
login_screen.dart · 190 लाइनें
// Sign-in screen for Flutter with Material 3, using only the Flutter SDK.
//
// Email and password with checks, a show/hide button for the password, autofill from the
// password manager, a spinner while it signs in and a message if it fails. It takes its
// colours from your app's Theme, so it follows light and dark mode.
//
// LoginScreen(
// onSignIn: (email, password) => auth.signIn(email, password),
// onForgotPassword: () => Navigator.pushNamed(context, '/reset'),
// onCreateAccount: () => Navigator.pushNamed(context, '/signup'),
// )
//
// onSignIn should throw if the sign-in fails; the screen then shows a message and stays.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({
super.key,
required this.onSignIn,
this.onForgotPassword,
this.onCreateAccount,
});
/// Called with the trimmed email and the password once both pass the checks.
final Future<void> Function(String email, String password) onSignIn;
/// Shows a "Forgot password?" link when set.
final VoidCallback? onForgotPassword;
/// Shows "No account yet? Create one" when set.
final VoidCallback? onCreateAccount;
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
static final _emailPattern = RegExp(r'^[^\s@]+@[^\s@]+\.[^\s@]+$');
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
final _password = TextEditingController();
final _passwordFocus = FocusNode();
bool _obscure = true;
bool _busy = false;
String? _error;
@override
void dispose() {
_email.dispose();
_password.dispose();
_passwordFocus.dispose();
super.dispose();
}
Future<void> _submit() async {
if (_busy) return;
setState(() => _error = null);
if (!(_formKey.currentState?.validate() ?? false)) return;
setState(() => _busy = true);
try {
await widget.onSignIn(_email.text.trim(), _password.text);
// Lets the password manager offer to save what was typed.
TextInput.finishAutofillContext();
} catch (_) {
if (mounted) {
setState(() => _error = 'Could not sign in. Check your email and password and try again.');
}
} finally {
if (mounted) setState(() => _busy = false);
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final muted = theme.textTheme.bodyMedium?.copyWith(color: theme.colorScheme.onSurfaceVariant);
यह प्रीव्यू छोटा किया गया है। पूरा कंटेंट इंस्टॉल करने पर मिलेगा।
1.0.0 में बदलाव
पहला संस्करण।