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.
61 lines
1.5 KiB
Dart
61 lines
1.5 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/site_model.dart';
|
|
import 'package:test_sa/providers/loading_list_notifier.dart';
|
|
|
|
class SignupSiteProvider extends LoadingListNotifier<SiteModel> {
|
|
@override
|
|
Future getData({int? id}) async {
|
|
if (loading) return -2;
|
|
|
|
if (id == null) {
|
|
items = [];
|
|
notifyListeners();
|
|
return -1;
|
|
}
|
|
|
|
loading = true;
|
|
notifyListeners();
|
|
|
|
try {
|
|
final headers = {
|
|
'Content-Type': 'application/json',
|
|
'X-Timezone-Offset': DateTime.now().timeZoneOffset.toString().split(".").first,
|
|
};
|
|
|
|
final response = await http.get(
|
|
Uri.parse('${URLs.signUpGetSiteList}?assetGroupId=$id'),
|
|
headers: headers,
|
|
);
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
final data = json.decode(response.body);
|
|
if (data['data'] != null && data['data'] is List) {
|
|
items = (data['data'] as List)
|
|
.map((item) => SiteModel.fromJson(item))
|
|
.toList();
|
|
} else {
|
|
items = [];
|
|
}
|
|
} else {
|
|
items = [];
|
|
}
|
|
|
|
loading = false;
|
|
notifyListeners();
|
|
return response.statusCode;
|
|
} catch (error) {
|
|
loading = false;
|
|
stateCode = -1;
|
|
items = [];
|
|
notifyListeners();
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|