any_image 0.0.1 copy "any_image: ^0.0.1" to clipboard
any_image: ^0.0.1 copied to clipboard

A universal Flutter image widget that renders any source

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(title: 'any_image example', home: ExampleScreen());
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('any_image example')),
      body: const SingleChildScrollView(
        padding: EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _SectionLabel('Network raster'),
            AnyImage(
              source: 'https://picsum.photos/400/200',
              width: double.infinity,
              height: 200,
              fit: BoxFit.cover,
              placeholder: Center(child: CircularProgressIndicator()),
              errorWidget: Center(child: Icon(Icons.broken_image)),
            ),
            _SectionLabel('Network SVG'),
            AnyImage(
              source:
                  'https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg',
              width: double.infinity,
              height: 200,
              placeholder: Center(child: CircularProgressIndicator()),
              errorWidget: Center(child: Icon(Icons.broken_image)),
            ),
            _SectionLabel('Asset raster'),
            AnyImage(
              source: 'assets/images/placeholder.png',
              width: double.infinity,
              height: 200,
              fit: BoxFit.cover,
              errorWidget: Center(child: Icon(Icons.broken_image)),
            ),
          ],
        ),
      ),
    );
  }
}

class _SectionLabel extends StatelessWidget {
  final String label;

  const _SectionLabel(this.label);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 24, bottom: 8),
      child: Text(label, style: Theme.of(context).textTheme.titleMedium),
    );
  }
}
2
likes
150
points
85
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A universal Flutter image widget that renders any source

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

cached_network_image, flutter, flutter_svg

More

Packages that depend on any_image