how to add http caching using "dio_http_cache" package to flutter

Viewed 99

I have a code that I use to download data, through a query (get) and display it. But I want to change something, I want to cache the data and display it. So that if the device was offline, I could display the latest data. Someone is already doing this, I will be grateful for your help)

import 'package:dio/dio.dart';
import 'package:dio_http_cache/dio_http_cache.dart';
import 'package:test_axles/models/seals_model.dart';
import 'package:test_axles/setting_var/globalvar.dart' as global;

class ApiProvider {

  final Dio _dio = Dio();
  final String _url = global.urlVar;
  Future<Objects> fetchSealsList() async {
    try {
      Response response = await _dio.get(_url);
      return Objects.fromJson(response.data);
    } catch (error, stacktrace) {
      return Objects.withError(" ");
    }
  }
}

0 Answers
Related