Skip to content

Instantly share code, notes, and snippets.

@Zfinix
Created September 14, 2019 16:22
Show Gist options
  • Select an option

  • Save Zfinix/8c074fdf40530f976d13c579611441b7 to your computer and use it in GitHub Desktop.

Select an option

Save Zfinix/8c074fdf40530f976d13c579611441b7 to your computer and use it in GitHub Desktop.
library custom_image;
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CustomImage extends StatelessWidget {
final String assetPath;
final double height, width, scale;
final Color color;
final BlendMode colorBlendMode;
final bool isProviderImage;
const CustomImage(this.assetPath,
{Key key,
this.scale = 1.0,
this.height,
this.width,
this.color,
this.colorBlendMode,
this.isProviderImage = false})
: super(key: key);
@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: _loadImage(),
builder: (BuildContext context, AsyncSnapshot<String> image) {
if (image.hasData) {
if (assetPath.toLowerCase().contains('.svg')) {
return SvgPicture.network(
image.data,
height: height,
width: width,
);
} else {
return isProviderImage
? NetworkImage(
image.data,
scale: scale,
)
: Image.network(image.data,
scale: scale,
height: height,
width: width,
color: color,
colorBlendMode: colorBlendMode); // image is ready
}
} else {
return new Container(); // placeholder
}
},
);
}
Future<String> _loadImage() async {
final ref = FirebaseStorage.instance.ref().child('assets').child(assetPath);
var url = await ref.getDownloadURL();
return url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment