2021-12-23 12:36:09 +01:00
|
|
|
import 'dart:async';
|
2021-11-17 06:20:23 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gecko/globals.dart';
|
|
|
|
import 'package:gecko/models/chest_data.dart';
|
|
|
|
|
|
|
|
class ChestProvider with ChangeNotifier {
|
|
|
|
void rebuildWidget() {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future deleteChest(context, ChestData _chest) async {
|
2021-12-23 21:44:24 +01:00
|
|
|
final bool? _answer = await (_confirmDeletingChest(context, _chest.name));
|
2021-11-17 06:20:23 +01:00
|
|
|
|
2021-12-23 21:44:24 +01:00
|
|
|
if (_answer!) {
|
2021-11-18 02:37:46 +01:00
|
|
|
await chestBox.delete(_chest.key);
|
|
|
|
if (chestBox.isEmpty) {
|
|
|
|
await configBox.put('currentChest', 0);
|
|
|
|
} else {
|
2021-12-23 12:36:09 +01:00
|
|
|
int? lastChest = chestBox.toMap().keys.first;
|
2021-11-18 02:37:46 +01:00
|
|
|
await configBox.put('currentChest', lastChest);
|
|
|
|
}
|
2021-11-17 06:20:23 +01:00
|
|
|
|
|
|
|
Navigator.popUntil(
|
|
|
|
context,
|
|
|
|
ModalRoute.withName('/'),
|
|
|
|
);
|
2021-11-18 02:37:46 +01:00
|
|
|
notifyListeners();
|
2021-11-17 06:20:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
Future<bool?> _confirmDeletingChest(context, String? _walletName) async {
|
2021-11-17 06:20:23 +01:00
|
|
|
return showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true, // user must tap button!
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(
|
|
|
|
'Êtes-vous sûr de vouloir supprimer le coffre "$_walletName" ?'),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: const Text("Non", key: Key('cancelDeleting')),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, false);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: const Text("Oui", key: Key('confirmDeleting')),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|