I am very new to Flutter and I run into a Problem. I want to check if the List: items, contains the word
Hey and I know it does. So I wrote: if(items.contains('Hey'))
to check. But it seems to skip the if
part and only returns the else part. I wrote this easy Code to show you what I mean. I would really appreciate
a quick answer, because of I really need to solve this problem.
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Contain()));
class Liste {
String Wort1;
String Wort2;
Liste({this.Wort1, this.Wort2});
}
class Contain extends StatefulWidget {
@override
_ContainState createState() => _ContainState();
}
class _ContainState extends State<Contain> {
List<Liste> items = List<Liste>();
@override
void initState() {
items = [
Liste(Wort1: 'Hey', Wort2: 'Ho'),
Liste(Wort1: 'HA', Wort2: 'HE'),
];
super.initState();
}
function() {
if (items.contains('Hey')) {
return Center(
child: Text('Works'),
);
} else {
return Center(
child: Text('Not Working'),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: function(),
);
}
}