title: How do I pass through parameters in order to post data to a REST API?
body: <p>I am trying to post multiple data items to a REST API in JSON format. I am able to post the username and password however am unable to pass through the other details pertaining to the device such as manufacturer, model and version. 
  I have created a function to pass through the additional parameters however in the function itself the parameters are not being pass through to the private variables I am assigning them to.
  Here is my code currently: </p>
  
  <p><strong>login screen</strong></p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:device_info/device_info.dart';
  
  import 'home_screen.dart';
  import '../auth/auth.dart';
  import '../data/database_helper.dart';
  import '../models/user.dart';
  import '../screens/login_screen_presenter.dart';
  
  import 'dart:ui';
  import 'dart:io';
  
  class LoginScreen extends StatefulWidget{
  
    @override
    State&lt;StatefulWidget&gt; createState(){
      return new LoginScreenState();
    }
  }
  
  class LoginScreenState extends State&lt;LoginScreen&gt;
    implements LoginScreenContract, AuthStateListener{
      BuildContext _ctx;
  
      bool _isLoading = false;
      final formKey = new GlobalKey&lt;FormState&gt;();
      final scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
  
      String _password;
      String _username;
      String _manufacturer;
      String _model;
      String _version;
  
      DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
      AndroidDeviceInfo androidDeviceInfo;
      IosDeviceInfo iosDeviceInfo;
  
      LoginScreenPresenter _presenter;
  
      LoginScreenState(){
        _presenter = new LoginScreenPresenter(this);
        var authStateProvider = new AuthStateProvider();
        authStateProvider.subscribe(this);
        initPlatform();
      }
  
      Future&lt;Null&gt; initPlatform() async {
        AndroidDeviceInfo aInfo;
        IosDeviceInfo iInfo;
  
  
        try{
          if (Platform.isAndroid) {
            aInfo = await deviceInfoPlugin.androidInfo;
          } else if (Platform.isIOS){
            iInfo = await deviceInfoPlugin.iosInfo;        
          } 
        }
        catch (e){
          print(e.toString());
        }
  
        if(!mounted) return;
  
        setState(() {
              androidDeviceInfo = aInfo;
              iosDeviceInfo = iInfo;
              function(_manufacturer,_model,_version);
            });
      }
  
       function(_manufacturer,_model,_version){
           _manufacturer = androidDeviceInfo.manufacturer;
           _model =  androidDeviceInfo.model;
           _version =  androidDeviceInfo.version;   
      }  
  
      void _submit(){
        final form = formKey.currentState;
  
        if (form.validate()) {
          setState(() =&gt; _isLoading = true);
          form.save();
          function(_manufacturer,_model,_version);
          _presenter.doLogin(_username, _password, _manufacturer, _model, _version);
        } 
      }
  
      void _showSnackBar(String text) {
        scaffoldKey.currentState
          .showSnackBar(new SnackBar(content: new Text(text)));
      }
  
      @override
      onAuthStateChanged(AuthState state){
        if (state == AuthState.LOGGED_IN)
          Navigator.of(_ctx).pushReplacementNamed('/home');
      }
  
      @override
      Widget build(context){
        _ctx = context;
        return Scaffold(
          key: scaffoldKey,
          appBar: new AppBarDesign(),
          drawer: new Drawer(
            child: new ListView(
              children: [
                new ListTile(
                  title: new Text('Home'),
                  trailing: new Icon(Icons.arrow_right),
                  onTap: (){Navigator.push(
                context,
                MaterialPageRoute(builder: (context) =&gt; HomeScreen()),
              ); },
                )
              ],
            ),
          ),        
          body: Form(
            key: formKey,
            child: ListView(
              children: [
                //  Banner 
                new Column(
                  children: [
                    new Row( 
                      children: [ 
                        new Expanded(
                          child:Image(
                          image: new AssetImage('assets/Banner.png'), 
                          fit: BoxFit.fitWidth              
                          )
                        )            
                      ]
                    ),      
                  ],
                ),
  
                new  Container(padding: EdgeInsets.only(top:10.0)),
  
                //Instructional text
                new Container(
                  child: new Column(
                    children:[
                      Text('Please enter your username'),
                      Text('and password below to start'),
                      Text('using the application'),
                    ]
                  ),
                ),
  
                new  Container(padding: EdgeInsets.only(top:4.0)),
  
                // Links to username widget, password widget and loginbtn widget
                new Column( 
                  children: [ 
                    usernameField(context),
                    passwordField(context),
                    new  Container(padding: EdgeInsets.only(top:10.0)),           
                    _isLoading ? new CircularProgressIndicator():  submitButton(context)                  
                  ],
                ),
              ]
            ) 
          ),          
        );
      }  
  
      Widget deviceInfo(BuildContext context){
        return FutureBuilder(
          future: initPlatform(),
          builder: (BuildContext context, AsyncSnapshot snapshot){
            if (snapshot.connectionState == ConnectionState.none){
              return Text('Error: ${snapshot.error}');
            } else {
              return Column(
                children: [
                  function(_manufacturer,_model,_version),                
                ]
              );
            }
          }
        );
      } 
  
      Widget usernameField(context){       
        return TextFormField(
          onSaved: (val) =&gt; _username = val,      
          keyboardType: TextInputType.emailAddress,
          validator: (val){
            return val.length &lt; 10
                ? "Username must have atleast 10 characters"
                : null;
          },
          decoration: InputDecoration(
            hintText: '',
            labelText: 'Username',
          ) 
        );      
      }
  
      Widget passwordField(context){        
        return TextFormField(
          onSaved: (val) =&gt; _password = val,
          validator: (val){
            return val.length &lt; 4
                ? "Password must have atleast 5 characters"
                : null;
          },
          obscureText: true,
          decoration: InputDecoration(
            hintText: 'Password',
          labelText: 'Password',
          ),
        );
      }
  
      Widget submitButton(context){
        return RaisedButton(
          child: Text('Login'),
          color: Colors.grey[150],
          onPressed: _submit,
        );
      } 
  
  
    @override
    void onLoginError(String errorTxt) {
      _showSnackBar(errorTxt);
      setState(() =&gt; _isLoading = false);
    }
  
    @override
    void onLoginSuccess(User user) async {
      _showSnackBar(user.toString());
      setState(() =&gt; _isLoading = false);
      var db = new DatabaseHelper();
      await db.saveUser(user);
      var authStateProvider = new AuthStateProvider();
      authStateProvider.notify(AuthState.LOGGED_IN);
    }
  }
  
  class AppBarDesign extends AppBar{
  
    AppBarDesign():super(
      title: Text('FlashLight'),    
            backgroundColor: Color.fromRGBO(32,32,32,32),
            actions: [
              Icon(
                IconData(0xe885, fontFamily: 'MaterialIcons'),
              ),
            ],
    );
  }
  </code></pre>
  
  <p><strong>login screen presenter</strong></p>
  
  <pre><code>import 'package:login_bloc/src/data/rest_ds.dart';
  import 'package:login_bloc/src/models/user.dart';
  
  abstract class LoginScreenContract {
    void onLoginSuccess(User user);
    void onLoginError(String errorTxt);
  }
  
  class LoginScreenPresenter {
    LoginScreenContract _view;
    RestDatasource api = new RestDatasource();
    LoginScreenPresenter(this._view);
  
    doLogin(String username, String password, String manufacturer, String model, String version) {
      api.login(username, password, manufacturer, model, version).then((dynamic res) {
  
        print(res.toString());
        print(res["LoginMessage"]);
        if(!res["LoginSuccessful"]) {
          _view.onLoginError(res["LoginMessage"]);
          return;
        }
  
        _view.onLoginSuccess(User.map(res["user"]));
      }).catchError((Exception error) { 
        _view.onLoginError(error.toString());
      });
    }
  }
  </code></pre>
  
  <p><strong>rest_ds</strong></p>
  
  <pre><code>import 'dart:async';
  
  import 'package:login_bloc/src/utils/network_util.dart';
  import 'package:login_bloc/src/models/user.dart';
  
  class RestDatasource {
    NetworkUtil _netUtil = new NetworkUtil();
    static final BASE_URL = "API url";
    static final LOGIN_URL = BASE_URL + "API url detail";
    static final _API_KEY = "somerandomkey";
  
    Future&lt;dynamic&gt; login(String username, String password, String manufacturer, String model, String version ) {
  
      return _netUtil.post(LOGIN_URL, body: {
        "token": _API_KEY,
        "username": username,
        "password": password,
        "manufacturer": manufacturer,
        "model": model,
        "version": version, 
      });
    }
  }
  </code></pre>