changes on login process
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:pcastlivetv/globals.dart';
|
||||
|
||||
import '../models/login_model.dart';
|
||||
|
||||
class AuthService {
|
||||
Future<LoginModel> login(String email, String password) async {
|
||||
final dio = Dio();
|
||||
try {
|
||||
final data = {
|
||||
"email": email,
|
||||
"password": password,
|
||||
};
|
||||
|
||||
final response = await dio.post(
|
||||
Endpoints.login,
|
||||
options: Options(
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
),
|
||||
data: jsonEncode(data),
|
||||
);
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
print(jsonDecode(response.data));
|
||||
var authModel = LoginModel.fromJson(jsonDecode(response.data));
|
||||
return authModel;
|
||||
default:
|
||||
throw Exception('Erro inesperado no login: ${response.statusCode} - ${response.data.toString()}');
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
throw Exception('Exception inesperada no login: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../globals.dart';
|
||||
|
||||
class SnackBarService {
|
||||
static void showSnackBar({required String content, bool error = false}) {
|
||||
snackbarKey.currentState?.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
content,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
backgroundColor: error ? Colors.red : Colors.green,
|
||||
duration: const Duration(seconds: 3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
elevation: 8.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user