Flutter应用评分引导插件phoenix_appraise的使用

Flutter应用评分引导插件phoenix_appraise的使用

描述

phoenix_appraise 是一个用于 Flutter 应用的评分和反馈引导插件。它提供了多种评分方式,如星级评分、表情列表等,帮助开发者快速集成用户评分功能。


特性

  • 支持星级评分。
  • 提供表情列表选择。
  • 自定义标题和标签。
  • 灵活的弹窗样式。

开始使用

添加依赖

pubspec.yaml 文件中添加以下依赖:

dependencies:
  phoenix_appraise: ^1.0.0

运行以下命令安装依赖:

flutter pub get

示例代码

主文件 (main.dart)

import 'package:flutter/material.dart';
import 'package:phoenix_appraise/phoenix_appraise.dart';

void main() {
  runApp(const MyApp());
}

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

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

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++;
    });

    // 显示星级评分弹窗
    AppraiseStarListView starListView = AppraiseStarListView(
      titles: ['1', '2', '3'],
      count: 3,
    );
    showDialog(context: context, builder: (context) => starListView);

    // 显示表情列表弹窗
    AppraiseEmojiListView emojiListView = AppraiseEmojiListView(
      indexes: const [0, 1, 2, 3, 4],
      titles: const ['1', '2', '3', '4', '5'],
    );
    showDialog(
      context: context,
      builder: (context) => emojiListView,
    );

    // 显示选择器弹窗
    AppraiseBottomPicker bottomPicker = AppraiseBottomPicker(
      title: '选择器',
      tags: const ['tag01', 'tag02', 'tag03', 'tag04'],
    );
    showDialog(context: context, builder: (ctx) => bottomPicker);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('你点击了按钮多少次:'),
            Text('$_counter', style: Theme.of(context).textTheme.headlineMedium),
            AppraiseStarListView(
              titles: ['1', '2', '3'],
              count: 3,
            ),
            AppraiseEmojiListView(
              indexes: const [0, 1, 2, 3, 4],
              titles: const ['1', '2', '3', '4', '5'],
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: '增加次数',
        child: const Icon(Icons.add),
      ),
    );
  }
}

功能详解

星级评分 (AppraiseStarListView)

AppraiseStarListView 是一个用于展示星级评分的控件。用户可以选择从 1 到指定数量的星星。

参数说明

  • titles: 星星对应的标签数组。
  • count: 星星的数量。

示例代码

AppraiseStarListView(
  titles: ['1', '2', '3'],
  count: 3,
)

表情列表 (AppraiseEmojiListView)

AppraiseEmojiListView 是一个用于展示表情列表的控件。用户可以从多个表情中选择一个。

参数说明

  • indexes: 表情对应的索引数组。
  • titles: 表情对应的标签数组。

示例代码

AppraiseEmojiListView(
  indexes: const [0, 1, 2, 3, 4],
  titles: const ['1', '2', '3', '4', '5'],
)

选择器 (AppraiseBottomPicker)

AppraiseBottomPicker 是一个底部弹出的选择器,用户可以从多个标签中选择一个。

参数说明

  • title: 弹窗标题。
  • tags: 可选标签数组。

示例代码

AppraiseBottomPicker(
  title: '选择器',
  tags: const ['tag01', 'tag02', 'tag03', 'tag04'],
)

更多关于Flutter应用评分引导插件phoenix_appraise的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter应用评分引导插件phoenix_appraise的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


phoenix_appraise 是一个用于 Flutter 应用中的评分引导插件,它可以帮助开发者在适当的时机引导用户对应用进行评分。这个插件通常会在用户完成某些关键操作或使用应用一段时间后,弹出一个对话框,提示用户去应用商店评分。

安装

首先,你需要在 pubspec.yaml 文件中添加 phoenix_appraise 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  phoenix_appraise: ^1.0.0  # 请使用最新版本

然后运行 flutter pub get 来安装依赖。

基本使用

  1. 导入插件

    在你的 Dart 文件中导入 phoenix_appraise 插件:

    import 'package:phoenix_appraise/phoenix_appraise.dart';
    
  2. 初始化插件

    在应用的 main 函数中初始化插件:

    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      PhoenixAppraise.initialize(
        appStoreId: 'your_app_store_id',  // 你的应用在 App Store 的 ID
        playStoreId: 'your_play_store_id',  // 你的应用在 Play Store 的 ID
      );
      runApp(MyApp());
    }
    
  3. 显示评分引导

    在适当的时机调用 PhoenixAppraise.showAppraiseDialog 方法来显示评分引导对话框:

    void showRatingDialog() {
      PhoenixAppraise.showAppraiseDialog(
        context: context,
        title: '喜欢这个应用吗?',
        message: '请给我们评分,帮助我们改进!',
        positiveButtonText: '去评分',
        negativeButtonText: '稍后再说',
        onPositiveButtonPressed: () {
          // 用户点击了“去评分”按钮
          PhoenixAppraise.launchStore();
        },
        onNegativeButtonPressed: () {
          // 用户点击了“稍后再说”按钮
        },
      );
    }
    
  4. 自定义对话框

    你可以自定义对话框的样式和行为,例如设置对话框的标题、消息、按钮文本等。

高级用法

  • 设置显示条件

    你可以通过设置条件来控制评分引导的显示频率。例如,只有在用户完成某些操作或使用应用达到一定次数后才显示评分引导。

    void checkAndShowRatingDialog() {
      if (shouldShowRatingDialog()) {
        PhoenixAppraise.showAppraiseDialog(
          context: context,
          title: '喜欢这个应用吗?',
          message: '请给我们评分,帮助我们改进!',
          positiveButtonText: '去评分',
          negativeButtonText: '稍后再说',
          onPositiveButtonPressed: () {
            PhoenixAppraise.launchStore();
          },
          onNegativeButtonPressed: () {
            // 用户点击了“稍后再说”按钮
          },
        );
      }
    }
    
    bool shouldShowRatingDialog() {
      // 自定义逻辑,例如检查用户是否已经评分过,或者是否达到了显示条件
      return true;
    }
    
  • 处理用户反馈

    你可以在用户点击“去评分”或“稍后再说”按钮后执行一些操作,例如记录用户的选择或调整应用的设置。

注意事项

  • 用户体验:评分引导应该在用户对应用有积极体验时显示,避免在用户遇到问题或刚安装应用时弹出。
  • 频率控制:避免频繁弹出评分引导,以免影响用户体验。可以通过设置条件来控制显示频率。
  • 平台差异:确保在 iOS 和 Android 平台上都能正确跳转到应用商店。

示例代码

以下是一个完整的示例代码,展示了如何在 Flutter 应用中使用 phoenix_appraise 插件:

import 'package:flutter/material.dart';
import 'package:phoenix_appraise/phoenix_appraise.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  PhoenixAppraise.initialize(
    appStoreId: 'your_app_store_id',
    playStoreId: 'your_play_store_id',
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Phoenix Appraise Example'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              showRatingDialog(context);
            },
            child: Text('Show Rating Dialog'),
          ),
        ),
      ),
    );
  }
}

void showRatingDialog(BuildContext context) {
  PhoenixAppraise.showAppraiseDialog(
    context: context,
    title: '喜欢这个应用吗?',
    message: '请给我们评分,帮助我们改进!',
    positiveButtonText: '去评分',
    negativeButtonText: '稍后再说',
    onPositiveButtonPressed: () {
      PhoenixAppraise.launchStore();
    },
    onNegativeButtonPressed: () {
      // 用户点击了“稍后再说”按钮
    },
  );
}
回到顶部