#StackBounty: #ios #firebase #dart #flutter Flutter Dart App RangeError only on specific devices (not simulator)

Bounty: 50

My Flutter app has a list that loads data from a Firebase Firestore database. It loads fine on all simulator devices (and some real iOS devices) but breaks on actual iPhone 7 devices only. The following error is what I’m getting on iPhone7 :

RangeError (index): Invalid value: Valid value range is empty: 0

I’m not really sure where to begin debugging this error. Any guidance would be greatly appreciated!

Here’s my list generator code:

return new ListView(
  physics: const AlwaysScrollableScrollPhysics(),
  children: snapshot.data.documents.map((DocumentSnapshot document) {
    return _buildActivityItem(context,
      new Activity(
        activity: document['activity'],
        dateCreated: document['dateCreated'],
        food: document['food'],
        id: document.documentID,
        sentiment: document['sentiment'],
        text: document['text'],
      )
    );
  }).toList(),
);

Widget _buildActivityItem(BuildContext context, Activity activity) {
  // Format Date
  var formatter = new DateFormat('E., MMMM d').add_j();
  var today = new DateFormat('E').format(new DateTime.now()) == new DateFormat('E').format(activity.dateCreated);
  String formattedDateCreated = today ? new DateFormat().add_j().format(activity.dateCreated) : formatter.format(activity.dateCreated);

  // Format Activity
  String emoji = activity.activity == 'Exercise' ? '🏃‍' 
    : activity.food.length > 0 ? '🍴' 
      : '😐';

  // List Foods
  String getFoodList = activity.food.join(', ');

  return Container(
    decoration: new BoxDecoration(
      border: new Border(
        bottom: new BorderSide(width: 1.0, color: Theme.of(context).dividerColor)
      )
    ),
    child: ListTile(
      leading: new Text(
        emoji,
        style: new TextStyle(
          fontSize: 34.0
        )
      ),
      title: new Text(activity.text),
      subtitle: activity.activity.length > 0 ?  
        new Text(activity.activity )
        : activity.food.length > 0 ? new Text(getFoodList) 
          : null,
      trailing: new Text(formattedDateCreated),
    ),
  );
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.