Pro Co
Pro Co

Reputation: 371

"Exception Caused by Gesture" Error in Flutter

Hi am Geeting an Error of Exception when I am Running "onChanged" in my Flutter Application. (Material Button)

════════ Exception caught by gesture ═══════════════════════════════════════════
type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => Iterable<dynamic>' of 'f'

Edit: This Function below is making these issues, as the code is big, I showed you a snipped where it is occurring, I also Quottted the line which my debugger Quoted for this Error.-

  TextEditingController emojiSlideshow = new TextEditingController();


var todoText;
  var ofTodoText;
  var charecters;
  var finalTodoEmoji;
  // final var rawtodoEmoji;
  // final var todoEmoji;
  var finaltodoEmoji;
  var finalTodoEmojiList;
  var totalEmojis;
  var currentEmoji;

    

void emojiRecommender() async {
await Future<void>.delayed(Duration(seconds: 1));
todoText = emojiSlideshow.text;

print(todoText); //What You need to Translate;
ofTodoText =
    todoText.split(' '); //Splits texts to Invidually Translate a word

charecters = ofTodoText
    .length; // int, the number of charectoers or words in todoText
finaltodoEmoji = [];

for (int i = 0; i < charecters;) {
  //for loop
  final rawtodoEmoji =
      Emoji.byKeyword(ofTodoText[i]); //It gives all emoji as output
  final todoEmoji = rawtodoEmoji
      .take(7)
      .toList(); // this Compresses each set of emoji to Three (limits)
  // print(todoEmoji); // prints those Three Emoji

  finaltodoEmoji.add(todoEmoji);

  finaltodoEmoji.shuffle();

  i++; //Counter increments.
}
finalTodoEmojiList = finaltodoEmoji.expand((x) => x).toList();
//print(finalTodoEmojiList);

//Print each Emoji in One Second
//
totalEmojis = finalTodoEmojiList.length;
for (var i = 0; i < totalEmojis; i++) {
  currentEmoji = finalTodoEmojiList[i];
  print(currentEmoji);
  

  sleep(Duration(seconds: 1, milliseconds: 2));
}
setState(() {});

}

If you are not able to Understand this Code, You can ask me to Have a Live-Share Session on VScode to Discuss the Whole Code. Respect++;

Upvotes: 0

Views: 129

Answers (1)

Maaz Aftab
Maaz Aftab

Reputation: 368

The issue is that you are not really passing the correct parameter in expand function that applies on List.

Example: You must return iterable object inside the expand

var input = [1, 2, 3];
var duplicated = input.expand((i) => **[i, i]**).toList();
print(duplicated); // => [1, 1, 2, 2, 3, 3]

However, in your case you are just returning a single value that is not how expand works. You can at least do below correction to make your code works.

finalTodoEmojiList = finaltodoEmoji.expand((x) => [x]).toList();

Upvotes: 1

Related Questions