diff --git a/lib/pages/ModManager.dart b/lib/pages/ModManager.dart index ec8e2a6..4a767ae 100644 --- a/lib/pages/ModManager.dart +++ b/lib/pages/ModManager.dart @@ -88,13 +88,15 @@ class ModManagerState extends State { enabled: mod.enabled)); if (reply != null) { - if (reply is bool) { + ModEditReturnArgs MERA = reply as ModEditReturnArgs; + if (MERA.delete) { setState(() { settings.inst!.mods.removeAt(idx); }); + return; } setState(() { - settings.inst!.mods[idx] = reply as Mod; + settings.inst!.mods[idx] = MERA.mod!; }); } }, @@ -110,10 +112,11 @@ class ModManagerState extends State { final reply = await Navigator.pushNamed(context, "/server/mods/edit", arguments: Mod(newMod: true)); - if (reply != null && reply is! bool) { - Mod mod = reply as Mod; + if (reply != null) { + ModEditReturnArgs MERA = reply as ModEditReturnArgs; + setState(() { - settings.inst!.mods.add(mod); + settings.inst!.mods.add(MERA.mod!); }); } }, @@ -132,7 +135,6 @@ class ModPageState extends State { TextEditingController name = TextEditingController(); String instance = ""; bool isNewMod = false; - bool willDelete = false; String pak = "Not initialized"; String hash = ""; bool enabled = false; @@ -167,17 +169,15 @@ class ModPageState extends State { idVal = int.parse(id.text); } catch (E) {} - if (willDelete) { - Navigator.pop(context, true); - } else { - Navigator.pop( - context, - Mod( - mod_id: idVal, - mod_name: name.text, - newMod: false, - enabled: enabled)); - } + Navigator.pop( + context, + ModEditReturnArgs( + delete: false, + mod: Mod( + mod_id: idVal, + mod_name: name.text, + newMod: false, + enabled: enabled))); }, ), body: SingleChildScrollView( @@ -248,8 +248,7 @@ class ModPageState extends State { if (!isNewMod) ElevatedButton( onPressed: () { - willDelete = true; - Navigator.pop(context); + Navigator.pop(context, ModEditReturnArgs(delete: true)); }, child: Row( children: [ @@ -265,3 +264,10 @@ class ModPageState extends State { ); } } + +class ModEditReturnArgs { + bool delete; + Mod? mod; + + ModEditReturnArgs({required this.delete, this.mod}); +}