-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
358 additions
and
208 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class PopAlert extends StatelessWidget { | ||
const PopAlert({ | ||
super.key, | ||
required this.child, | ||
required this.title, | ||
required this.content, | ||
required this.onConfirm, | ||
this.onDeny, | ||
required this.onCancel, | ||
}); | ||
|
||
final Widget child; | ||
final String title; | ||
final String content; | ||
final void Function() onConfirm; | ||
final void Function()? onDeny; | ||
final void Function() onCancel; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return WillPopScope( | ||
onWillPop: () async { | ||
final shouldPop = await showDialog<bool>( | ||
context: context, | ||
builder: (context) { | ||
return AlertDialog( | ||
title: Text(title), | ||
content: Text(content), | ||
actions: [ | ||
TextButton( | ||
onPressed: () => { | ||
Navigator.of(context).pop(true), | ||
onConfirm(), | ||
}, | ||
child: const Text('是'), | ||
), | ||
if (onDeny != null) | ||
TextButton( | ||
onPressed: () => { | ||
Navigator.of(context).pop(true), | ||
onDeny!(), | ||
}, | ||
child: const Text('否'), | ||
), | ||
TextButton( | ||
onPressed: () => { | ||
Navigator.of(context).pop(false), | ||
onCancel(), | ||
}, | ||
child: const Text('点错了'), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
return shouldPop ?? false; | ||
}, | ||
child: child, | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.