Skip to content

gzeinnumer/flutter_alert_dialog_callback

Repository files navigation

flutter_alert_dialog_callback

showDialog(
  context: context,
  builder: (context) => ExamplesDialog(),
).then((value) {
  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
    content: Text(value),
  ));
});
class ExamplesDialog extends StatelessWidget {
  final _editTextController = TextEditingController();
  ExamplesDialog({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('Are you sure?'),
      content: Wrap(
        children: [
          TextFormField(
            controller: _editTextController,
            decoration: const InputDecoration(hintText: "Hint"),
          )
        ],
      ),
      actions: <Widget>[
        TextButton(
          onPressed: () => Navigator.of(context).pop('NO'),
          child: const Text('NO'),
        ),
        TextButton(
          onPressed: () => Navigator.of(context).pop(_editTextController.text),
          child: const Text('YES'),
        )
      ],
    );
  }
}

Copyright 2023 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published