Setting environment variables in Flutter

后端 未结 4 1615
野趣味
野趣味 2020-12-16 09:24

For example, building a client for an API, like Twitch.

In a Dart CLI binary, I could use a generic environment variable, or a Dart definition variable. For example,

4条回答
  •  再見小時候
    2020-12-16 10:10

    Create a class:

    import 'package:flutter/foundation.dart';
    
    class AppUtils {
      static String get clientId {
        if (kDebugMode) return 'debug_id';
        else if (kProfileMode) return 'profile_id';
        else if (kReleaseMode) return 'production_id';
        else if (kIsWeb) return 'web_mode_id';
        
        throw ArgumentError('No mode detected');
      }
    }
    

    Usage:

    var id = AppUtils.clientId;
    

提交回复
热议问题