Last active
January 4, 2022 15:11
-
-
Save edemekong/1bf6c03d3cb2477c20c9f15d72746668 to your computer and use it in GitHub Desktop.
Track Dialog Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class MyAlertDialog extends StatelessWidget { | |
final String title; | |
final String content; | |
final String buttonText1; | |
final String? buttonText2; | |
final void Function(bool v) callback; | |
const MyAlertDialog( | |
{Key? key, | |
required this.title, | |
required this.content, | |
required this.buttonText1, | |
this.buttonText2, | |
required this.callback}) | |
: super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return AlertDialog( | |
title: Text(title), | |
content: Text(content), | |
actions: <Widget>[ | |
TextButton( | |
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.green)), | |
child: Text(buttonText1, style: const TextStyle(color: Colors.white)), | |
onPressed: () { | |
///When a user taps on [YES] | |
callback(true); | |
Navigator.pop(context); | |
}, | |
), | |
if (buttonText2 != null) | |
TextButton( | |
child: Text("$buttonText2", style: const TextStyle(color: Colors.black)), | |
onPressed: () { | |
///When a user taps on [NO] | |
callback(false); | |
Navigator.pop(context); | |
}, | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment