我想弹出一个窗口来评价我的应用程序,它将把用户重定向到 Google Play 商店。
我目前已经放置了一个代码,可以让用户通过单击按钮直接进入 Playstore。
onPressed: () async {
const String packageName = 'com.mycompany.refereevision'; // Replace with your app's package name
const String url = 'https://play.google.com/store/apps/details?id=$packageName';
if (await launchURL(url)) {
await launchURL(url);
} else {
throw 'Could not launch $url';
}
},
),
),
].divide(SizedBox(height: 30.0)),
最好是像下面这样的对话框。
您可以使用AlertDialog小部件
import 'package:flutter/material.dart';
/// Flutter code sample for [AlertDialog].
void main() => runApp(const AlertDialogExampleApp());
class AlertDialogExampleApp extends StatelessWidget {
const AlertDialogExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('AlertDialog Sample')),
body: const Center(
child: DialogExample(),
),
),
);
}
}
class DialogExample extends StatelessWidget {
const DialogExample({super.key});
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: const Text('AlertDialog description'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
),
child: const Text('Show Dialog'),
);
}
}
参考:https://api.flutter.dev/flutter/material/AlertDialog-class.html