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.
		
		
		
		
		
			
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
import 'dart:convert';
 | 
						|
 | 
						|
import 'package:flutter/cupertino.dart';
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
import 'package:http/http.dart';
 | 
						|
import 'package:test_sa/api/hospitals_api_client.dart';
 | 
						|
import 'package:test_sa/controllers/providers/loading_notifier.dart';
 | 
						|
 | 
						|
import '../../../models/hospital.dart';
 | 
						|
import '../../../models/user.dart';
 | 
						|
import '../../api_routes/urls.dart';
 | 
						|
 | 
						|
class HospitalsProvider extends LoadingNotifier {
 | 
						|
  // number of items call in each request
 | 
						|
  final pageItemNumber = 50;
 | 
						|
 | 
						|
  //reset provider data
 | 
						|
  void reset() {
 | 
						|
    _hospitals.clear();
 | 
						|
    _stateCode = null;
 | 
						|
  }
 | 
						|
 | 
						|
  int? _stateCode;
 | 
						|
 | 
						|
  int? get stateCode => _stateCode;
 | 
						|
 | 
						|
 | 
						|
  // contain user data
 | 
						|
  // when user not login or register _user = null
 | 
						|
  List<Hospital> _hospitals=[];
 | 
						|
 | 
						|
  List<Hospital> get hospitals => _hospitals;
 | 
						|
 | 
						|
 | 
						|
  Future getHospitals({
 | 
						|
    required String? title,
 | 
						|
  }) async {
 | 
						|
    waitApiRequest(() async {
 | 
						|
         _hospitals = [];
 | 
						|
        _hospitals.addAll(await HospitalsApiClient().getHospitals(title: title ?? "", pageSize: _hospitals.length ~/ pageItemNumber));
 | 
						|
        notifyListeners();
 | 
						|
    },
 | 
						|
    onSuccess: (){
 | 
						|
      _stateCode = 200;
 | 
						|
    }
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  Future<List<Hospital>> getHospitalsList({
 | 
						|
    required String title,
 | 
						|
  }) async {
 | 
						|
    waitApiRequest((){
 | 
						|
      return HospitalsApiClient().getHospitalsList(title: title);
 | 
						|
    },
 | 
						|
    onSuccess: (){
 | 
						|
      _stateCode=200;
 | 
						|
    }
 | 
						|
    );
 | 
						|
    return [];
 | 
						|
  }
 | 
						|
}
 |