initial version

This commit is contained in:
2023-08-23 10:11:10 -03:00
commit 304f895d25
23 changed files with 970 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:pcasttv/globals.dart';
import 'package:pcasttv/models/login_model.dart';
class AuthService {
Future<LoginModel> login(String email, String password) async {
http.Response response;
final data = {
"email": email,
"password": password,
};
try {
response = await http.post(
Uri.parse(Endpoints.login),
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json',
},
body: jsonEncode(data),
);
switch (response.statusCode) {
case 200:
var authModel = LoginModel.fromJson(utf8.decode(response.bodyBytes).toString());
return authModel;
default:
throw Exception('Erro inesperado no login: ${response.statusCode} - ${response.body.toString()}');
}
} on Exception catch (e) {
throw Exception('Exception inesperada no login: $e');
}
}
}
+26
View File
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:pcasttv/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,
),
);
}
}