title: Flutter how to make this class return onChanged?
body: <p>I used some classes online to edit them and make what I needed, this is what I got, however I need to get the data using an 'onChange' function, so I can use it in different forms in the app.</p>
  <p>How would I be able to do it? This is the code of the class:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:sembast/sembast.dart';
  
  import 'flutter_search_pannel/flutter_search_panel.dart';
  import 'flutter_search_pannel/search_item.dart';
  
  class SuspendedListPicker extends StatefulWidget {
    SuspendedListPicker({
      this.data,
      this.onChanged,
    });
  
    List&lt;SearchItem&lt;int&gt;&gt; data = [];
    final Function onChanged;
  
    @override
    _MyAppState createState() =&gt; new _MyAppState(data);
  }
  
  class _MyAppState extends State&lt;SuspendedListPicker&gt; {
    _MyAppState(this.data);
    List&lt;SearchItem&lt;int&gt;&gt; data = [];
    var selected;
    @override
    Widget build(BuildContext context) {
      return Container(
          width: MediaQuery.of(context).size.width * 0.55,
          child: FlutterSearchPanel&lt;int&gt;(
            title: &quot;Selecione&quot;,
            data: data,
  
            //padding: EdgeInsets.all(10.0),
            icon: Icon(Icons.label, color: Colors.blue[300]),
            color: Colors.white,
  
            textStyle: TextStyle(
              color: Colors.black,
              fontSize: 28.0,
              // onChanged: (value) {
              //   print(value);
              // },
            ),
          ));
    }
  }
  </code></pre>
  <p>And here is Flutter_search_panel asset that I also modified (It is an import from <a href="https://pub.dev/packages/flutter_search_panel" rel="nofollow noreferrer">https://pub.dev/packages/flutter_search_panel</a>)</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'search_page.dart';
  import 'search_item.dart';
  
  class FlutterSearchPanel&lt;TValue&gt; extends StatefulWidget {
    @required
    final Function onChanged;
    @required
    final List&lt;SearchItem&lt;TValue&gt;&gt; data;
    final String title;
    final Icon icon;
    final TextStyle textStyle;
    final Color color;
    final EdgeInsetsGeometry padding;
    final TValue selected;
  
    FlutterSearchPanel(
        {this.onChanged,
        this.title,
        this.data,
        this.icon,
        this.textStyle,
        this.selected,
        this.padding,
        this.color});
  
    @override
    State&lt;StatefulWidget&gt; createState() {
      return new _FlutterSearchPanelState&lt;TValue&gt;();
    }
  }
  
  class _FlutterSearchPanelState&lt;TValue&gt;
      extends State&lt;FlutterSearchPanel&lt;TValue&gt;&gt; {
    SearchItem&lt;TValue&gt; selection;
    final _defaultIcon = Icons.label;
    final TextStyle _defaultTextStyle =
        new TextStyle(color: Colors.red, fontSize: 22.0);
    final Color _defaultColor = Colors.red;
    final EdgeInsetsGeometry _defaultPadding = EdgeInsets.all(10.0);
  
    @override
    void initState() {
      super.initState();
      if (widget.selected != null) {
        selection = widget.data.firstWhere(
            (item) =&gt; item.value == widget.selected,
            orElse: () =&gt; selection = widget.data[0]);
      } else {
        selection = widget.data[0];
      }
    }
  
    @override
    void dispose() {
      super.dispose();
    }
  
    _openSearchPage() async {
      final result = await Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) =&gt; SearchPage(
                title: widget.title,
                data: widget.data,
                icon: widget.icon ?? _defaultIcon,
                padding: widget.padding ?? _defaultPadding,
                color: widget.color ?? _defaultColor,
                textStyle: widget.textStyle ?? _defaultTextStyle)),
      );
  
      if (result != null) {
        setState(() {
          selection = result;
        });
        if (widget.onChanged != null) {
          widget.onChanged((result as SearchItem&lt;TValue&gt;).value);
        }
      }
    }
  
    @override
    Widget build(BuildContext context) =&gt; new InkWell(
      onTap: _openSearchPage,
      child: SizedBox(
      //height: MediaQuery.of(context).size.height,
      child: Container(
          decoration: BoxDecoration(
              border: Border.all(color: Colors.black)),
              child: Text(
                  selection.text,
  
                  textAlign: TextAlign.right,
                  style: widget.textStyle ?? Theme.of(context).textTheme.button, 
              ),
          ),
      ),
  );
  }
  
  
  // RaisedButton(
  //         color: widget.color ?? Colors.blue,
  //         child: Flex(
  //           direction: Axis.horizontal,
  //           mainAxisSize: MainAxisSize.min,
  //           children: &lt;Widget&gt;[
  //             Flexible(
  //               child: Padding(
  //                 padding: const EdgeInsets.all(10.0),
  //                 child: Text(
  //                   selection.text,
  //                   style: widget.textStyle ?? Theme.of(context).textTheme.button, textAlign: TextAlign.right,
  //                 ),
  //               ),
  //             ),
  //           ],
  //         ),
  //         padding: widget.padding,
  //         onPressed: _openSearchPage,
  //       );
  </code></pre>