dio_http_cache 0.0.1 copy "dio_http_cache: ^0.0.1" to clipboard
dio_http_cache: ^0.0.1 copied to clipboard

outdated

http cache lib for Flutter dio like RxCache.

example/lib/main.dart

import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:dio_http_cache/dio_http_cache.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _content = "Hello";
  var _url = "https://5d241383e39785001406ead9.mockapi.io/user";
  static DioCacheManager _manager = DioCacheManager(CacheConfig());
  var _dio = Dio()..interceptors.add(_manager.interceptor);

  void _doPost() {
    _dio.post(_url, options: buildCacheOptions(Duration(hours: 1), subKey: "id=1")).then((response) {
      setState(() {
        _content = jsonEncode(response.data);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Text(
            '$_content',
            style: Theme.of(context).textTheme.display1,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _doPost,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
241
likes
0
pub points
96%
popularity

Publisher

unverified uploader

http cache lib for Flutter dio like RxCache.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, dio, flutter, json_annotation, json_serializable, path, quiver, sqflite

More

Packages that depend on dio_http_cache