AlertDialog

AlertDialog

AlertDialog({ Widget title, EdgeInsetsGeometry titlePadding, TextStyle titleTextStyle, Widget content, TextStyle contentTextStyle, List actions, Color backgroundColor, double elevation, String semanticLabel, ShapeBorder shape })

açıklama

Bir uyarı pencesi sunar örneğin “İptal” .. “Devam” gibi.

parametreler

Future _neverSatisfied() async {
  return showDialog(
    context: context,
    barrierDismissible: false, // user must tap button!
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text('Rewind and remember'),
        content: SingleChildScrollView(
          child: ListBody(
            children: [
              Text('You will never be satisfied.'),
              Text('You\’re like me. I’m never satisfied.'),
            ],
          ),
        ),
        actions: [
          FlatButton(
            child: Text('Regret'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
      );
    },
  );
}

örnek uygulama

AlertDialog
  
import 'package:flutter/material.dart';
import 'dart:async';

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

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

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

class _MyHomePageState extends State <;; MyHomePage >; {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Flutter Application"),
      ),
      body: new ListTile(
        title: new Text(" "),
        trailing: new RaisedButton(
          child: new Text("Delete"),
          onPressed: _handlePressed,
        ),
      ),
    );
  }

  void _handlePressed() {
    var onYes = () {
      print("~~~ onYes");
    };

    var onNo = () {
      print("~~~ onYes");
    };

    confirmDialog3(context, onYes, onNo).then((_) {
      print("done");
    });
  }
}

Future  confirmDialog1(BuildContext context) {
  return showDialog(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text('Are you sure?'),
          actions: [
            new FlatButton(
              child: const Text('YES'),
              onPressed: () {
                Navigator.of(context).pop(true);
              },
            ),
            new FlatButton(
              child: const Text('NO'),
              onPressed: () {
                Navigator.of(context).pop(false);
              },
            ),
          ],
        );
      });
}

Future
 confirmDialog2(BuildContext context) {
  return showDialog
(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text('Are you sure?'),
          actions: [
            new FlatButton(
              child: const Text('YES'),
              onPressed: () {
                var sendBack = <String, dynamic>{
                  'from': 'Brandon',
                  'value': true,
                };
                Navigator.of(context).pop(sendBack);
              },
            ),
            new FlatButton(
              child: const Text('NO'),
              onPressed: () {
                var sendBack = <String, dynamic>{
                  'from': 'Brandon',
                  'value': false,
                };
                Navigator.of(context).pop(sendBack);
              },
            ),
          ],
        );
      });
}

Future confirmDialog3(BuildContext context, void onNo(), void onYes()) {
  return showDialo(
      context: context,
      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return new AlertDialog(
          title: new Text('Are you sure?'),
          actions: [
            new FlatButton(
              child: const Text('YES'),
              onPressed: () {
                Navigator.of(context).pop();
                onYes();
              },
            ),
            new FlatButton(
              child: const Text('NO'),
              onPressed: () {
                Navigator.of(context).pop();
                onNo();
              },
            ),
          ],
        );
      });
}

Bir cevap yazın

KAPAT
%d blogcu bunu beğendi: