title: The setter 'msg=' was called on null
body: <p>I am sending a request to an api with flutter and saving the response values in  instance of one of my models. but i am getting some strange errors. you can see my code and errors that i am getting below. I am using scoped_model for state management.</p>
  
  <pre><code>import 'dart:convert';
  import 'dart:async';
  import 'dart:io';
  
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:scoped_model/scoped_model.dart';
  import 'package:http/http.dart' as http;
  import 'package:rxdart/subjects.dart';
  
  
  class Patient {
    final String guid;
    final String phone;
    final String token;
    final String name;
    final String lastName;
  
    Patient({@required this.guid, @required this.phone, @required this.token , @required this.name , @required this.lastName });
  }
  
  class RTN {
     String msg = '';
     String success = 'false';
     String guid ='';
     String srcPath ='';
     String thumbPath ='';
     dynamic obj ='';
  
    RTN(
        {@required this.msg,
        @required this.guid,
        @required this.obj,
        @required this.srcPath,
        @required this.success,
        @required this.thumbPath});
  }
  
  
  
  class MainModel extends Model with Connected, PatientModel, UtilityModel {
  }
  
  mixin Connected on Model {
    List&lt;Doctor&gt; _doctor = [];
    Patient _authenticatedPatient;
    bool _isLoading = false;
    RTN _rtn;
    RTN get rtn{
      return _rtn;
    }
  
    List&lt;Doctor&gt; get allDrs {
      return List.from(_doctor);
    }
  }
  
  mixin PatientModel on Connected {
    PublishSubject&lt;bool&gt; _patientSubject = PublishSubject();
  
    Patient get patient {
      return _authenticatedPatient;
    }
  
    PublishSubject&lt;bool&gt; get patientSubject {
      return _patientSubject;
    }
  
    Future&lt;Map&lt;String, dynamic&gt;&gt; authenticateFirst(String phone) async {
      try{
      _isLoading = true;
      notifyListeners();
      final Map&lt;String, dynamic&gt; authFirstData = {
        'Phone': phone,
      };
      http.Response response;
      response = await http.post(
        'http://guffy.ir/Auth/RegisterOne',
        body: json.encode(authFirstData),
        headers: {'Content-Type': 'application/json'},
      );
  
      final Map&lt;String, dynamic&gt; responseData = json.decode(response.body);
      print(responseData);
      bool hasError = true;
      String message = '';
      print(responseData);
      if (responseData.containsKey("guid")) {
         hasError = false;
        rtn.msg = responseData["msg"];
        rtn.guid = responseData["guid"];
        rtn.obj = responseData["obj"];
        rtn.srcPath = responseData["srcPath"];
        rtn.success = responseData["success"];
        rtn.thumbPath = responseData["thumbPath"];
        message = rtn.msg;
        _authenticatedPatient = Patient(
          guid: responseData["guid"],
          phone: phone,
          token: null,
          name: null,
          lastName: null,
        );
        // _patientSubject.add(true);
        final SharedPreferences prefs = await SharedPreferences.getInstance();
        prefs.setString('token', '');
        prefs.setString('patientPhone', phone);
        prefs.setString('patientGuid', responseData['guid']);
        prefs.setString('name', '');
        prefs.setString('lastName', '');
      }
      _isLoading = false;
      notifyListeners();
      return {'success': !hasError, 'message': message};
    }
    catch(error){
      _isLoading = false;
      print(error);
    }}
    Future&lt;Map&lt;String, dynamic&gt;&gt; authenticateSecond(String phone) async {
      _isLoading = true;
      notifyListeners();
      final Map&lt;String, dynamic&gt; authFirstData = {
        'Phone': phone,
      };
      http.Response response;
      response = await http.post(
        'http://guffy.ir/Auth/RegisterOne',
        body: json.encode(authFirstData),
        headers: {'Content-Type': 'application/json'},
      );
  
      final Map&lt;String, dynamic&gt; responseData = json.decode(response.body);
      print(responseData);
      bool hasError = true;
      String message = '';
      print(responseData);
      if (responseData.containsKey('guid')) {
        hasError = false;
        message = responseData['msg'];
        _authenticatedPatient = Patient(
          guid: responseData['guid'],
          phone: phone,
          token: null,
          name: null,
          lastName: null,
        );
        // _patientSubject.add(true);
        final SharedPreferences prefs = await SharedPreferences.getInstance();
        prefs.setString('token', null);
        prefs.setString('patientPhone', phone);
        prefs.setString('patientGuid', responseData['guid']);
        prefs.setString('name', null);
        prefs.setString('lastName', null);
      }
      _isLoading = false;
      notifyListeners();
      return {'success': !hasError, 'message': message};
    }
      Future&lt;Map&lt;String, dynamic&gt;&gt; authenticateThird(String phone) async {
      _isLoading = true;
      notifyListeners();
      final Map&lt;String, dynamic&gt; authThirdData = {
        'Phone': phone,
      };
      http.Response response;
      response = await http.post(
        'http://guffy.ir/Auth/RegisterOne',
        body: json.encode(authThirdData),
        headers: {'Content-Type': 'application/json'},
      );
  
      final Map&lt;String, dynamic&gt; responseData = json.decode(response.body);
      print(responseData);
      bool hasError = true;
      String message = '';
      print(responseData);
      if (responseData.containsKey('guid')) {
        hasError = false;
        message = responseData['msg'];
        _authenticatedPatient = Patient(
          guid: responseData['guid'],
          phone: phone,
          token: null,
          name: null,
          lastName: null,
        );
        _patientSubject.add(true);
        final SharedPreferences prefs = await SharedPreferences.getInstance();
        prefs.setString('token', null);
        prefs.setString('patientPhone', phone);
        prefs.setString('patientGuid', responseData['guid']);
        prefs.setString('name', null);
        prefs.setString('lastName', null);
      }
      _isLoading = false;
      notifyListeners();
      return {'success': !hasError, 'message': message};
    }
    void autoAuthenticate() async {
      final SharedPreferences prefs = await SharedPreferences.getInstance();
      final String name = prefs.getString('name');
      final String lastName = prefs.getString('lastName');
      if (name != '' &amp;&amp; lastName != '') {
        final String patientPhone = prefs.getString('patientPhone');
        final String patientGuid = prefs.getString('patientGuid');
        final String token = prefs.getString('token');
        _authenticatedPatient =
            Patient(guid: patientGuid, phone: patientPhone, token: token , name: name , lastName: lastName);
        _patientSubject.add(true);
        notifyListeners();
      }
    }
  
    void logout() async {
      _authenticatedPatient = null;
      _patientSubject.add(false);
      final SharedPreferences prefs = await SharedPreferences.getInstance();
      prefs.remove('token');
      prefs.remove('PatientEmail');
      prefs.remove('PatientId');
    }
  }
  mixin UtilityModel on Connected {
    bool get isLoading {
      return _isLoading;
    }
  }
  </code></pre>
  
  <p>this is the response that i am getting from the api:</p>
  
  <pre><code>{msg: کد ارسال شد, success: true, guid: 15dde915-d752-4bf1-90ad-49872868af35, srcPath: null, thumbPath: null, obj: null}
  </code></pre>
  
  <p>this is the error that i am getting:</p>
  
  <pre><code>I/flutter (10151): NoSuchMethodError: The setter 'msg=' was called on null.
  I/flutter (10151): Receiver: null
  I/flutter (10151): Tried calling: msg="کد ارسال شد"
  E/flutter (10151): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
  E/flutter (10151): NoSuchMethodError: The method '[]' was called on null.
  E/flutter (10151): Receiver: null
  E/flutter (10151): Tried calling: []("success")
  E/flutter (10151): #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
  E/flutter (10151): #1      _AuthOnePageState._submitForm (package:restt/pages/authone.dart:93:27)
  E/flutter (10151): &lt;asynchronous suspension&gt;
  </code></pre>