Reputation: 31
Recently I developed an application, on android the application did'nt crash but then I try on iphone 6 my application crashes when opening the list. here the list code:
Container(
decoration: BoxDecoration(
border: Border.all(
color: KColors.GREY_PODCAST_L4),
borderRadius: BorderRadius.circular(4)),
margin: EdgeInsets.only(
left: 28, bottom: 16, right: 28),
padding: EdgeInsets.all(10),
child:PodcastEpisodeDetail(
podcast.episodes[index]),
),
class PodcastEpisodeDetail extends StatefulWidget {
final Episode episode;
PodcastEpisodeDetail(this.episode);
@override
_PodcastEpisodeDetailState createState() => _PodcastEpisodeDetailState();
}
class _PodcastEpisodeDetailState extends State<PodcastEpisodeDetail> {
String image;
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () async {
final firebase_storage.Reference storageRef = firebase_storage
.FirebaseStorage.instance
.ref()
.child(widget.episode.episodeImage);
final String url = (await storageRef.getDownloadURL());
if (this.mounted) {
setState(() {
image = url;
});
}
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(4)),
child: Container(
width: 64,
height: 64,
child: widget.episode.episodeImage != null &&
widget.episode.episodeImage.isNotEmpty &&
image != null &&
image.isNotEmpty
? CachedNetworkImage(
imageUrl: image,
alignment: Alignment.center,
fit: BoxFit.cover,
placeholder: (context, url) {
return Image.asset(
Images.PODCAST_SKELETON_HEADPHONE,
width: 64,
height: 64,
fit: BoxFit.cover,
);
},
errorWidget: (context, url, error) => Icon(Icons.error),
)
: Image.asset(
Images.PODCAST_SKELETON_HEADPHONE,
width: 64,
height: 64,
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, right: 19),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: MediaQuery.of(context).size.width - 204,
child: Text(
widget.episode.episodeTitle,
maxLines: 2,
softWrap: true,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.left,
style: Fonts.PODCAST_TITLE,
),
),
],
),
),
],
);
}
When i run in xcode it give me error title : Thread 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=650 MB, unused=0x0)
So why my iphone 6 can't handle it? while my android can handle the app?
Upvotes: 3
Views: 7949
Reputation: 51
CachedNetworkImage has properties maxHeightDiskCache and maxWidthDiskCache, you can use them to compress the size of the image stored in the cache of your device, thus, minimizing risks of getting app crashed.
Example
CachedNetworkImage(
width: width,
height: height - 45,
maxHeightDiskCache: ((height - 45)).round(),
maxWidthDiskCache: (width).round(),
fit: BoxFit.cover,
imageUrl: imageUrl,
placeholder: (_, __) => const CustomPlaceHolderWidget(),
errorWidget: (_, __, ___) => const CustomPlaceHolderWidget(), ),
Upvotes: 3
Reputation: 10539
The cause of the error is that the app likely consumes a huge amount of memory. Note that the iPhone 6 is an old device, possibly older compared to the Android device that you're currently testing with. If you're including older devices in your targets, you may want to consider limiting the amount of images displayed at a time. Images usually doesn't consume that much memory, but when there's a lot of images to be displayed, it could be.
Upvotes: 0