gpt4 book ai didi

flutter - 在 flutter 中使用 rate_my_app 包?

转载 作者:行者123 更新时间:2023-12-05 02:58:45 33 4
gpt4 key购买 nike

谁能告诉我,你是如何使用rate_my_app https://pub.dev/packages/rate_my_app的打包在flutter app中增加用户评价?

示例代码会很有用吗?

最佳答案

rate_my_app 只是一个提醒用户对您的应用进行评分的插件。如果您的应用满足了用户的需求,就会增加用户的正面评价。

示例代码 Skyost :

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

/// Main rate my app instance.
RateMyApp _rateMyApp = RateMyApp();

/// First plugin test method.
void main() {
_rateMyApp.init().then((_) {
runApp(_RateMyAppTestApp());
print('Minimum days : ' + _rateMyApp.minDays.toString());
print('Minimum launches : ' + _rateMyApp.minLaunches.toString());

print('Base launch : ' + _dateToString(_rateMyApp.baseLaunchDate));
print('Launches : ' + _rateMyApp.launches.toString());
print('Do not open again ? ' + (_rateMyApp.doNotOpenAgain ? 'Yes' : 'No'));

print('Are conditions met ? ' + (_rateMyApp.shouldOpenDialog ? 'Yes' : 'No'));
});
}

/// Returns a formatted date string.
String _dateToString(DateTime date) => date.day.toString().padLeft(2, '0') + '/' + date.month.toString().padLeft(2, '0') + '/' + date.year.toString();

/// The main rate my app test widget.
class _RateMyAppTestApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Rate my app !'),
),
body: _RateMyAppTestAppBody(),
),
);
}

/// The body of the main rate my app test widget.
class _RateMyAppTestAppBody extends StatefulWidget {
@override
State<StatefulWidget> createState() => _RateMyAppTestAppBodyState();
}

/// The body state of the main rate my app test widget.
class _RateMyAppTestAppBodyState extends State<_RateMyAppTestAppBody> {
@override
Widget build(BuildContext context) => Padding(
padding: EdgeInsets.symmetric(
horizontal: 40,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_textCenter('Minimum days : ' + _rateMyApp.minDays.toString()),
_textCenter('Minimum launches : ' + _rateMyApp.minLaunches.toString()),
_textCenter('Base launch : ' + _dateToString(_rateMyApp.baseLaunchDate)),
_textCenter('Launches : ' + _rateMyApp.launches.toString()),
_textCenter('Do not open again ? ' + (_rateMyApp.doNotOpenAgain ? 'Yes' : 'No')),
_textCenter('Are conditions met ? ' + (_rateMyApp.shouldOpenDialog ? 'Yes' : 'No')),
Padding(
padding: EdgeInsets.only(top: 10),
child: RaisedButton(
child: Text('Launch "Rate my app" dialog'),
onPressed: () => _rateMyApp.showRateDialog(context).then((v) => setState(() {})),
),
),
RaisedButton(
child: Text('Launch "Rate my app" star dialog'),
onPressed: () => _rateMyApp.showStarRateDialog(context, onRatingChanged: (count) {
FlatButton cancelButton = FlatButton(
child: Text('CANCEL'),
onPressed: () {
_rateMyApp.doNotOpenAgain = true;
_rateMyApp.save().then((v) => Navigator.pop(context));
setState(() {});
},
);

if (count == null || count == 0) {
return [cancelButton];
}

String message = 'You put ' + count.round().toString() + ' star(s). ';
Color color;
switch (count.round()) {
case 1:
message += 'Did this app hurt you physically ?';
color = Colors.red;
break;
case 2:
message += 'That\'s not really cool man.';
color = Colors.orange;
break;
case 3:
message += 'Well, it\'s average.';
color = Colors.yellow;
break;
case 4:
message += 'This is cool, like this app.';
color = Colors.lime;
break;
case 5:
message += 'Great ! <3';
color = Colors.green;
break;
}

return [
FlatButton(
child: Text('OK'),
onPressed: () {
print(message);
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: color,
),
);
_rateMyApp.doNotOpenAgain = true;
_rateMyApp.save().then((v) => Navigator.pop(context));
setState(() {});
},
),
cancelButton,
];
}),
),
RaisedButton(
child: Text('Reset'),
onPressed: () => _rateMyApp.reset().then((v) => setState(() {})),
),
],
),
);

/// Returns a centered text.
Text _textCenter(String content) => Text(
content,
textAlign: TextAlign.center,
);
}

GitHub code

关于flutter - 在 flutter 中使用 rate_my_app 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58653835/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com