Refactor routing methods to Navi helper class
This commit is contained in:
parent
431d91a380
commit
beb1005710
@ -3,6 +3,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:simplecloudnotifier/pages/debug/debug_main.dart';
|
import 'package:simplecloudnotifier/pages/debug/debug_main.dart';
|
||||||
import 'package:simplecloudnotifier/state/app_theme.dart';
|
import 'package:simplecloudnotifier/state/app_theme.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
|
|
||||||
class SCNAppBar extends StatelessWidget implements PreferredSizeWidget {
|
class SCNAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
const SCNAppBar({
|
const SCNAppBar({
|
||||||
@ -43,7 +44,7 @@ class SCNAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
icon: const Icon(FontAwesomeIcons.solidSpiderBlackWidow),
|
icon: const Icon(FontAwesomeIcons.solidSpiderBlackWidow),
|
||||||
tooltip: 'Debug',
|
tooltip: 'Debug',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(context, MaterialPageRoute<DebugMainPage>(builder: (context) => DebugMainPage()));
|
Navi.push(context, () => DebugMainPage());
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,6 +10,7 @@ import 'package:simplecloudnotifier/pages/account/login.dart';
|
|||||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||||
import 'package:simplecloudnotifier/state/globals.dart';
|
import 'package:simplecloudnotifier/state/globals.dart';
|
||||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||||
import 'package:simplecloudnotifier/utils/ui.dart';
|
import 'package:simplecloudnotifier/utils/ui.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
@ -157,7 +158,7 @@ class _AccountRootPageState extends State<AccountRootPage> {
|
|||||||
text: 'Use existing account',
|
text: 'Use existing account',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
Navigator.push(context, MaterialPageRoute<AccountLoginPage>(builder: (context) => AccountLoginPage()));
|
Navi.push(context, () => AccountLoginPage());
|
||||||
},
|
},
|
||||||
tonal: true,
|
tonal: true,
|
||||||
big: true,
|
big: true,
|
||||||
|
@ -8,6 +8,7 @@ import 'package:simplecloudnotifier/state/application_log.dart';
|
|||||||
import 'package:simplecloudnotifier/state/globals.dart';
|
import 'package:simplecloudnotifier/state/globals.dart';
|
||||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||||
import 'package:simplecloudnotifier/state/token_source.dart';
|
import 'package:simplecloudnotifier/state/token_source.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||||
import 'package:simplecloudnotifier/utils/ui.dart';
|
import 'package:simplecloudnotifier/utils/ui.dart';
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ class _AccountLoginPageState extends State<AccountLoginPage> {
|
|||||||
await acc.save();
|
await acc.save();
|
||||||
|
|
||||||
Toaster.success("Login", "Successfully logged in");
|
Toaster.success("Login", "Successfully logged in");
|
||||||
Navigator.popUntil(context, (route) => route.isFirst);
|
Navi.popToRoot(context);
|
||||||
} catch (exc, trace) {
|
} catch (exc, trace) {
|
||||||
ApplicationLog.error('Failed to verify token: ' + exc.toString(), trace: trace);
|
ApplicationLog.error('Failed to verify token: ' + exc.toString(), trace: trace);
|
||||||
Toaster.error("Error", 'Failed to verify token');
|
Toaster.error("Error", 'Failed to verify token');
|
||||||
|
@ -5,6 +5,7 @@ import 'package:simplecloudnotifier/pages/debug/debug_persistence_hive.dart';
|
|||||||
import 'package:simplecloudnotifier/pages/debug/debug_persistence_sharedprefs.dart';
|
import 'package:simplecloudnotifier/pages/debug/debug_persistence_sharedprefs.dart';
|
||||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||||
import 'package:simplecloudnotifier/state/request_log.dart';
|
import 'package:simplecloudnotifier/state/request_log.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
|
|
||||||
class DebugPersistencePage extends StatefulWidget {
|
class DebugPersistencePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -33,7 +34,7 @@ class _DebugPersistencePageState extends State<DebugPersistencePage> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute<DebugSharedPrefPage>(builder: (context) => DebugSharedPrefPage(sharedPref: prefs!)));
|
Navi.push(context, () => DebugSharedPrefPage(sharedPref: prefs!));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
@ -51,7 +52,7 @@ class _DebugPersistencePageState extends State<DebugPersistencePage> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute<DebugHiveBoxPage>(builder: (context) => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNRequest>('scn-requests'))));
|
Navi.push(context, () => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNRequest>('scn-requests')));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
@ -69,7 +70,7 @@ class _DebugPersistencePageState extends State<DebugPersistencePage> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute<DebugHiveBoxPage>(builder: (context) => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNLog>('scn-logs'))));
|
Navi.push(context, () => DebugHiveBoxPage(boxName: 'scn-requests', box: Hive.box<SCNLog>('scn-logs')));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
@ -3,6 +3,7 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||||||
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
|
import 'package:simplecloudnotifier/components/layout/scaffold.dart';
|
||||||
import 'package:simplecloudnotifier/pages/debug/debug_persistence_hiveentry.dart';
|
import 'package:simplecloudnotifier/pages/debug/debug_persistence_hiveentry.dart';
|
||||||
import 'package:simplecloudnotifier/state/interfaces.dart';
|
import 'package:simplecloudnotifier/state/interfaces.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
|
|
||||||
class DebugHiveBoxPage extends StatelessWidget {
|
class DebugHiveBoxPage extends StatelessWidget {
|
||||||
final String boxName;
|
final String boxName;
|
||||||
@ -21,7 +22,7 @@ class DebugHiveBoxPage extends StatelessWidget {
|
|||||||
itemBuilder: (context, listIndex) {
|
itemBuilder: (context, listIndex) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute<DebugHiveEntryPage>(builder: (context) => DebugHiveEntryPage(value: box.getAt(listIndex)!)));
|
Navi.push(context, () => DebugHiveEntryPage(value: box.getAt(listIndex)!));
|
||||||
},
|
},
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(box.getAt(listIndex).toString(), style: TextStyle(fontWeight: FontWeight.bold)),
|
title: Text(box.getAt(listIndex).toString(), style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
@ -3,6 +3,7 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:simplecloudnotifier/pages/debug/debug_request_view.dart';
|
import 'package:simplecloudnotifier/pages/debug/debug_request_view.dart';
|
||||||
import 'package:simplecloudnotifier/state/request_log.dart';
|
import 'package:simplecloudnotifier/state/request_log.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
|
|
||||||
class DebugRequestsPage extends StatefulWidget {
|
class DebugRequestsPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -40,7 +41,7 @@ class _DebugRequestsPageState extends State<DebugRequestsPage> {
|
|||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
|
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => Navigator.push(context, MaterialPageRoute<DebugRequestViewPage>(builder: (context) => DebugRequestViewPage(request: req))),
|
onTap: () => Navi.push(context, () => DebugRequestViewPage(request: req)),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
tileColor: Theme.of(context).colorScheme.errorContainer,
|
tileColor: Theme.of(context).colorScheme.errorContainer,
|
||||||
textColor: Theme.of(context).colorScheme.onErrorContainer,
|
textColor: Theme.of(context).colorScheme.onErrorContainer,
|
||||||
@ -76,7 +77,7 @@ class _DebugRequestsPageState extends State<DebugRequestsPage> {
|
|||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
|
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 2.0),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => Navigator.push(context, MaterialPageRoute<DebugRequestViewPage>(builder: (context) => DebugRequestViewPage(request: req))),
|
onTap: () => Navi.push(context, () => DebugRequestViewPage(request: req)),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -8,6 +8,7 @@ import 'package:simplecloudnotifier/pages/message_view/message_view.dart';
|
|||||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||||
import 'package:simplecloudnotifier/pages/message_list/message_list_item.dart';
|
import 'package:simplecloudnotifier/pages/message_list/message_list_item.dart';
|
||||||
|
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||||
|
|
||||||
class MessageListPage extends StatefulWidget {
|
class MessageListPage extends StatefulWidget {
|
||||||
const MessageListPage({super.key});
|
const MessageListPage({super.key});
|
||||||
@ -83,7 +84,7 @@ class _MessageListPageState extends State<MessageListPage> {
|
|||||||
message: item,
|
message: item,
|
||||||
allChannels: _channels ?? {},
|
allChannels: _channels ?? {},
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(context, MaterialPageRoute<MessageViewPage>(builder: (context) => MessageViewPage(message: item)));
|
Navi.push(context, () => MessageViewPage(message: item));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1 +1,11 @@
|
|||||||
class Navi {}
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Navi {
|
||||||
|
static void push<T extends Widget>(BuildContext context, T Function() builder) {
|
||||||
|
Navigator.push(context, MaterialPageRoute<T>(builder: (context) => builder()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void popToRoot(BuildContext context) {
|
||||||
|
Navigator.popUntil(context, (route) => route.isFirst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user