Created
September 14, 2019 16:22
-
-
Save Zfinix/8c074fdf40530f976d13c579611441b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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