Flutter - Как создать CupertinoAlertDialog - PullRequest
0 голосов
/ 11 октября 2018

Я пытаюсь создать iOS CupertinoAlertDialog в своем проекте Flutter, используя следующий код:

   showDialog(
      context: context,
      builder: (BuildContext context) => new CupertinoAlertDialog(
        title: new Text("Alert"),
        content: new Text("My alert message"),
        actions: [
          CupertinoDialogAction(isDefaultAction: true, child: new Text("Close"))
        ]));

Однако при вызове этого диалогового окна я получаю следующее сообщение об ошибке:

NoSuchMethodError: The getter 'alertDialogLabel' was called on null

Android AlertDialog работает правильно.

Что не так с этим кодом?

1 Ответ

0 голосов
/ 11 октября 2018

Вы создаете метод и оттуда показываете диалог

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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void displayDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) => new CupertinoAlertDialog(
            title: new Text("Alert"),
            content: new Text("My alert message"),
            actions: [
              CupertinoDialogAction(
                  isDefaultAction: true, child: new Text("Close"))
            ],
          ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(child: new Text("Welcome")),
      floatingActionButton: new FloatingActionButton(
        onPressed: displayDialog,
        child: new Icon(Icons.add),
      ),
    );
  }
}
...