按下按钮时对我的应用程序评分对话框的实现

问题描述 投票:0回答:1

我想弹出一个窗口来评价我的应用程序,它将把用户重定向到 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)),

最好是像下面这样的对话框。

enter image description here

android flutter dialog
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.