download_network_images_for_offline 0.0.5 copy "download_network_images_for_offline: ^0.0.5" to clipboard
download_network_images_for_offline: ^0.0.5 copied to clipboard

A simple flutter package that saves network images for whenever the user is offline

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:download_network_images_for_offline/download_network_images_for_offline.dart';

String externalStorageDir;
void main() async {
  Directory dir = await getExternalStorageDirectory();
  externalStorageDir = dir.path;

  // ensure file dir exists
  final offlineImagesDir = Directory(externalStorageDir + '/offlineImages');
  bool offlineImagesDirExists = await offlineImagesDir.exists();
  if (!offlineImagesDirExists) offlineImagesDir.create();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final List<String> images = ["WTlQ0sW", "ViZKPUs", "7saRqmV", "mUbOPfz"];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: ListView.builder(
          itemCount: images.length,
          itemBuilder: (BuildContext context, int index) {
            String imageID = images[index];

            return NetworkImageForOffline(
              file: File('$externalStorageDir/offlineImages/$imageID.jpeg'),
              url: 'https://i.imgur.com/$imageID.png',
              imageBuilder: (BuildContext context, ImageProvider imageProvider) {
                return ListTile(
                  leading: CircleAvatar(
                    backgroundImage: imageProvider,
                  ),
                  title: Text('Test-Text'),
                );
              },
            );
          },
        ),
      ),
    );
  }
}
7
likes
40
pub points
0%
popularity

Publisher

verified publishermartvenck.com

A simple flutter package that saves network images for whenever the user is offline

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

connectivity, flutter, http

More

Packages that depend on download_network_images_for_offline