Flutter用户反馈插件app_feedback的使用

Flutter用户反馈插件app_feedback的使用

App Feedback

Open Source Love Hits GitHub code size in bytes GitHub stars GitHub forks

pub package Likes Popularity Pub points

一个用于从用户那里获取应用反馈的Flutter包。它提供了根据需求显示反馈表单的功能。 反馈表单可以即时显示,也可以在一段时间后显示。

下载Demo App

GitHub All Releases

如何使用这个包

1. 在pubspec.yaml文件中添加库

dependencies:
  app_feedback: ^0.0.2

2. 在Dart文件中导入库

import 'package:app_feedback/app_feedback.dart';

3. 创建AppFeedback实例

AppFeedback feedbackForm = AppFeedback.instance;

4. 初始化app反馈(仅当您希望定期询问用户反馈时)

@override
void initState() {
  /// `duration` 设置为10秒用于测试目的。
  /// 您可以根据需要调整此时间间隔,例如15天,1或2个月等。
  feedbackForm.init(FeedbackConfig(duration: Duration(seconds: 10)));
  super.initState();
}

5. 创建一个方法以启动反馈表单

void tryDisplay() {
  feedbackForm.tryDisplay(context, onSubmit: (UserFeedback feedback) {
    print(feedback);
  });
}

6. 创建一个按钮来调用tryDisplay方法

TextButton(
  onPressed: tryDisplay,
  child: Text("Try Display Form")
),

注意事项

  1. feedbackForm仅会在设置的持续时间过后才会显示一次。
  2. 一旦feedbackForm被显示,它将不会再次显示直到下一个持续周期完成。
  3. 第一次初始化feedbackForm时提供的config数据将存储在本地缓存中,其他初始化数据将被忽略。

7. 清除旧配置

如果需要清除旧的config值,请调用clearConfig方法。否则忽略此操作。

void clearConfig() async {
  await feedbackForm.clearConfig();
}

注意事项

  1. 清除配置后,feedbackForm将不会再显示,除非重新初始化。
  2. 清除配置并不意味着重置持续周期。它只是从缓存中移除所有配置。
  3. 要重置持续时间和其他配置,请调用feedbackForm.init()方法并传入新的config值。

即时显示feedbackForm

如果需要随时即时显示feedbackForm,则调用feedbackForm.display方法。 调用此方法不会重置在步骤3中提供的持续时间周期。 无需初始化feedbackForm即可调用以下方法。

void launchAppFeedback() {
  feedbackForm.display(context,
      option: Option(
        maxRating: 10,
        ratingButtonTheme: RatingButtonThemeData.defaultTheme,
      ), onSubmit: (feedback) {
    print(feedback);
  });
}

更多关于Flutter用户反馈插件app_feedback的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter用户反馈插件app_feedback的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


app_feedback 是一个 Flutter 插件,用于在应用中收集用户反馈。它可以帮助开发者轻松地集成用户反馈功能,用户可以通过该插件提交反馈、评分、或者报告问题。以下是如何使用 app_feedback 插件的基本步骤:

1. 添加依赖

首先,在 pubspec.yaml 文件中添加 app_feedback 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  app_feedback: ^1.0.0  # 请检查最新版本

然后运行 flutter pub get 来获取依赖。

2. 导入包

在需要使用 app_feedback 的 Dart 文件中导入包:

import 'package:app_feedback/app_feedback.dart';

3. 初始化插件

在使用插件之前,通常需要初始化它。你可以选择在应用的 main 函数中进行初始化:

void main() {
  runApp(MyApp());
  AppFeedback.initialize(
    iosAppId: 'YOUR_IOS_APP_ID',  // iOS应用的App Store ID
    androidAppId: 'YOUR_ANDROID_APP_ID',  // Android应用的Play Store ID
  );
}

4. 显示反馈对话框

你可以通过调用 AppFeedback.showFeedbackDialog 来显示一个反馈对话框,用户可以在此提交反馈:

AppFeedback.showFeedbackDialog(
  context: context,
  title: 'Send Feedback',  // 对话框标题
  message: 'Please share your feedback with us.',  // 对话框消息
  positiveButtonText: 'Send',  // 正面按钮文本
  negativeButtonText: 'Cancel',  // 负面按钮文本
  onPositiveButtonPressed: (String feedback) {
    // 用户点击“发送”按钮时的回调
    print('User feedback: $feedback');
    // 在这里处理反馈,例如发送到服务器
  },
  onNegativeButtonPressed: () {
    // 用户点击“取消”按钮时的回调
    print('User canceled feedback');
  },
);

5. 显示评分对话框

你还可以通过调用 AppFeedback.showRateDialog 来显示一个评分对话框,用户可以在此对应用进行评分:

AppFeedback.showRateDialog(
  context: context,
  title: 'Rate Us',  // 对话框标题
  message: 'If you enjoy using our app, please take a moment to rate it.',  // 对话框消息
  positiveButtonText: 'Rate Now',  // 正面按钮文本
  negativeButtonText: 'Later',  // 负面按钮文本
  onPositiveButtonPressed: () {
    // 用户点击“立即评分”按钮时的回调
    print('User wants to rate the app');
    // 在这里处理评分逻辑,例如跳转到应用商店
  },
  onNegativeButtonPressed: () {
    // 用户点击“稍后”按钮时的回调
    print('User wants to rate later');
  },
);

6. 处理反馈

用户提交的反馈可以通过 onPositiveButtonPressed 回调进行处理。你可以将反馈发送到服务器、存储在本地,或者通过其他方式处理。

7. 自定义样式

你可以通过传递不同的参数来自定义反馈和评分对话框的样式,例如标题、消息、按钮文本等。

8. 其他功能

app_feedback 插件还提供了其他一些功能,例如:

  • AppFeedback.openStoreListing: 直接打开应用在应用商店的页面。
  • AppFeedback.sendEmail: 打开电子邮件客户端,允许用户通过邮件发送反馈。

示例代码

以下是一个完整的示例,展示了如何使用 app_feedback 插件:

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

void main() {
  runApp(MyApp());
  AppFeedback.initialize(
    iosAppId: 'YOUR_IOS_APP_ID',
    androidAppId: 'YOUR_ANDROID_APP_ID',
  );
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FeedbackScreen(),
    );
  }
}

class FeedbackScreen extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Feedback Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                AppFeedback.showFeedbackDialog(
                  context: context,
                  title: 'Send Feedback',
                  message: 'Please share your feedback with us.',
                  positiveButtonText: 'Send',
                  negativeButtonText: 'Cancel',
                  onPositiveButtonPressed: (String feedback) {
                    print('User feedback: $feedback');
                  },
                  onNegativeButtonPressed: () {
                    print('User canceled feedback');
                  },
                );
              },
              child: Text('Give Feedback'),
            ),
            SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                AppFeedback.showRateDialog(
                  context: context,
                  title: 'Rate Us',
                  message: 'If you enjoy using our app, please take a moment to rate it.',
                  positiveButtonText: 'Rate Now',
                  negativeButtonText: 'Later',
                  onPositiveButtonPressed: () {
                    print('User wants to rate the app');
                  },
                  onNegativeButtonPressed: () {
                    print('User wants to rate later');
                  },
                );
              },
              child: Text('Rate the App'),
            ),
          ],
        ),
      ),
    );
  }
}
回到顶部