title: Pass List to another Class in Flutter
body: <p>I have a list 'names' of strings in a NameViewList and trying to pass its values to another class Basic().</p>
  
  <p>I tried this approach but it gives me an error: 
  error: 'names' is final and was given a value when it was declared, so it can't be set to a new value. (final_initialized_in_declaration_and_constructor at [flutterspinningwheel] lib/nameviewlist.dart:5)</p>
  
  <p>I used this way to pass variable and it was working but when I pass list it does not work</p>
  
  <pre><code>     class NameViewList extends StatefulWidget {
    NameViewList({Key key, this.names});
    final List&lt;String&gt; names = &lt;String&gt;[];
  
    @override
    _NameViewListState createState() =&gt; _NameViewListState();
  }
  
  class _NameViewListState extends State&lt;NameViewList&gt; {
  
  
    TextEditingController nameController = TextEditingController();
  
     createDialog(BuildContext context){
      return showDialog(context: context, builder: (context) {
        return AlertDialog(
          title: Text('Insert Name'),
          content: TextField(
            controller: nameController,
            decoration: InputDecoration(
              border: OutlineInputBorder(),
              labelText: 'Contact Name',
            ),
          ),
          actions: [
            MaterialButton(
              child: Text('Submit'),
              onPressed: (){
                addItemToList();
                Navigator.of(context).pop();
              },
            )
          ],
        );
      });
    }
  
    void addItemToList(){
      setState(() {
        widget.names.insert(0, nameController.text);
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Settings'),
          centerTitle: true,
        ),
        body: Column(
          children: [
            IconButton(
              icon: Icon(Icons.queue, color: Colors.green,),
              onPressed: (){createDialog(context);},
            ),
            Padding(
              padding: EdgeInsets.all(20),
              child: TextField(
                controller: nameController,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: 'Contact Name',
                ),
              ),
            ),
            Row(
              children: [
                RaisedButton(
                  child: Text('Clear'),
                  onPressed: () {
                    setState(() {
                      widget.names.clear();
  
                    });
                  },
                ),
                RaisedButton(
                  child: Text('Submit'),
                  onPressed: () {
                    Navigator.of(context).push(MaterialPageRoute(builder: (context)=&gt; Basic(names: names)));
                  },
                ),
              ],
            ),
  </code></pre>