Quantcast
Channel: This class (or a class which this class inherits from) is marked as '@imutable' but one or more of its instance fields are not final - Stack Overflow
Viewing all articles
Browse latest Browse all 2

This class (or a class which this class inherits from) is marked as '@imutable' but one or more of its instance fields are not final

$
0
0

I get this warning in Android Studio in stateless widget

This class (or a class which this class inherits from) is marked as'@imutable' but one or more of its instance fields are not final

when I want to create variable outside of build method. How do I get rid of this warning... or am I doing something wrong?

Replicable code

class TestScreen extends StatelessWidget {  final List<Map<String, dynamic>> list = [    {'id': 1, 'name': 'name1'},    {'id': 2, 'name': 'name2'}  ];  List<int> _ids = [];  @override  Widget build(BuildContext context) {    _ids.clear();    return Scaffold(      body: Column(        children: <Widget>[          Expanded(            child: ListView.builder(                itemCount: list.length,                itemBuilder: (BuildContext context, int index) {                  _ids.add(list[index]['id']);                  return ListTile(                    title: Text(list[index]['name']),                  );                }),          ),          FlatButton(            child: Text('Print all ids'),            onPressed: () {              print(_ids.toString());            },          )        ],      ),    );  }}

peace of that warning message

enter image description here


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>