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

Automated cache management with encryption, substitution/invalidation policies and efficient size handling.

example/lib/main.dart

import 'package:flutter_auto_cache/flutter_auto_cache.dart';

import 'package:flutter/material.dart';

import 'src/constants/cache_constants.dart';

Future<void> main() async {
  await AutoCacheInitializer.initialize();

  runApp(const AppWidget());
}

class AppWidget extends StatelessWidget {
  const AppWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(useMaterial3: true),
      debugShowCheckedModeBanner: false,
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final store = CounterStore();

  @override
  void initState() {
    super.initState();
    store.getCount();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Flutter Auto Cache')),
      body: Center(
        child: ValueListenableBuilder<int>(
          valueListenable: store,
          builder: (context, count, _) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              mainAxisSize: MainAxisSize.min,
              children: [
                IconButton(onPressed: store.decrement, icon: const Icon(Icons.remove)),
                Text(count.toString(), style: const TextStyle(fontSize: 24)),
                IconButton(onPressed: store.increment, icon: const Icon(Icons.add)),
              ],
            );
          },
        ),
      ),
    );
  }
}

class CounterStore extends ValueNotifier<int> {
  CounterStore() : super(0);

  Future<void> increment() => _updateCount(() => value += 1);

  Future<void> decrement() => _updateCount(() => value -= 1);

  Future<void> getCount() async {
    final response = await AutoCache.data.getInt(key: CacheConstants.countKey);
    value = response.data ?? 0;
  }

  Future<void> _updateCount(VoidCallback action) async {
    action.call();
    await AutoCache.data.saveInt(key: CacheConstants.countKey, data: value);
  }
}
53
likes
150
pub points
71%
popularity

Publisher

verified publisherluizgasparetto.dev

Automated cache management with encryption, substitution/invalidation policies and efficient size handling.

Homepage
Repository (GitHub)
View/report issues

Topics

#cache #cache-management #cryptography

Documentation

Documentation
API reference

License

BSD-3-Clause (license)

Dependencies

crypto, encrypt, flutter, meta, path_provider, shared_preferences

More

Packages that depend on flutter_auto_cache