network_resource 0.2.5 copy "network_resource: ^0.2.5" to clipboard
network_resource: ^0.2.5 copied to clipboard

Deprecated in favor of async_resource. Automatically cache network resources and use them when offline.

example/main.dart

import 'dart:convert';
import 'dart:io';
import 'package:network_resource/network_resource.dart';

// A string list, line by line.
final words = StringListNetworkResource(
  url: 'https://example.com/wordlist.txt',
  cacheFile: File('wordlist.txt'),
);

// Extending [NetworkResource] to provide a different data type.
class EventListResource extends NetworkResource<List<Event>> {
  EventListResource()
      : super(
            url: 'http://example.com/events.json',
            cacheFile: File('events.json'),
            maxAge: Duration(minutes: 60),
            isBinary: false);
  @override
  List<Event> parseContents(contents) {
    List events;
    json.decode(contents).forEach((item) => events.add(Event(item)));
    return events;
  }
}

class Event {
  final String title;
  Event(this.title);
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Deprecated in favor of async_resource. Automatically cache network resources and use them when offline.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

http, meta, path

More

Packages that depend on network_resource