Home > Software engineering >  Sharing data between two different classes
Sharing data between two different classes

Time:04-22

I am new to dart/flutter and need help with a part of my app that deals with authentication. I need to move the value of a variable to another class that contains a variable i am using in another part of my app. Here is the first part of my code that contains the variable 'basicAuth'. I need to migrate the result of the base64encode to a different class.

Widget build(BuildContext context) {
void _login(AuthController authController) {
  String username = phoneNumberController.text.trim();
  String password = passwordController.text.trim();
  String basicAuth =
      'Basic '   base64Encode(utf8.encode('$username:$password'));
      setState(() {
        
      });
      print(basicAuth);

I need to move the value of basicAuth to AppConstants.BASIC_AUTH located here:

  static const String APP_NAME = "";
  static const int APP_VERSION = 1;
  static const String BASE_URL = "";
  static const String DEVICE_LIST_URI = "/device";

  //auth end points
  static const String REGISTRATION_URI = "/users";
  static const String LOGIN_URI = "";

  static const String TOKEN = "";
  static const String API_KEY = "";
  static const String PHONE = "";
  static const String PASSWORD = "";
  static const String BASIC_AUTH = "";
}


CodePudding user response:

//import AppConstants file

String basicAuth =
      'Basic '   base64Encode(utf8.encode('$username:$password'));
      setState(() {
        
      });
      print(basicAuth);
AppConstants.BASIC_AUTH = basicAuth;
  • Related