⚑ Cache Manager A tidy utility to handle cache of your flutter app like a Boss.

Overview

⚑ Cache Manager

A tidy utility to handle cache of your flutter app like a Boss. It provides support for both iOS and Android platforms (offcourse).

πŸŽ– Installing

dependencies:
  cache_manager: ^
   

⚽ Awesome Features

🍧 Cache Utilities

🌟 CacheManagerUtils.conditionalCache({key, valueType, actionIfNull, actionIfNotNull})

  • Conditional builder based on the value of cache. actionIfNull & actionIfNotNull are dynamic arguments used for Navigation through views, Rendering UI, Debugging values etc. The valueType refers to the datatype of cache (StringValue, BoolValue, IntValue, DoubleValue)

🌟 CacheManagerUtils.cacheTextBuilder(textStyle, cacheKey})

  • TextBuilder for the cached value. cacheKey is the key used to address the cache. The builder will return 'Invalid cache' if no cache is missing. Use textStyle to style the value of the cache.

πŸ‘€ Read cache

🌟 ReadCache.getJson(key) : Get JSON stored as cache.

🌟 ReadCache.getString(key) : Get string stored as cache.

🌟 ReadCache.getBool(key) : Get boolean stored as cache.

🌟 ReadCache.getInt(key) : Get integer stored as cache.

🌟 ReadCache.getDouble(key) : Get double stored as cache.

πŸ–Š Write cache

🌟 WriteCache.setJson(key,value) : Set JSON as cache.

🌟 WriteCache.setString(key,value) : Set a string as cache.

🌟 WriteCache.setInt(key,value) : Set an integer as cache.

🌟 WriteCache.setBool(key,value) : Set a boolean as cache.

🌟 WriteCache.setDouble(key,value) : Set a double as cache.

🌟 WriteCache.setListString(key,value) : Set a List of string as cache.

❌ Delete cache

🌟 DeleteCache.deleteKey(key,[takeAction]) : Delete the cache and perform an action when cache is deleted(Optional).

Example : Login flow with caching userID

_SplashViewState(); } class _SplashViewState extends State { Future initiateCache() async { return CacheManagerUtils.conditionalCache( key: "cache", valueType: ValueType.StringValue, actionIfNull: () { Navigator.of(context).pushNamed(AppRoutes.LoginRoute); }, actionIfNotNull: () { Navigator.of(context).pushNamed(AppRoutes.HomeRoute); }); } @override void initState() { Timer(Duration(seconds: 1), initiateCache); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Text("demo app"), ), ); } } //Home view import 'package:cache_manager/core/cache_manager_utils.dart'; import 'package:cache_manager/core/delete_cache_service.dart'; import 'package:flutter/material.dart'; class HomeView extends StatefulWidget { @override _HomeViewState createState() => _HomeViewState(); } class _HomeViewState extends State { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: CacheManagerUtils.cacheTextBuilder( textStyle: TextStyle(color: Colors.white), cacheKey: "cache"), ), floatingActionButton: FloatingActionButton( onPressed: () { DeleteCache.deleteKey( "cache", Navigator.of(context).pushNamed(AppRoutes.LoginRoute)); }, ), ); } }">
//Attached function in a login view
Future<String?> login({
    required BuildContext context,
    required String email,
    required String password,
  }) async {
    try {
      var userId = await _authenticationService.login(
          context: context, email: email, password: password);
      await WriteCache.setString(key: "cache", value: userId!);
    } catch (e) {
      print(e); //Do something if error occurs
   }
 }
 
//Splash view
import 'dart:async';
import 'package:cache_manager/cache_manager.dart';
import 'package:flutter/material.dart';

class SplashView extends StatefulWidget {
  @override
  _SplashViewState createState() => _SplashViewState();
}

class _SplashViewState extends State<SplashView> {
  Future initiateCache() async {
    return CacheManagerUtils.conditionalCache(
        key: "cache",
        valueType: ValueType.StringValue,
        actionIfNull: () {
          Navigator.of(context).pushNamed(AppRoutes.LoginRoute);
        },
        actionIfNotNull: () {
          Navigator.of(context).pushNamed(AppRoutes.HomeRoute);
        });
  }

  @override
  void initState() {
    Timer(Duration(seconds: 1), initiateCache);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text("demo app"),
      ),
    );
  }
}

//Home view
import 'package:cache_manager/core/cache_manager_utils.dart';
import 'package:cache_manager/core/delete_cache_service.dart';
import 'package:flutter/material.dart';

class HomeView extends StatefulWidget {
  @override
  _HomeViewState createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: CacheManagerUtils.cacheTextBuilder(
            textStyle: TextStyle(color: Colors.white), cacheKey: "cache"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          DeleteCache.deleteKey(
              "cache", Navigator.of(context).pushNamed(AppRoutes.LoginRoute));
        },
      ),
    );
  }
}

❀ Loved the utility? Donate here.

πŸš€ Want to learn more about Flutter? Checkout this out!

πŸ’₯ DM me on Instagram for doubts Follow here

πŸ› Bugs/Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github and I'll look into it. Pull request are also welcome.

You might also like...

Screenshots - A command line utility and package for capturing screenshots for Flutter

Screenshots - A command line utility and package for capturing screenshots for Flutter

A screenshot image with overlaid status bar placed in a device frame. For an example of images generated with Screenshots on a live app in both stores

Nov 22, 2022

Scaff is a simple command-line utility for generating Dart and Flutter components from template files.

Introduction Scaffold Generator for Dart and Flutter. scaff is a simple command-line utility for generating Dart and Flutter components from template

Jul 17, 2022

πŸ“ It's a set of common utility strategies to work with responsive styles with Flutter and CSS in JS

πŸ“ It's a set of common utility strategies to work with responsive styles with Flutter and CSS in JS

@displaykit/responsive_styles You don't need to be worried just because you have to support multiple screens πŸ“Ί πŸ–₯ πŸ’» πŸ“± . It's a set of common utilit

Dec 16, 2022

A Dart package that constantly writes a string to an IOSink, simillarly to the UNIX yes utility.

yes A Dart package that constantly writes a string to an IOSink, simillarly to the UNIX yes utility. Usage // Write to stdout for 5 seconds. final con

Sep 22, 2022

A pure Dart utility library that checks for an internet connection by opening a socket to a list of specified addresses, each with individual port and timeout. Defaults are provided for convenience.

data_connection_checker A pure Dart utility library that checks for an internet connection by opening a socket to a list of specified addresses, each

Nov 29, 2022

Link-extractor - A Simple utility for extracting media urls from different websites

Link Extractor A Simple utility for extracting media urls from differennt social

Feb 5, 2022

Interactive command line interface Couchbase Lite REPL utility built with the Dart

Interactive command line interface Couchbase Lite REPL utility built with the Dart

Couchbase Lite Dart CLI Interactive command line interface Couchbase Lite REPL utility built with the Dart programming language. This code uses the cb

Jul 20, 2022

A Dart utility package for easy async task cancellation

Dart Cancellation Token. Inspired by CancellationToken in C#. A Dart utility package for easy async task cancellation.

Sep 6, 2022

A font loader to download, cache and load web fonts in flutter with support for Firebase Cloud Storage.

A font loader to download, cache and load web fonts in flutter with support for Firebase Cloud Storage.

Dynamic Cached Fonts A simple, easy to use yet customizable font loader to use web fonts. Demo: https://sidrao2006.github.io/dynamic_cached_fonts πŸ‘‹ I

Dec 21, 2022
Comments
  • SharedPreferences: insecure by default

    SharedPreferences: insecure by default

    Hi. Just want to notice that SharedPreferences is insecure by default, so this implementation shouldn't be used to store sensitive data (i.e. user tokens)

    Current implementation works well but I think this information should be added to the README.md file in order to avoid unwanted effects.

    If you want you can check other packages like https://pub.dev/packages/encrypted_shared_preferences

    opened by henry2man 0
Owner
Abhishek Chavhan
AWS Solutions Architect | Flutter Developer | Youtuber
Abhishek Chavhan
Memory Cache is simple, fast and global in-memory cache with CRUD features.

Memory Cache Memory Cache is simple, fast and global in-memory cache. Features Create, read, update, delete and invalidate cache. Expirable Cache Gett

Gâkberk Bardakçı 6 Dec 25, 2022
Daily-Task-Manager a daily task manager application project created in flutter

This is a daily task manager application project created in flutter. Install this application on Android - Install from Play Store

DVS 0 May 10, 2022
Kyber Mod Manager A Mod Manager build for Kyber.

Kyber Mod Manager A Mod Manager build for Kyber. This app is not affiliated with Kyber or any of its creators. Key Features β€’ Download β€’ Screenshots β€’

liam 14 Sep 25, 2022
A Dart package to handle HTTP services

http_services A package to support the creation of Http services in a Dart application. Features convenient methods to perform HTTP requests disposing

Antonello GalipΓ² 5 Jul 27, 2021
A package help you to make api call and handle error faster, also you can check for internet before call api.

http_solver ##not for production use, only for learning purpose. A package help you to make api call and handle error faster, also you can check for i

Abdelrahman Saed 1 Jun 18, 2020
SearchBar widget to handle most of search cases

flappy_search_bar A SearchBar widget handling most of search cases. Usage To use this plugin, add flappy_search_bar as a dependency in your pubspec.ya

Smart&Soft 171 Dec 2, 2022
A library to easily handle sequential queueing of futures in dart.

queue Easily queue futures and await their values. This library allows you to send a future to central queue. The queue will execute the futures in th

Ryan Knell 38 Jan 4, 2023
Git+ is your ultimate GitLab mobile app that lets you interact with your projects like as if you were using desktop.

Git+ for GitLab Git+ is your ultimate GitLab mobile app that lets you interact with your projects like as if you were using desktop. Git+ lets you see

Marek Gvora 38 Jan 7, 2023
A flutter package from AsurRaa for widgets and utility functions to support mobile departments here.

sura_flutter A flutter package from AsurRaa for custom widgets and utility functions. Migrate from 0.2.x to 0.3.x BREAKING CHANGE: remove FutureManage

AsurRaa 4 Nov 15, 2022
Learn how to use Dart List Utility Methods in Flutter

Flutter Tutorial - List Utility Methods Learn how to use Dart List Utility Metho

Behruz Hurramov 0 Dec 29, 2021