flutter_login_widget/example/lib/main.dart
Bart Ribbers 907af2639d feat(EmailPasswordLoginForm): get title and subtitle from the widget rather than loginoptions
Previously the EmailPasswordLoginForm and the ForgotPasswordForm used
different ways to provide a title and subtitle/description. This is now
the same and the related fields are removed from LoginOptions
2024-05-24 13:08:27 +02:00

94 lines
2.2 KiB
Dart

// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:flutter_login/flutter_login.dart';
final loginOptions = LoginOptions(
emailDecoration: const InputDecoration(
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
passwordDecoration: const InputDecoration(
prefixIcon: Icon(Icons.password),
border: OutlineInputBorder(),
),
image: const FlutterLogo(
size: 200,
),
requestForgotPasswordButtonBuilder: (
context,
onPressed,
isDisabled,
onDisabledPress,
translations,
) {
return Opacity(
opacity: isDisabled ? 0.5 : 1.0,
child: ElevatedButton(
onPressed: isDisabled ? onDisabledPress : onPressed,
child: const Text('Send request'),
),
);
},
);
void main() {
runApp(const LoginExample());
}
class LoginExample extends StatelessWidget {
const LoginExample({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: const LoginScreen(),
);
}
}
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: EmailPasswordLoginForm(
title: const Text('Login Demo'),
options: loginOptions,
onLogin: (email, password) => print('$email:$password'),
onRegister: (email, password, ctx) => print('Register!'),
onForgotPassword: (email, ctx) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return const ForgotPasswordScreen();
},
),
);
},
),
);
}
}
class ForgotPasswordScreen extends StatelessWidget {
const ForgotPasswordScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ForgotPasswordForm(
options: loginOptions,
title: const Text('Forgot password'),
description: const Text('Hello world'),
onRequestForgotPassword: (email) {
print('Forgot password email sent to $email');
},
),
);
}
}