network_cache_interceptor 1.1.1 copy "network_cache_interceptor: ^1.1.1" to clipboard
network_cache_interceptor: ^1.1.1 copied to clipboard

NetworkCacheInterceptor is a custom interceptor designed to optimize network requests by integrating caching functionality into your application using the Dio library.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  final Dio dio = Dio()..interceptors.add(NetworkCacheInterceptor());

  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Network Cache Example'),
        ),
        body: Center(
          child: FutureBuilder(
            future: fetchData(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const CircularProgressIndicator();
              } else if (snapshot.hasError) {
                return Text('Error: ${snapshot.error}');
              } else {
                return Text('Data: ${snapshot.data}');
              }
            },
          ),
        ),
      ),
    );
  }

  Future<String> fetchData() async {
    try {
      final response = await dio.get(
        'https://jsonplaceholder.typicode.com/posts/1',
        options: Options(
          extra: {
            'cache': true,
            'validate_time': 60, // Cache validity in minutes
          },
        ),
      );
      return response.data.toString();
    } catch (e) {
      return 'Failed to fetch data';
    }
  }
}
8
likes
0
points
396
downloads

Publisher

unverified uploader

Weekly Downloads

NetworkCacheInterceptor is a custom interceptor designed to optimize network requests by integrating caching functionality into your application using the Dio library.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter, path, sqflite

More

Packages that depend on network_cache_interceptor