You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
|
2 years ago
|
import 'dart:convert';
|
||
|
|
import 'dart:developer';
|
||
|
|
|
||
|
10 months ago
|
import 'package:flutter/foundation.dart';
|
||
|
|
|
||
|
|
import 'package:http/http.dart';
|
||
|
|
|
||
|
10 months ago
|
import 'package:fluffychat/pangea/common/config/environment.dart';
|
||
|
|
import 'package:fluffychat/pangea/common/network/urls.dart';
|
||
|
|
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||
|
|
import 'package:fluffychat/pangea/learning_settings/models/language_model.dart';
|
||
|
|
import '../../common/network/requests.dart';
|
||
|
2 years ago
|
|
||
|
|
class LanguageRepo {
|
||
|
|
static Future<List<LanguageModel>> fetchLanguages() async {
|
||
|
1 year ago
|
final Requests req = Requests(
|
||
|
|
choreoApiKey: Environment.choreoApiKey,
|
||
|
|
);
|
||
|
2 years ago
|
final Response res = await req.get(url: PApiUrls.getLanguages);
|
||
|
|
|
||
|
|
final decodedBody =
|
||
|
|
jsonDecode(utf8.decode(res.bodyBytes).toString()) as List;
|
||
|
|
final List<LanguageModel> langFlag = decodedBody.map((e) {
|
||
|
|
try {
|
||
|
|
return LanguageModel.fromJson(e);
|
||
|
|
} catch (err, stack) {
|
||
|
|
debugger(when: kDebugMode);
|
||
|
|
ErrorHandler.logError(e: err, s: stack, data: e);
|
||
|
|
return LanguageModel.unknown;
|
||
|
|
}
|
||
|
|
}).toList();
|
||
|
|
return langFlag;
|
||
|
|
}
|
||
|
|
}
|