title: How to return data from custom function which uses bottom sheet in flutter
body: <p>I made a custom function which opens modal bottom sheet in flutter. Now, I want to get some data back from the sheet to my previous page. How should I do it? I tried to make function's return type as <code>Future&lt;FilterDataModel&gt;</code> and Future, but it's not working. I want that whenever the user clicks on cancel, it should return false and when he presses apply, i should get true with the data.</p>
  <p>Here is what I tried -</p>
  <pre><code>Future&lt;FilterDataModel&gt; showFilterBottomSheet&lt;T&gt;(
      {required BuildContext context}) async {
    
    Some code ...........
  
    FilterDataModel filterData = FilterDataModel();
  
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      builder: (context) {
        String val = &quot;One&quot;;
        return StatefulBuilder(
          builder: (context, StateSetter setState) {
            return Wrap(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(
                    vertical: getProportionateScreenHeight(20),
                    horizontal: getProportionateScreenWidth(16),
                  ),
                  child: Column(
                    ..............
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Expanded(
                            child: InkWell(
                              onTap: () {
                                Navigator.pop(context, [false, filterData]);
                              },
                              child: Container(
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(8),
                                  border: Border.all(color: Colors.white),
                                ),
                                padding: EdgeInsets.symmetric(
                                  vertical: getProportionateScreenHeight(16),
                                ),
                                child: Center(
                                  child: Text(
                                    'Cancel',
                                    style: TextStyle(
                                      color: primaryText2,
                                      fontSize: 16,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: getProportionateScreenWidth(20),
                          ),
                          Expanded(
                            child: InkWell(
                              onTap: () {
                                Navigator.pop(context, [true, filterData]);
                              },
                              child: Container(
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(8),
                                  border: Border.all(color: Colors.black38),
                                ),
                                padding: EdgeInsets.symmetric(
                                  vertical: getProportionateScreenHeight(16),
                                ),
                                child: Center(
                                  child: Text(
                                    'Apply',
                                    style: TextStyle(
                                      color: primaryOrange,
                                      fontSize: 16,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            );
          },
        );
      },
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.0),
      ),
    ).then((value) {
      debugPrint(&quot;Coming data&quot;);
      debugPrint(filterData.academicYear.toString());
      return filterData;
    });
    return filterData;
  }
  </code></pre>
  <p>And how I am calling it -</p>
  <pre><code>onPressed: () async {
                FilterDataModel f = await showFilterBottomSheet(
                  context: context,
                );
                print(&quot;Here - ${f.academicYear}&quot;);
              },
  </code></pre>
  <p>I also tried to do it like this -</p>
  <pre><code>onPressed: () async {
                await showFilterBottomSheet(
                  context: context,
                ).then((value) {
                  print(&quot;Inside then&quot;);
                  print(value[0]);
                  print(value[1].toString());
                });
                print(&quot;Here - ${f.academicYear}&quot;);
              },
  </code></pre>
  <p>But it's not working.</p>