如何使用Flutter在Android中显示iOS / cupertino警报对话框?

时间:2018-11-24 18:40:03

标签: dart flutter

我试图在Flutter应用中显示一个iOS主题对话框,但我在文档中找不到任何内容

4 个答案:

答案 0 :(得分:5)

Android主题/样式的关键字为材料(默认设计),iOS主题/样式的关键字为 Cupertino 。每个iOS主题小部件都有前缀 Cupertino 。因此,根据您的要求,我们可以猜测关键字为 CupertinoDialog / CupertinoAlertDialog

您可以在这里查阅所有https://flutter.io/docs/reference/widgets/cupertino

new CupertinoAlertDialog(
  title: new Text("Dialog Title"),
  content: new Text("This is my content"),
  actions: <Widget>[
    CupertinoDialogAction(
      isDefaultAction: true,
      child: Text("Yes"),
    ),
    CupertinoDialogAction(
      child: Text("No"),
    )
  ],
)

答案 1 :(得分:5)

我在 ShowDialog 中使用了 CupertinoAlertDialog ,您可以在下面找到

showDialog(
      context: context,
      builder: (BuildContext context) => CupertinoAlertDialog(
        title: new Text("Dialog Title"),
        content: new Text("This is my content"),
        actions: <Widget>[
          CupertinoDialogAction(
            isDefaultAction: true,
            child: Text(StringConstants.BIOMETRICAUTHORIZED),
          ),
          CupertinoDialogAction(
            child: Text("No"),
          )
        ],
      )
    );

答案 2 :(得分:3)

首先,您要检查platForm ios还是android ..然后返回当前设备的小部件..

import pandas as pd
import numpy as np
x = pd.DataFrame({'Code':['a', 'a', 'a', 'b', 'b', 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'a'], 'Value': np.arange(13)})

   Code  Value
0     a      0
1     a      1
2     a      2
3     b      3
4     b      4
5     a      5
6     a      6
7     a      7
8     b      8
9     b      9
10    b     10
11    a     11
12    a     12

答案 3 :(得分:2)

下面是一个简单的示例,说明如何在Flutter中使用两个按钮创建简单的警报,

导入import 'package:flutter/cupertino.dart';,然后复制并粘贴以下代码,并在要显示对话框的位置将其命名为showAlertDialog(context);

here is my result

void showAlertDialog(BuildContext context) {

  showDialog(
    context: context,
    child:  CupertinoAlertDialog(
      title: Text("Log out?"),
      content: Text( "Are you sure you want to log out?"),
      actions: <Widget>[
        CupertinoDialogAction(
            isDefaultAction: true,
            onPressed: (){
              Navigator.pop(context);
            },
            child: Text("Cancel")
        ),
        CupertinoDialogAction(
          textStyle: TextStyle(color: Colors.red),
            isDefaultAction: true,
            onPressed: () async {
              Navigator.pop(context);
              SharedPreferences prefs = await SharedPreferences.getInstance();
              prefs.remove('isLogin');
              Navigator.pushReplacement(context,
                  MaterialPageRoute(builder: (BuildContext ctx) => LoginScreen()));
            },
            child: Text("Log out")
        ),
      ],
    ));
}