搜索插件、代码仓与 APP 分类

flavor 封面
插件详情v2.0.0

flavor

一种轻松配置风味设置并显示风味横幅的方法。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1040
喜欢数
56
Pub 分数
160

安装插件

flutter pub add flavor

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flavor 是一个 Flutter 包,可简化应用程序风味的配置,并在调试构建中显示可见的风味横幅。它通过在屏幕上显示可自定义的横幅,使开发者能够轻松区分不同的构建变体(如开发、预发布和生产)。该横幅在发布构建中会自动隐藏,确保用户获得干净的体验。非常适合管理多个环境的团队,可简化设置并在测试期间提高可见性。

适合场景

  • 调试不同的构建环境
  • 识别开发版与生产版构建
  • 在测试期间显示环境信息
  • 按口味自定义横幅
  • 在多环境项目中提升团队协作

主要特点

  • 轻松的口味配置
  • 调试模式下自动显示横幅
  • 可自定义的横幅外观
  • 支持所有 Flutter 平台
  • 在发布版本中隐藏横幅

适合对象

  • 开发人员在处理多个应用版本时
  • 团队在测试不同的环境
  • 需要明确构建标识的应用程序
  • 带有 CI/CD 流水线的 Flutter 项目
  • 开发过程中需要视觉反馈的项目

使用建议

  • 横幅仅在调试版本中显示
  • 需要为新口味进行手动设置
  • 可能需要对复杂 UI 进行样式调整
  • 不适用于生产环境
  • 超出基本横幅属性的自定义功能有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flavor

pub package build Buy Me A Coffee

A Flutter plugin for configuring flavor settings and optionally display a flavor banner on the app.

Flavors

Each app needs some kind of flavor during its development lifecycle. You often have an api you use that is different during dev, beta, production, or log settings for example. That's when flavors come in.

Setup flavors

You can define different start main methods, each can be configured with a flavor.

So for example, you can create a main_dev.dart file for your development environment:

void main() {
  Flavor.create(
    Environment.dev,
    color: Colors.green,
    name: 'PREVIEW',
    properties: {
      Keys.apiUrl: 'https://api.dev.company.com',
      Keys.apiKey: 'jksdhfkjhs83rjkh324kj23h4',
      logLevelKey: 100,
    },
  );
  setupApp();
}

And a main_prod.dart file for your production environment:

void main() {
  Flavor.create(
    Environment.production,
    properties: {
      Keys.apiUrl: 'https://api.company.com',
      Keys.apiKey: 'lksdhjfkjhdsf8sdfjkhsdf896',
      logLevelKey: 5,
    },
  );
  setupApp();
}

Each of these files will point to another main.dart file:

void setupApp() {
  final logLevel = Flavor.I.getInt(logLevelKey);
  print('LogLevel set for this flavor: $logLevel');
  runApp(FlavorApp());
}
How does it look?
DEV BETA PROD

Note that in the PROD flavor no flavor banner is showed.

launch.json

In Visual Code you can define following to use the different flavors:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "DEV",
			"request": "launch",
			"type": "dart",
			"program": "example/lib/main_dev.dart",
			// "args": [
			// 	"--flavor",
			// 	"dev"
			// ]
		},
		{
			"name": "BETA",
			"request": "launch",
			"type": "dart",
			"program": "example/lib/main_beta.dart",
			// "args": [
			// 	"--flavor",
			// 	"beta"
			// ]
		},
		{
			"name": "PRD",
			"request": "launch",
			"type": "dart",
			"program": "example/lib/main_prod.dart",
			// "args": [
			// 	"--flavor",
			// 	"prod"
			// ]
		},
	]
}

Note: The args keys are currently commented. These only works if you created the flavors in the iOS / Android native projects too.

Extras

You can also define additional properties for each flavor/configuration. This is handy to store url's, api keys, etc. Further in your app you can access these values.

Flavor.I.getString(Keys.apiUrl)

The package has some default Keys at the moment which will be extended over time. The defaults: apiUrl, apiKey, appTitle

Of course you can add custom keys yourself as showed in the example.

Or you can check what flavor is currently running:

if (Flavor.I.isDevelopment) {
// do something nice in development
}

Checkout the example folder for a complete setup.

Flavorize your bundleids and assets

If you want to change bundle ids, or even assets (icon, splash screen) check out flutter_flavorizr. This nice tool will help you create flavors in Android and iOS.

API Documentation

API documentation can be found here

所属分类

源码仓库

使用此插件的项目

暂无相关数据。