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.
42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart';
|
|
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
import 'package:test_sa/models/fault_description.dart';
|
|
import 'package:test_sa/models/service_request/spare_parts.dart';
|
|
|
|
class FaultDescriptionProvider extends ChangeNotifier {
|
|
|
|
int? _stateCode;
|
|
|
|
int? get stateCode => _stateCode;
|
|
|
|
bool _loading = false;
|
|
|
|
bool get isLoading => _loading;
|
|
|
|
set isLoading(bool isLoading) {
|
|
_loading = isLoading;
|
|
notifyListeners();
|
|
}
|
|
Future<List<FaultDescription>> getFaultDescriptionList({num? assetId}) async {
|
|
late Response response;
|
|
try {
|
|
response = await ApiManager.instance.get(URLs.getFaultDescription+"?assetId=$assetId",);
|
|
List<FaultDescription> list = [];
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
// client's request was successfully received
|
|
List faultListJson = json.decode(response.body)["data"];
|
|
|
|
list = faultListJson.map((fault) => FaultDescription.fromJson(fault)).toList();
|
|
}
|
|
return list;
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
}
|
|
}
|