Skip to content

Instantly share code, notes, and snippets.

@GursheeshSingh
Created April 5, 2020 13:17
Show Gist options
  • Save GursheeshSingh/23bba5f75f64feb89d2e8b87efab56f4 to your computer and use it in GitHub Desktop.
Save GursheeshSingh/23bba5f75f64feb89d2e8b87efab56f4 to your computer and use it in GitHub Desktop.
typedef Future<bool> OnDeleteClicked();
class DeleteWidget extends StatefulWidget {
final OnDeleteClicked onDeleteClicked;
DeleteWidget(this.onDeleteClicked);
@override
_DeleteWidgetState createState() => _DeleteWidgetState();
}
class _DeleteWidgetState extends State<DeleteWidget> {
bool isDeleting = false;
void stopDeleting() {
setState(() {
isDeleting = false;
});
}
void startDeleting() {
setState(() {
isDeleting = true;
});
}
_onDeleteWidgetClicked() async {
print('DELETING');
startDeleting();
bool isDeleted = await widget.onDeleteClicked();
stopDeleting();
print('DELETED');
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _onDeleteWidgetClicked,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Visibility(
visible: isDeleting,
child: SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.redAccent),
strokeWidth: 4.0,
),
),
),
Visibility(
visible: isDeleting == false,
child: Icon(
MaterialCommunityIcons.delete,
color: Colors.redAccent,
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment