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.
cloudsolutions-atoms/lib/modules/signup/providers/group_provider.dart

45 lines
1.2 KiB
Dart

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/modules/signup/models/group_model.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';
class AssetGroupProvider extends LoadingListNotifier<AssetGroup> {
@override
Future getData({int? id}) async {
if (loading) return -2;
loading = true;
notifyListeners();
try {
// Use direct HTTP call without authentication token
final headers = {
'Content-Type': 'application/json',
'X-Timezone-Offset': DateTime.now().timeZoneOffset.toString().split(".").first,
};
final response = await http.get(
Uri.parse(URLs.signUpGetAssetGroups),
headers: headers,
);
stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) {
List categoriesListJson = json.decode(response.body)["data"];
items = categoriesListJson.map((item) => AssetGroup.fromJson(item)).toList();
}
loading = false;
notifyListeners();
return response.statusCode;
} catch (error) {
loading = false;
stateCode = -1;
notifyListeners();
return -1;
}
}
}