39 lines
1013 B
Dart
39 lines
1013 B
Dart
// ignore_for_file: unnecessary_brace_in_string_interps
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:server/apis/auth.dart';
|
|
import 'package:server/client.dart';
|
|
|
|
class Shop {
|
|
String lastError = '';
|
|
getCatalog() async {
|
|
String token = '';
|
|
try {
|
|
final loginResponse = await auth.login(
|
|
'example123123333333@mail.ru',
|
|
'string213123',
|
|
);
|
|
if (loginResponse != null) {
|
|
token = loginResponse['token'];
|
|
api.options.headers['Authorization'] = "Bearer ${token}";
|
|
}
|
|
final response = await api.get('collections/products/records');
|
|
if (response.data != null) {
|
|
return response.data;
|
|
} else {
|
|
return Error();
|
|
}
|
|
} on DioException catch (e) {
|
|
if (e.type == DioExceptionType.connectionError) {
|
|
lastError = 'Internet Connection errror';
|
|
}
|
|
lastError = e.response!.data['message'];
|
|
} catch (e) {
|
|
print('empty error');
|
|
return 'empty errror';
|
|
}
|
|
}
|
|
}
|
|
|
|
final shop = Shop();
|