asset_widget 1.0.0 copy "asset_widget: ^1.0.0" to clipboard
asset_widget: ^1.0.0 copied to clipboard

A powerful and flexible widget for rendering all types of visual assets in a single line of code!

πŸ–ΌοΈ Asset Flutter Package #

A powerful and flexible widget for rendering all types of visual assets in a single line of code!

Supports:

  • βœ… Material Icons
  • βœ… Cupertino Icons
  • βœ… Asset Images (png, jpg, jpeg, gif)
  • βœ… Network Images (png, jpg, jpeg, gif) β€” with caching
  • βœ… File Images (from memory)
  • βœ… SVGs (from assets)
  • βœ… Lottie animations (from assets or network)

✨ Features #

  • Render different asset types using the same Asset widget
  • Support for tap interaction via onTap
  • Customize size, color, fit, shape, and border radius
  • Display a placeholder widget while loading
  • Display a fallback error widget when loading fails
  • Automatically determines asset type at runtime
  • Built-in network image caching

πŸ“¦ Installation #

Add the following to your pubspec.yaml:

dependencies:
  asset_widget: <latest_version>

Then run:

flutter pub get

πŸš€ Usage #

Import the package #

import 'package:asset_widget/asset.dart';

🧩 Examples #

Material Icon #

Asset(Icons.person, height: 32, color: Colors.blue)

Cupertino Icon #

Asset(CupertinoIcons.person, height: 32, color: Colors.red)

Image from Assets #

Asset('assets/images/image.jpg', height: 100, width: 100)

Image from Network (with caching) #

Asset(
  'https://picsum.photos/seed/picsum/600/300',
  height: 150,
  width: 300,
  placeholder: CircularProgressIndicator(),
  errorWidget: Icon(Icons.error),
)

GIF from Assets #

Asset('assets/giphy.gif', height: 150)

GIF from Network #

Asset('https://media2.giphy.com/media/giphy.gif', height: 150)

SVG from Assets #

Asset(
  'assets/icons/icon.svg',
  height: 64,
  width: 64,
  color: Colors.green,
)

Lottie from Assets #

Asset('assets/animations/animation.json', height: 120)

Lottie from Network #

Asset('https://assets9.lottiefiles.com/packages/lf20_zrqthn6o.json', height: 120)

🎨 Customization #

All asset types support the following optional parameters:

Parameter Type Description
height double? Height of the asset
width double? Width of the asset
color Color? Tint color (applied to icons and SVGs)
placeholder Widget? Placeholder while loading
errorWidget Widget? Fallback widget on failure
fit BoxFit (default: fill) Image fitting behavior
borderRadius BorderRadiusGeometry? Rounded corners
shape BoxShape? Shape of the container (e.g.,BoxShape.circle)
onTap void Function()? Callback when tapped

πŸ§ͺ Bonus Example with Border Radius and Tap Handler #

Asset(
  'https://example.com/image.jpg',
  height: 120,
  width: 120,
  borderRadius: BorderRadius.circular(12),
  fit: BoxFit.cover,
  onTap: () => print('Asset tapped!'),
)

πŸ“ Supported Asset Types & Detection Logic #

The Asset widget intelligently detects the type using runtime checks:

Type Detection Logic
Material/Cupertino asset is IconData
Network Image asset.toString().startsWith('http')
Asset Image asset.toString().startsWith('assets/')
File Image Otherwise assumes it's a file path
SVG asset.endsWith('.svg')
Lottie (asset) asset.endsWith('.json') and from assets
Lottie (network) JSON file with http path

🧱 Example in a ListView #

ListView(
  children: [
    Asset(Icons.home),
    Asset(CupertinoIcons.settings),
    Asset('assets/icon.svg'),
    Asset('assets/sample.jpg'),
    Asset('https://via.placeholder.com/150'),
    Asset('assets/anim.json'),
  ],
)

πŸ”§ Dependencies #


πŸ’‘ Tip #

Use BoxFit.contain, BoxFit.cover, etc., to control how the asset fits inside its container.


πŸ§‘β€πŸ’» Author #

Feel free to contribute to this project!

3
likes
150
points
22
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful and flexible widget for rendering all types of visual assets in a single line of code!

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

cached_network_image, flutter, flutter_svg, lottie

More

Packages that depend on asset_widget