simple_app_cache_manager 0.0.4 copy "simple_app_cache_manager: ^0.0.4" to clipboard
simple_app_cache_manager: ^0.0.4 copied to clipboard

Flutter Package for Managing Application Cache

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:simple_app_cache_manager/simple_app_cache_manager.dart';

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

class Example extends StatefulWidget {
  const Example({super.key});

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> with CacheMixin {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ValueListenableBuilder(
                valueListenable: cacheSizeNotifier,
                builder: (context, cacheSize, child) => Text(cacheSize),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text('clear'),
                onPressed: () {
                  cacheManager.clearCache();
                  updateCacheSize();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

mixin CacheMixin on State<Example> {
  late final SimpleAppCacheManager cacheManager;
  late ValueNotifier<String> cacheSizeNotifier = ValueNotifier<String>('');

  @override
  void initState() {
    super.initState();
    cacheManager = SimpleAppCacheManager();
    updateCacheSize();
  }

  void updateCacheSize() async {
    final cacheSize = await cacheManager.getTotalCacheSize();
    cacheSizeNotifier.value = cacheSize;
  }
}
7
likes
140
pub points
83%
popularity

Publisher

unverified uploader

Flutter Package for Managing Application Cache

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, path_provider, plugin_platform_interface

More

Packages that depend on simple_app_cache_manager