-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
function-pointers-in-flutter.dart
54 lines (49 loc) · 1.37 KB
/
function-pointers-in-flutter.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 🐦 Twitter https://twitter.com/vandadnp
// 🔵 LinkedIn https://linkedin.com/in/vandadnp
// 🎥 YouTube https://youtube.com/c/vandadnp
// 💙 Free Flutter Course https://linktr.ee/vandadnp
// 📦 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY
// 🤝 Want to support my work? https://buymeacoffee.com/vandad
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
typedef LoginOrRegisterFunction = Future<UserCredential> Function({
required String email,
required String password,
});
Future<bool> _registerOrLogin({
required LoginOrRegisterFunction fn,
required String email,
required String password,
}) async {
try {
await fn(
email: email,
password: password,
);
// do some processing
return true;
} catch (e) {
// handle the error here
return false;
} finally {
// perform cleanup
}
}
Future<bool> register({
required String email,
required String password,
}) =>
_registerOrLogin(
fn: FirebaseAuth.instance.createUserWithEmailAndPassword,
email: email,
password: password,
);
Future<bool> login({
required String email,
required String password,
}) =>
_registerOrLogin(
fn: FirebaseAuth.instance.signInWithEmailAndPassword,
email: email,
password: password,
);