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.
		
		
		
		
		
			
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
| import 'dart:convert';
 | |
| 
 | |
| import 'package:flutter/foundation.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 'traf_request_model.dart';
 | |
| 
 | |
| class TrafRequestProvider extends ChangeNotifier {
 | |
|   bool isLoading = false;
 | |
| 
 | |
|   TrafRequestDataModel? trafRequestDataModel;
 | |
| 
 | |
|   Future<int> addTraf(Map<String, dynamic> body) async {
 | |
|     try {
 | |
|       isLoading = true;
 | |
|       notifyListeners();
 | |
|       Response response = await ApiManager.instance.post(URLs.addTRAF, body: body);
 | |
|       if (response.statusCode >= 200 && response.statusCode < 300) {
 | |
|         // trafRequestDataModel = TrafRequestDataModel.fromJson(json.decode(response.body)["data"]);
 | |
|       }
 | |
|       isLoading = false;
 | |
|       notifyListeners();
 | |
|       return 0;
 | |
|     } catch (error) {
 | |
|       isLoading = false;
 | |
|       notifyListeners();
 | |
|       return -1;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   Future<int> getTRAFById(int trafId) async {
 | |
|     try {
 | |
|       isLoading = true;
 | |
|       notifyListeners();
 | |
|       Response response = await ApiManager.instance.get("${URLs.getTRAFById}?tRAFId=$trafId");
 | |
|       if (response.statusCode >= 200 && response.statusCode < 300) {
 | |
|         trafRequestDataModel = TrafRequestDataModel.fromJson(json.decode(response.body)["data"]);
 | |
|       }
 | |
|       isLoading = false;
 | |
|       notifyListeners();
 | |
|       return 0;
 | |
|     } catch (error) {
 | |
|       isLoading = false;
 | |
|       notifyListeners();
 | |
|       return -1;
 | |
|     }
 | |
|   }
 | |
| }
 |