From 89c0b069e12be87ff6d6167d7d308b2ef76c6fdd Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Tue, 4 Apr 2023 20:33:49 +0200 Subject: [PATCH] Formatted some files --- lib/screens/room/categories/edit.dart | 18 ++++++++++++------ lib/screens/room/main.dart | 17 +++++++++-------- lib/screens/room/pages/categories.dart | 2 +- lib/tools/fetch_wrapper.dart | 8 +++++--- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/screens/room/categories/edit.dart b/lib/screens/room/categories/edit.dart index 75626c4..ede33f3 100644 --- a/lib/screens/room/categories/edit.dart +++ b/lib/screens/room/categories/edit.dart @@ -12,9 +12,9 @@ import 'dart:math'; class EditCategoryPage extends StatefulWidget { final String server; final String tag; - int? id; + final int? id; - EditCategoryPage(this.server, this.tag, {super.key, this.id}); + const EditCategoryPage(this.server, this.tag, {super.key, this.id}); @override State createState() => _EditCategoryPageState(); @@ -30,7 +30,13 @@ class _EditCategoryPageState extends State { void initState() { super.initState(); - WidgetsBinding.instance.addPostFrameCallback((_) => fetchCategory()); + WidgetsBinding.instance.addPostFrameCallback((_) { + if (widget.id == null) { + // trying to create a new category + return; + } + fetchCategory(); + }); } void fetchCategory() { @@ -46,7 +52,8 @@ class _EditCategoryPageState extends State { body: { 'room': widget.tag, 'server': widget.server, - 'listCatID': widget.id}), + 'listCatID': widget.id + }), onOK: (json) { setState(() { _ctrName.text = json['data']['title']; @@ -241,8 +248,7 @@ class _EditCategoryPageState extends State { label: Text((widget.id == null) ? AppLocalizations.of(context)!.newCategoryShort : AppLocalizations.of(context)!.editCategoryShort), - icon: Icon((widget.id == null) - ? Icons.add : Icons.edit)), + icon: Icon((widget.id == null) ? Icons.add : Icons.edit)), ); } } diff --git a/lib/screens/room/main.dart b/lib/screens/room/main.dart index fbd9ba9..2bba06f 100644 --- a/lib/screens/room/main.dart +++ b/lib/screens/room/main.dart @@ -76,6 +76,11 @@ class _RoomPageState extends State { void initState() { super.initState(); + room = Room( + id: widget.tag, + serverTag: widget.server + ); + _ctr.addListener(() { setState(() { page = _ctr.page?.toInt() ?? _ctr.initialPage; @@ -126,23 +131,19 @@ class _RoomPageState extends State { NavigationDestination( icon: const Icon(Icons.list), label: AppLocalizations.of(context)!.roomListTitle, - tooltip: AppLocalizations.of(context)!.roomListSubtitle - ), + tooltip: AppLocalizations.of(context)!.roomListSubtitle), NavigationDestination( icon: const Icon(Icons.inventory_2), label: AppLocalizations.of(context)!.roomProductsTitle, - tooltip: AppLocalizations.of(context)!.roomProductsSubtitle - ), + tooltip: AppLocalizations.of(context)!.roomProductsSubtitle), NavigationDestination( icon: const Icon(Icons.category), label: AppLocalizations.of(context)!.roomCategoriesTitle, - tooltip: AppLocalizations.of(context)!.roomCategoriesSubtitle - ), + tooltip: AppLocalizations.of(context)!.roomCategoriesSubtitle), NavigationDestination( icon: const Icon(Icons.info_rounded), label: AppLocalizations.of(context)!.roomAboutTitle, - tooltip: AppLocalizations.of(context)!.roomAboutSubtitle - ), + tooltip: AppLocalizations.of(context)!.roomAboutSubtitle), ], ), ); diff --git a/lib/screens/room/pages/categories.dart b/lib/screens/room/pages/categories.dart index b722fce..beafb7d 100644 --- a/lib/screens/room/pages/categories.dart +++ b/lib/screens/room/pages/categories.dart @@ -123,7 +123,7 @@ class _RoomCategoriesPageState extends State { context.pushNamed('edit-category', params: { 'server': widget.room!.serverTag, 'id': widget.room!.id, - 'cid': item.id.toString() + 'category': item.id.toString() }); }, ), diff --git a/lib/tools/fetch_wrapper.dart b/lib/tools/fetch_wrapper.dart index 7e35bda..5ac8939 100644 --- a/lib/tools/fetch_wrapper.dart +++ b/lib/tools/fetch_wrapper.dart @@ -5,14 +5,15 @@ import 'package:outbag_app/tools/snackbar.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; Future doNetworkRequest(ScaffoldMessengerState? sm, - {required Future Function() req, + {required Future Function() req, Function(Map body)? onOK, bool Function()? onNetworkErr, bool Function()? onUnknownErr, Function()? onAnyErr, Function()? after, bool Function(Map)? onServerErr}) async { - AppLocalizations? trans = (sm!=null)?AppLocalizations.of(sm.context):null; + AppLocalizations? trans = + (sm != null) ? AppLocalizations.of(sm.context) : null; Response res; try { @@ -50,7 +51,8 @@ Future doNetworkRequest(ScaffoldMessengerState? sm, showBar = onServerErr(res.body); } if (showBar && sm != null) { - showSimpleSnackbar(sm, text: errorAsString(res.body, trans!), action: trans.ok); + showSimpleSnackbar(sm, + text: errorAsString(res.body, trans!), action: trans.ok); } if (onAnyErr != null) { onAnyErr();