file_cache 0.3.0 copy "file_cache: ^0.3.0" to clipboard
file_cache: ^0.3.0 copied to clipboard

File cached Json,Buffer,FileCacheImage for flutter package project.

example/lib/main.dart

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

class FileCacheTestFrame extends StatefulWidget {
  createState() => _FileCacheTestFrameState();
}

class _FileCacheTestFrameState extends State<FileCacheTestFrame> {
  FileCache? fileCache;
  Map? map;

  @override
  initState() {
    super.initState();

    FileCache.fromDefault().then((instance) {
      fileCache = instance;
    });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          // load
          ElevatedButton(
            onPressed: () {
              fileCache?.load('http://httpbin.org/cache/60').then((resp) {
                setState(() {});
              });
            },
            child: Text("load an url"),
          ),

          // getJson
          ElevatedButton(
            onPressed: () {
              fileCache?.getJson('http://httpbin.org/cache/600').then((resp) {
                setState(() {
                  print(">> got $resp");
                  map = resp;
                });
              });
            },
            child:
                Text('map: ${map == null ? null : map!["result"][0]["name"]}'),
          ),

          const Image(
              image: FileCacheImage(
            'https://assets.msn.com/weathermapdata/1/static/background/v2.0/jpg/sunny.jpg',
            scale: 1.9,
          )),

          //
          Text(fileCache == null ? '' : fileCache!.stats.toString())
        ],
      )),
    );
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final fileCache = await FileCache.fromDefault();
  print(fileCache.path);
  runApp(MaterialApp(home: FileCacheTestFrame()));
}
5
likes
120
pub points
66%
popularity

Publisher

unverified uploader

File cached Json,Buffer,FileCacheImage for flutter package project.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-2-Clause (LICENSE)

Dependencies

flutter, path_provider

More

Packages that depend on file_cache