title: How to setup a base URL and where do I declare it in flutter dio for api calls?
body: <p><strong>like how to fix boilerplate code in separate file and use it in ui pages.</strong></p>
  <blockquote>
  <p><strong>I Need to declare this uri variable in separate file and access across over all pages:</strong></p>
  </blockquote>
  <pre><code>  static var uri = &quot;https://xxx/xxx/web_api/public&quot;;
    static BaseOptions options = BaseOptions(
    baseUrl: uri,
    responseType: ResponseType.plain,
    connectTimeout: 30000,
    receiveTimeout: 30000,
    // ignore: missing_return
    validateStatus: (code) {
      if (code &gt;= 200) {
        return true;
      }
    });  static Dio dio = Dio(options);
  </code></pre>
  <p><strong>In UI page i have to declare that uri variable and BaseOption variable in this future function:</strong></p>
  <pre><code>   Future&lt;dynamic&gt; _loginUser(String email, String password) async {
       try {
    Options options = Options(
      headers: {&quot;Content-Type&quot;: &quot;application/json&quot;},
    );
    Response response = await dio.post('/login',
        data: {
          &quot;email&quot;: email,
          &quot;password&quot;: password,
          &quot;user_type&quot;: 2,
          &quot;status&quot;: 1
        },
        options: options);
  
    if (response.statusCode == 200 || response.statusCode == 201) {
      var responseJson = json.decode(response.data);
      return responseJson;
    } else if (response.statusCode == 401) {
      throw Exception(&quot;Incorrect Email/Password&quot;);
    } else
      throw Exception('Authentication Error');
  } on DioError catch (exception) {
    if (exception == null ||
        exception.toString().contains('SocketException')) {
      throw Exception(&quot;Network Error&quot;);
    } else if (exception.type == DioErrorType.RECEIVE_TIMEOUT ||
        exception.type == DioErrorType.CONNECT_TIMEOUT) {
      throw Exception(
          &quot;Could'nt connect, please ensure you have a stable network.&quot;);
    } else {
      return null;
    }
  }
  </code></pre>
  <p>}</p>