Fix mod editor

This commit is contained in:
zontreck 2024-08-28 12:39:49 -07:00
parent 3819b67e34
commit ebcad1f8fc

View file

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