50 lines
1.2 KiB
Dart
50 lines
1.2 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
|
|
enum Status {
|
|
NotLoggedIn,
|
|
NotRegistered,
|
|
LoggedIn,
|
|
Registered,
|
|
Authenticating,
|
|
Registering,
|
|
LoggedOut
|
|
}
|
|
|
|
class AuthProvider with ChangeNotifier {
|
|
Status _loggedInStatus = Status.NotLoggedIn;
|
|
Status _registeredInStatus = Status.NotRegistered;
|
|
|
|
Status get loggedInStatus => _loggedInStatus;
|
|
Status get registeredInStatus => _registeredInStatus;
|
|
|
|
Future<Map<String, dynamic>> login(String email, int pinCode) async {
|
|
var result;
|
|
|
|
final Map<String, dynamic> loginData = {
|
|
'user': {'email': email, 'pinCode': pinCode}
|
|
};
|
|
|
|
_loggedInStatus = Status.Authenticating;
|
|
notifyListeners();
|
|
Timer(Duration(seconds: 30), () {
|
|
_loggedInStatus = Status.LoggedIn;
|
|
notifyListeners();
|
|
result = {'status': true, 'message': 'Successful'};
|
|
return result;
|
|
});
|
|
}
|
|
|
|
Future<Map<String, dynamic>> register(
|
|
String email, String password, String passwordConfirmation) async {
|
|
final Map<String, dynamic> registrationData = {
|
|
'user': {
|
|
'email': email,
|
|
'password': password,
|
|
'password_confirmation': passwordConfirmation
|
|
}
|
|
};
|
|
return {'status': true, 'message': 'Successfully registered'};
|
|
}
|
|
}
|