title: check if flutter future function works?
body: <p>hello iam new to flutter and i want to do a register function when the sign up button is pressed but i need to make sure that the function is sucssessfull so here is this code and i want to figure out whether i can check if the future function works if it does ill move to another screen id it don't ill show an error message .</p>
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter_custom_clippers/flutter_custom_clippers.dart';
  import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  import 'package:fluttertoast/fluttertoast.dart';
  import 'package:http/http.dart' as http;
  import 'dart:async';
  import 'dart:convert';
  
  class Signup extends StatefulWidget {
    @override
    _SignupState createState() =&gt; _SignupState();
  }
  
  class _SignupState extends State&lt;Signup&gt; {
    TextEditingController controllerName = TextEditingController();
    TextEditingController controllerEmail = TextEditingController();
    TextEditingController controllerPassword = TextEditingController();
    TextEditingController controllerYear = TextEditingController();
    TextEditingController controllerType = TextEditingController();
    void register() {
      var url = &quot;http://msc-mu.com/register.php&quot;;
      http.post(url, body: {
        &quot;Full_name&quot;: controllerName.text,
        &quot;Email&quot;: controllerEmail.text,
        &quot;Password&quot;: controllerPassword.text,
        &quot;Year&quot;: controllerYear.text,
        &quot;Type&quot;: controllerType.text
      });
    }
    String _selectedYear;
    List yearsList = List();
    Future&lt;String&gt; getYears() async {
      final response = await http.get('http://msc-mu.com/getYears.php');
      var resBody = json.decode(response.body);
      setState(() {
        yearsList = resBody;
      });
    }
    String _selectedLevel ;
    List levelList = List() ;
    Future&lt;String&gt; getLevel() async {
      final response = await http.get('http://msc-mu.com/getlevel.php');
      var resBody = json.decode(response.body);
      setState(() {
        levelList = resBody;
      });
    }
  
  
    @override
    void initState() {
      super.initState();
      this.getYears();
      this.getLevel();
      controllerYear.text = _selectedYear;
      controllerType.text = _selectedYear;
    }
  
    @override
    Widget build(BuildContext context) {
      Size size = MediaQuery.of(context).size;
      return Scaffold(
        body: SingleChildScrollView(
          child: Container(
            height: size.height,
            width: double.infinity,
              child: Form(
                child: Column(
                  children: &lt;Widget&gt;[
                    ClipPath(
                      clipper: OvalBottomBorderClipper(),
                      child: Image(
                        image: AssetImage('images/logo1.png'),
                        width: double.infinity,
                        height: MediaQuery.of(context).size.height / 2.9,
                        fit: BoxFit.cover,
                      ),
                    ),
                    Padding(
                      padding:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 50.0),
                      child: TextFormField(
                        controller: controllerName,
                        decoration: InputDecoration(
                          contentPadding: EdgeInsets.symmetric(vertical: 15.0),
                          fillColor: Colors.white,
                          filled: false,
                          hintText: 'Full Name',
                          prefixIcon: Icon(
                            FontAwesomeIcons.idCard,
                            size: 30.0,
                          ),
                        ),
                      ),
                    ),
                    Padding(
                      padding:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 50.0),
                      child: TextFormField(
                        controller: controllerEmail,
                        keyboardType: TextInputType.emailAddress,
                        decoration: InputDecoration(
                            contentPadding: EdgeInsets.symmetric(vertical: 15.0),
                            fillColor: Colors.white,
                            filled: false,
                            hintText: 'E-mail Address',
                            prefixIcon: Icon(FontAwesomeIcons.envelope)),
                      ),
                    ),
                    Padding(
                      padding:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 50.0),
                      child: TextFormField(
                        controller: controllerPassword,
                        keyboardType: TextInputType.visiblePassword,
                        decoration: InputDecoration(
                          contentPadding: EdgeInsets.symmetric(vertical: 15.0),
                          fillColor: Colors.white,
                          filled: false,
                          hintText: 'Password',
                          prefixIcon: Icon(FontAwesomeIcons.key),
                        ),
                        obscureText: true,
                      ),
                    ),
                    Padding(
                      padding:
                          EdgeInsets.symmetric(vertical: 10.0, horizontal: 50.0),
                      child: DropdownButton(
                        hint: Text('Choose A Year'),
                        icon: Icon(FontAwesomeIcons.caretDown),
                        style: TextStyle(color: Colors.black, fontSize: 18),
                        underline: Container(
                          height: 2,
                          color: Theme.of(context).primaryColor,
                        ),
                        items: yearsList.map((item) {
                          return DropdownMenuItem(
                            child: Text(item['name']),
                            value: item['name'].toString(),
                          );
                        }).toList(),
                        onChanged: (yearVal) {
                          setState(() {
                            _selectedYear = yearVal;
                            controllerYear.text = _selectedYear;
                          });
  
                        },
                        value: _selectedYear,
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(vertical: 10.0 , horizontal: 50.0),
                      child: DropdownButton(
                        hint: Text('Choose A Role'),
                        icon: Icon(FontAwesomeIcons.caretDown),
                        style: TextStyle(color: Colors.black, fontSize: 18),
                        underline: Container(
                          height: 2,
                          color: Theme.of(context).primaryColor,
                        ),
                        items: levelList.map((item) {
                          return DropdownMenuItem(
                            child: Text(item['levelname']),
                            value: item['levelname'].toString(),
                          );
                        }).toList(),
                        onChanged: (levelVal) {
                          setState(() {
                            _selectedLevel = levelVal;
                            controllerType.text = _selectedLevel;
                          });
  
                        },
                        value: _selectedLevel,
                      ),
                    ),
                    Expanded(
                      child: Align(
                        alignment: FractionalOffset.bottomCenter,
                        child: GestureDetector(
                          onTap: (){
                            setState(() {
                              if(((controllerName.text.isNotEmpty) &amp;&amp;
                                  (controllerPassword.text.isNotEmpty) &amp;&amp;
                                  (controllerEmail.text.isNotEmpty) &amp;&amp;
                                  (controllerYear.text.isNotEmpty) &amp;&amp;
                                  (controllerType.text.isNotEmpty))){
                                register();
  
                              }else {
                                Fluttertoast.showToast(
                                    msg: 'Please fill every thing',
                                    toastLength: Toast.LENGTH_SHORT,
                                    gravity: ToastGravity.BOTTOM,
                                    timeInSecForIosWeb: 1,
                                    backgroundColor: Colors.lightBlueAccent,
                                    textColor: Colors.white,
                                    fontSize: 16.0);
                              }
                            });
                          },
                          child: Container(
                            height: 80.0,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Theme.of(context).primaryColor
                            ),
                            child: Text('Signup',
                                style: TextStyle(
                                    color: Colors.white,
                                    letterSpacing: 1.5,
                                    fontSize: 22.0,
                                    fontWeight: FontWeight.w600)),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
  
          ),
        ),
      );
    }
  }
  
  </code></pre>