Skip to content

Commit dbd4ec2

Browse files
docs: update and expand examples
1 parent 8e13cc6 commit dbd4ec2

File tree

5 files changed

+88
-20
lines changed

5 files changed

+88
-20
lines changed

README.md

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<b>⚠️ Attention: This package is at an early stage. A lot of features are missing. Eventually this package will be "lit", but for now, use at your own risk.</b>
66

7-
Pre-lit Firebase authentication. It provides a set of convenient utilities and widgets to easily add Firebase auth to a Flutter app.
7+
Pre-lit Firebase authentication. It provides a set of convenient utilities and widgets to easily add Firebase authentication to a Flutter app.
88

99

1010
## Features
@@ -27,8 +27,8 @@ Pre-lit Firebase authentication. It provides a set of convenient utilities and w
2727
## Getting started
2828

2929
See the [example](example/) project to get up and running fast.
30-
31-
## Platform Configuration
30+
<details>
31+
<summary><h2>Platform Configuration</h2></summary>
3232

3333
### Android integration
3434

@@ -96,6 +96,7 @@ Below is an example of a Flutter Web `index.html` with Firebase Auth enabled:
9696
<!-- CONTINUE TO INITIALIZE FLUTTER WEB -->
9797
...
9898
```
99+
</details>
99100

100101
## Usage
101102
The two most important widgets are
@@ -130,16 +131,16 @@ class MyApp extends StatelessWidget {
130131

131132
### Standard Sign-in widget
132133
You can either create your own custom Sign-in widget, or make use of the standard built in one.
133-
To use the standard widget:
134-
134+
To use the standard sign-in form with no changes:
135135

136136
```dart
137137
LitAuth(
138-
config: AuthConfig.standard(),
138+
config: AuthConfig(),
139139
);
140140
```
141141

142142
This will use the default configuration and UI theming. See the section on decoration and theming for customization.
143+
143144
**NOTE**: This widget needs to be below a `Scaffold` widget.
144145

145146
### Handle auth state changes
@@ -165,7 +166,6 @@ You can provide optional callbacks in `LitAuth` to handle success and failure wh
165166

166167
```dart
167168
LitAuth(
168-
config: AuthConfig.standard(),
169169
onAuthFailure: (failure) {
170170
print('Auth failed.'); // show error message
171171
},
@@ -176,13 +176,12 @@ LitAuth(
176176
```
177177
**Note**: these handlers will not be called if `LitAuth` is already disposed.
178178

179-
For example, if you were to wrap this widget in `LitAuthState`, such as:
179+
For example, if you were to wrap this `LitAuth` in `LitAuthState`, such as:
180180
```dart
181181
LitAuthState(
182182
authenticated: () =>
183183
Text('Authenticated'), // Login widget, or sign in button
184184
unauthenticated: () => LitAuth(
185-
config: AuthConfig.standard(),
186185
onAuthFailure: (failure) {
187186
print('Auth failed.'); // show error message
188187
},
@@ -192,7 +191,7 @@ LitAuthState(
192191
),
193192
);
194193
```
195-
Then in this instance the `onAuthSuccess` handler may not be called. As the *`authenticated`* state will be triggered and `LitAuth` widget disposed. *Depending on the platform, behaviour may be different. For web it may take longer for `LitAuthState` to receive a new auth value and push changes. Thus resulting in `onAuthSuccess` being called.*
194+
Then in this instance the `onAuthSuccess` handler may not be called. As the `authenticated` state will be triggered and the `LitAuth` widget disposed.
196195

197196
### Sign out
198197
To sign out the current user, make use of the `signOut` extension method on `BuildContext`. For example:
@@ -221,17 +220,18 @@ For example, to override the standard email `InputDecoration` just provide a cus
221220

222221
```dart
223222
LitAuth(
224-
config: AuthConfig.standard(
225-
emailTextFormField: InputDecoration(labelText: 'My beautiful label'),
223+
config: AuthConfig(
224+
emailTextFormField: InputDecoration(labelText: 'My beautiful label'),
226225
)
227226
```
228227

229228
Or, to customize a button:
230229

231230
```dart
232231
LitAuth(
233-
config: AuthConfig.standard(
232+
config: AuthConfig(
234233
googleButton: ButtonConfig(
234+
type: ButtonType.raised(),
235235
themeData: ButtonThemeData(
236236
buttonColor: Colors.red,
237237
),
@@ -243,24 +243,76 @@ LitAuth(
243243
```
244244

245245
### Dialogs
246-
For now dialogs are rendered using the `flushbar` package to show dialog messages.
246+
For now dialog nessage are rendered using the `flushbar` package.
247247

248248
**todo**: provide additional theming/overrides for dialogs.
249249

250250
### Additional Customization
251251

252-
For further customization you can directly make use of the Lit Firebase components to build a completely custom Sign-in widget. Legos fitting together.
252+
For further customization you can directly make use of the Lit Firebase components to build a completely custom sign-in widget.
253253

254254
Instead of using the standard `AuthConfig`, set it to custom and provide your custom Sign-in widget:
255255
```dart
256-
LitAuth(
257-
config: AuthConfig.custom(
258-
signIn: CustomSignInWidget(),
259-
),
256+
LitAuth.custom(
257+
child: YourCustomSignInWidget(),
260258
);
261259
```
262260

263-
Tutorials and code samples will be added soon on how to create a custom Sign-in widget. For now, see the example project for more information.
261+
You can build any form you want, for example:
262+
263+
```dart
264+
class YourCustomSignInWidget extends StatelessWidget {
265+
const CustomSignInWidget({Key key}) : super(key: key);
266+
267+
@override
268+
Widget build(BuildContext context) {
269+
return Column(
270+
children: [
271+
Text('Welcome', style: Theme.of(context).textTheme.headline4),
272+
// You need to wrap the custom sign-in widgets with a SignIn form.
273+
// This is used to validate the email and password
274+
SignInForm(
275+
formChild: Column(
276+
children: [
277+
Padding(
278+
padding: const EdgeInsets.all(8.0),
279+
child: Text(
280+
'A custom form',
281+
style: Theme.of(context).textTheme.headline5,
282+
),
283+
),
284+
Padding(
285+
padding: const EdgeInsets.all(8.0),
286+
child: EmailTextFormField(
287+
decoration: InputDecoration(labelText: 'My Email Label'),
288+
),
289+
),
290+
Padding(
291+
padding: const EdgeInsets.all(8.0),
292+
child: PasswordTextFormField(
293+
decoration: InputDecoration(labelText: 'My Password Label'),
294+
),
295+
),
296+
RaisedButton(
297+
onPressed: () {
298+
context.signInWithEmailAndPassword();
299+
},
300+
child: Text('Sign In'),
301+
),
302+
FlatButton(
303+
onPressed: () {
304+
context.signInAnonymously();
305+
},
306+
child: Text('Anony Sign In'),
307+
),
308+
],
309+
),
310+
),
311+
],
312+
);
313+
}
314+
}
315+
```
264316

265317
## Planned features
266318

example/lib/main.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class SplashScreen extends StatelessWidget {
3333

3434
@override
3535
Widget build(BuildContext context) {
36+
// LitAuth.custom(
37+
// child: CustomSignInWidget(),
38+
// );
3639
return Scaffold(
3740
body: Center(
3841
child: SingleChildScrollView(
@@ -90,6 +93,8 @@ class CustomSignInWidget extends StatelessWidget {
9093
return Column(
9194
children: [
9295
Text('Welcome', style: Theme.of(context).textTheme.headline4),
96+
// You need to wrap the custom sign-in widgets with a SignIn form.
97+
// This is used to validate the email and password
9398
SignInForm(
9499
formChild: Column(
95100
children: [

lib/src/domain/auth/auth.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'auth_failure.dart';
55
part 'auth.freezed.dart';
66

77
@freezed
8+
9+
/// Union class for whether authentication was successful or whether it failed
810
abstract class Auth with _$Auth {
911
const factory Auth.success() = _AuthSucc;
1012
const factory Auth.failure(AuthFailure failure) = _AuthFail;

lib/src/domain/auth/auth_failure.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:freezed_annotation/freezed_annotation.dart';
33
part 'auth_failure.freezed.dart';
44

55
@freezed
6+
7+
/// AuthFailure union which holds the reason for failure
68
abstract class AuthFailure with _$AuthFailure {
79
const factory AuthFailure.cancelledByUser() = CancelledByUser;
810
const factory AuthFailure.serverError() = ServerError;

lib/src/domain/auth/auth_providers.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import 'package:freezed_annotation/freezed_annotation.dart';
33
part 'auth_providers.freezed.dart';
44

55
@freezed
6+
7+
/// State which authentication providers should be enabled.
8+
///
9+
/// [emailAndPassword] defaults to enabled. The rest are disabled by default.
10+
///
11+
/// You will receive an [AuthProviderNotEnabled] exception a you try to use
12+
/// an authentication provider that is not enabled here.
613
abstract class AuthProviders with _$AuthProviders {
714
const factory AuthProviders({
815
@Default(true) bool emailAndPassword,

0 commit comments

Comments
 (0)