搜尋套件、儲存庫與 APP 分類

flutter_flavor 封面
套件詳情v3.1.4

flutter_flavor

我們可以建立不同的版本,進而於發布到 App Store 與 Google Play 之前,擁有應用程式的不同實例。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3.4萬
喜歡數
479
Pub 分數
160

安裝套件

flutter pub add flutter_flavor

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_flavor 是一個開發者工具,可建立不同的應用風味,讓您在發布到應用商店之前,為各種環境(例如開發、測試和生產)提供不同的設定與建構。它簡化了管理特定環境設定(如 API 端點、記錄層級和品牌識別)的過程,無需複製程式碼。此套件與 Flutter 的建構系統無縫整合,支援所有受支援的平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它幫助團隊維持乾淨且可配置的工作流程,以進行測試與部署。

適用情境

  • 管理多個環境
  • 自定義建構設定
  • 發布前測試
  • 分離開發/預發布/生產環境設定
  • 優化CI/CD流程

主要特色

  • 環境特定的設定
  • 跨平台支援
  • 與 Flutter 的輕鬆整合
  • 建構時風味區分
  • 最小化樣板程式碼

適合對象

  • 開發團隊
  • CI/CD 工作流
  • 多環境應用
  • 依版本的應用程式自訂
  • 使用不同部署階段的團隊

使用建議

  • 需要在建構腳本中進行設定
  • 口味名稱必須在各平台上保持一致
  • 有限的執行時間切換
  • 不適用於面向使用者的口味選擇
  • 需要團隊成員之間的協調

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_flavor

pub package Star on Github License: MIT

Flavors helps us to create builds for different instances of our app. For example, we can create a flavor for development, a flavor for production and another flavor for a demo of the app. In this way we can create different flavors, and thus have different instances of our apps before publishing it on the App Store and Google Play.

flutter_favor allows you to quickly configure and define dynamic variables for each flavor in your project. The flavors, as well as their names; they are dynamically defined by the developer or development team. In the configuration of a flavor you can set the name of each flavor, as well as the color and location of its banner. When attribute name is undefined or empty, the banner is hidden.

You can also configure the banners independently. The aforementioned attributes are globally configured in FlavorConfig, but can be changed in the FlavorBanner.

Screenshot

PROD DEV TEST
Screenshot Prod Screenshot Dev Screenshot Test

Note By default the banner is shown in BannerLocation.topStart and is visibility only when the attribute name of configuration is defined and not empty.

Getting Started

Adding package
flutter_flavor: ^3.1.4
Importing package
import 'package:flutter_flavor/flutter_flavor.dart';
Configuring
FlavorConfig(
    name: "DEVELOP",
    color: Colors.red,
    location: BannerLocation.bottomStart,
    variables: {
        "counter": 0,
        "baseUrl": "https://www.example.com",
    }
);
Using variables
 int _counter = FlavorConfig.instance.variables["counter"];

Example

Main
import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';

import 'app.dart';

void main() {
  FlavorConfig(
    name: "DEVELOP",
    color: Colors.red,
    location: BannerLocation.topStart,
    variables: {
      "counter": 5,
      "baseUrl": "https://www.example2.com",
    },
  );

  runApp(const MyApp());
}
App
import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return FlavorBanner(
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

VSCode Configuration

The .vscode folder is created in the workspace, if it does not exist it can be created by hand. Inside that folder a launch.json file is created and the configuration is established inside the file. For more information, visit: https://code.visualstudio.com/docs/editor/debugging and https://go.microsoft.com/fwlink/?linkid=830387

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "PROD-Flavor",
      "program": "[project-folder]/lib/main_prod.dart",
      "request": "launch",
      "type": "dart"
    },
    {
      "name": "DEV-Flavor",
      "program": "[project-folder]/lib/main_dev.dart",
      "request": "launch",
      "type": "dart"
    }
  ]
}

License

MIT License

所屬分類

原始碼儲存庫

使用此套件的專案