From 4da80f94ef2a6f176e250699e85a022a41e3be95 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Wed, 3 Jul 2024 11:41:37 +0530 Subject: [PATCH 1/4] wip: about page -> dialog --- lib/screens/common_widgets/button_navbar.dart | 99 +++++++++++++ .../common_widgets/common_widgets.dart | 1 + lib/screens/dashboard.dart | 77 ++++------ lib/screens/mobile/dashboard.dart | 6 +- lib/screens/mobile/navbar.dart | 140 ++++-------------- 5 files changed, 166 insertions(+), 157 deletions(-) create mode 100644 lib/screens/common_widgets/button_navbar.dart diff --git a/lib/screens/common_widgets/button_navbar.dart b/lib/screens/common_widgets/button_navbar.dart new file mode 100644 index 00000000..1daf31cd --- /dev/null +++ b/lib/screens/common_widgets/button_navbar.dart @@ -0,0 +1,99 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:apidash/providers/providers.dart'; + +class NavbarButton extends ConsumerWidget { + const NavbarButton({ + super.key, + required this.railIdx, + this.buttonIdx, + required this.selectedIcon, + required this.icon, + required this.label, + this.showLabel = true, + this.isCompact = false, + this.onTap, + }); + final int railIdx; + final int? buttonIdx; + final IconData selectedIcon; + final IconData icon; + final String label; + final bool showLabel; + final Function()? onTap; + final bool isCompact; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final bool isSelected = railIdx == buttonIdx; + final Size size = isCompact ? const Size(56, 32) : const Size(65, 32); + return MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: isSelected + ? null + : () { + if (buttonIdx != null) { + ref.read(navRailIndexStateProvider.notifier).state = + buttonIdx!; + if (railIdx > 1 && buttonIdx! <= 1) { + ref.read(leftDrawerStateProvider.notifier).state = false; + } + } + onTap?.call(); + }, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton( + style: isSelected + ? TextButton.styleFrom( + fixedSize: size, + backgroundColor: + Theme.of(context).colorScheme.secondaryContainer, + ) + : TextButton.styleFrom( + fixedSize: size, + ), + onPressed: isSelected + ? null + : () { + if (buttonIdx != null) { + ref.read(navRailIndexStateProvider.notifier).state = + buttonIdx!; + if (railIdx > 1 && buttonIdx! <= 1) { + ref.read(leftDrawerStateProvider.notifier).state = + false; + } + } + onTap?.call(); + }, + child: Icon( + isSelected ? selectedIcon : icon, + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ), + showLabel ? const SizedBox(height: 4) : const SizedBox.shrink(), + showLabel + ? Text( + label, + style: Theme.of(context).textTheme.labelSmall!.copyWith( + fontWeight: FontWeight.w600, + color: isSelected + ? Theme.of(context) + .colorScheme + .onSecondaryContainer + : Theme.of(context) + .colorScheme + .onSurface + .withOpacity(0.65), + ), + ) + : const SizedBox.shrink(), + ], + ), + ), + ); + } +} diff --git a/lib/screens/common_widgets/common_widgets.dart b/lib/screens/common_widgets/common_widgets.dart index 57282325..6c08887a 100644 --- a/lib/screens/common_widgets/common_widgets.dart +++ b/lib/screens/common_widgets/common_widgets.dart @@ -1,3 +1,4 @@ +export 'button_navbar.dart'; export 'editor_title.dart'; export 'editor_title_actions.dart'; export 'envfield_url.dart'; diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 3be66748..9699e581 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/consts.dart'; +import 'common_widgets/common_widgets.dart'; import 'envvar/environment_page.dart'; import 'home_page/home_page.dart'; -import 'intro_page.dart'; import 'settings_page.dart'; class Dashboard extends ConsumerWidget { @@ -52,6 +52,19 @@ class Dashboard extends ConsumerWidget { 'Variables', style: Theme.of(context).textTheme.labelSmall, ), + kVSpacer10, + IconButton( + isSelected: railIdx == 2, + onPressed: () { + ref.read(navRailIndexStateProvider.notifier).state = 2; + }, + icon: const Icon(Icons.history_outlined), + selectedIcon: const Icon(Icons.history), + ), + Text( + 'History', + style: Theme.of(context).textTheme.labelSmall, + ), ], ), Expanded( @@ -60,30 +73,31 @@ class Dashboard extends ConsumerWidget { children: [ Padding( padding: const EdgeInsets.only(bottom: 16.0), - child: bottomButton(context, ref, railIdx, 2, - Icons.help, Icons.help_outline), + child: NavbarButton( + railIdx: railIdx, + selectedIcon: Icons.help, + icon: Icons.help_outline, + label: 'About', + showLabel: false, + isCompact: true, + ), ), Padding( padding: const EdgeInsets.only(bottom: 16.0), - child: bottomButton(context, ref, railIdx, 3, - Icons.settings, Icons.settings_outlined), + child: NavbarButton( + railIdx: railIdx, + buttonIdx: 3, + selectedIcon: Icons.settings, + icon: Icons.settings_outlined, + label: 'Settings', + showLabel: false, + isCompact: true, + ), ), ], ), ), ], - // destinations: const [ - // // NavigationRailDestination( - // // icon: Icon(Icons.home_outlined), - // // selectedIcon: Icon(Icons.home), - // // label: Text('Home'), - // // ), - // NavigationRailDestination( - // icon: Icon(Icons.auto_awesome_mosaic_outlined), - // selectedIcon: Icon(Icons.auto_awesome_mosaic), - // label: Text('Requests'), - // ), - // ], ), VerticalDivider( thickness: 1, @@ -99,7 +113,7 @@ class Dashboard extends ConsumerWidget { EnvironmentPage( scaffoldKey: mobileScaffoldKey, ), - const IntroPage(), + const SizedBox(), const SettingsPage(), ], ), @@ -109,31 +123,4 @@ class Dashboard extends ConsumerWidget { ), ); } - - TextButton bottomButton( - BuildContext context, - WidgetRef ref, - int railIdx, - int buttonIdx, - IconData selectedIcon, - IconData icon, - ) { - bool isSelected = railIdx == buttonIdx; - return TextButton( - style: isSelected - ? TextButton.styleFrom( - backgroundColor: Theme.of(context).colorScheme.secondaryContainer, - ) - : null, - onPressed: isSelected - ? null - : () { - ref.read(navRailIndexStateProvider.notifier).state = buttonIdx; - }, - child: Icon( - isSelected ? selectedIcon : icon, - color: Theme.of(context).colorScheme.onSurfaceVariant, - ), - ); - } } diff --git a/lib/screens/mobile/dashboard.dart b/lib/screens/mobile/dashboard.dart index d1642be8..d6e73490 100644 --- a/lib/screens/mobile/dashboard.dart +++ b/lib/screens/mobile/dashboard.dart @@ -4,7 +4,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flex_color_scheme/flex_color_scheme.dart'; import 'package:apidash/extensions/extensions.dart'; import 'package:apidash/providers/providers.dart'; -import '../intro_page.dart'; import '../settings_page.dart'; import 'navbar.dart'; import 'requests_page/requests_page.dart'; @@ -74,9 +73,10 @@ class PageBranch extends ConsumerWidget { scaffoldKey: scaffoldKey, ); case 2: + // TODO: Implement history page return const PageBase( - title: 'About', - scaffoldBody: IntroPage(), + title: 'History', + scaffoldBody: SizedBox(), ); case 3: return const PageBase( diff --git a/lib/screens/mobile/navbar.dart b/lib/screens/mobile/navbar.dart index 99ad861d..5449f45f 100644 --- a/lib/screens/mobile/navbar.dart +++ b/lib/screens/mobile/navbar.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; +import '../common_widgets/common_widgets.dart'; class BottomNavBar extends ConsumerWidget { const BottomNavBar({super.key}); @@ -30,39 +31,39 @@ class BottomNavBar extends ConsumerWidget { mainAxisSize: MainAxisSize.min, children: [ Expanded( - child: customNavigationDestination(context, ref, railIdx, 0, - Icons.dashboard, Icons.dashboard_outlined, 'Requests'), - ), - Expanded( - child: customNavigationDestination( - context, - ref, - railIdx, - 1, - Icons.laptop_windows, - Icons.laptop_windows_outlined, - 'Variables'), - ), - Expanded( - child: customNavigationDestination( - context, - ref, - railIdx, - 2, - Icons.help, - Icons.help_outline, - 'About', + child: NavbarButton( + railIdx: railIdx, + buttonIdx: 0, + selectedIcon: Icons.dashboard, + icon: Icons.dashboard_outlined, + label: 'Requests', ), ), Expanded( - child: customNavigationDestination( - context, - ref, - railIdx, - 3, - Icons.settings, - Icons.settings_outlined, - 'Settings', + child: NavbarButton( + railIdx: railIdx, + buttonIdx: 1, + selectedIcon: Icons.laptop_windows, + icon: Icons.laptop_windows_outlined, + label: 'Variables', + ), + ), + Expanded( + child: NavbarButton( + railIdx: railIdx, + buttonIdx: 2, + selectedIcon: Icons.history, + icon: Icons.history_outlined, + label: 'History', + ), + ), + Expanded( + child: NavbarButton( + railIdx: railIdx, + buttonIdx: 3, + selectedIcon: Icons.settings, + icon: Icons.settings_outlined, + label: 'Settings', ), ), ], @@ -73,82 +74,3 @@ class BottomNavBar extends ConsumerWidget { ); } } - -Widget customNavigationDestination( - BuildContext context, - WidgetRef ref, - int railIdx, - int buttonIdx, - IconData selectedIcon, - IconData icon, - String label, { - bool showLabel = true, - Function()? onTap, -}) { - bool isSelected = railIdx == buttonIdx; - return MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: isSelected - ? null - : () { - ref.read(navRailIndexStateProvider.notifier).state = buttonIdx; - if (railIdx > 1 && buttonIdx <= 1) { - ref.read(leftDrawerStateProvider.notifier).state = false; - } - onTap?.call(); - }, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Ink( - width: 65, - height: 32, - decoration: BoxDecoration( - color: isSelected - ? Theme.of(context).colorScheme.secondaryContainer - : Colors.transparent, - borderRadius: BorderRadius.circular(30), - ), - child: InkWell( - borderRadius: BorderRadius.circular(30), - onTap: isSelected - ? null - : () { - ref.read(navRailIndexStateProvider.notifier).state = - buttonIdx; - if (railIdx > 1 && buttonIdx <= 1) { - ref.read(leftDrawerStateProvider.notifier).state = - false; - } - onTap?.call(); - }, - child: Icon( - isSelected ? selectedIcon : icon, - color: isSelected - ? Theme.of(context).colorScheme.onSecondaryContainer - : Theme.of(context).colorScheme.onSurface.withOpacity(0.65), - ), - ), - ), - showLabel ? const SizedBox(height: 4) : const SizedBox.shrink(), - showLabel - ? Text( - label, - style: Theme.of(context).textTheme.labelSmall!.copyWith( - fontWeight: FontWeight.w600, - color: isSelected - ? Theme.of(context).colorScheme.onSecondaryContainer - : Theme.of(context) - .colorScheme - .onSurface - .withOpacity(0.65), - ), - ) - : const SizedBox.shrink(), - ], - ), - ), - ); -} From ab2cd0dbf58b9413020124752ccd501205f8c339 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Wed, 3 Jul 2024 13:56:14 +0530 Subject: [PATCH 2/4] feat: about dialog --- lib/consts.dart | 3 ++ lib/screens/about_dialog.dart | 29 +++++++++++ lib/screens/dashboard.dart | 4 ++ lib/screens/intro_page.dart | 11 ----- lib/screens/settings_page.dart | 19 +++---- lib/widgets/intro_message.dart | 3 +- test/providers/ui_providers_test.dart | 71 +++++++++++++-------------- 7 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 lib/screens/about_dialog.dart delete mode 100644 lib/screens/intro_page.dart diff --git a/lib/consts.dart b/lib/consts.dart index 0e125b53..481a0665 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -124,6 +124,9 @@ const kP8CollectionPane = EdgeInsets.only( const kPt8 = EdgeInsets.only( top: 8, ); +const kPt20 = EdgeInsets.only( + top: 20, +); const kPt28 = EdgeInsets.only( top: 28, ); diff --git a/lib/screens/about_dialog.dart b/lib/screens/about_dialog.dart new file mode 100644 index 00000000..692b6743 --- /dev/null +++ b/lib/screens/about_dialog.dart @@ -0,0 +1,29 @@ +import 'package:apidash/consts.dart'; +import 'package:flutter/material.dart'; +import 'package:apidash/widgets/widgets.dart'; + +showAboutAppDialog( + BuildContext context, +) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + contentPadding: kPt20 + kPh20, + content: Container( + width: double.infinity, + height: double.infinity, + constraints: const BoxConstraints(maxWidth: 540, maxHeight: 544), + child: const IntroMessage(), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text("Close"), + ), + ], + ); + }); +} diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 9699e581..931092e9 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -1,3 +1,4 @@ +import 'package:apidash/screens/about_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; @@ -80,6 +81,9 @@ class Dashboard extends ConsumerWidget { label: 'About', showLabel: false, isCompact: true, + onTap: () { + showAboutAppDialog(context); + }, ), ), Padding( diff --git a/lib/screens/intro_page.dart b/lib/screens/intro_page.dart deleted file mode 100644 index 83d32253..00000000 --- a/lib/screens/intro_page.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:apidash/widgets/widgets.dart'; - -class IntroPage extends StatelessWidget { - const IntroPage({super.key}); - - @override - Widget build(BuildContext context) { - return const IntroMessage(); - } -} diff --git a/lib/screens/settings_page.dart b/lib/screens/settings_page.dart index 90db09bb..98c9f529 100644 --- a/lib/screens/settings_page.dart +++ b/lib/screens/settings_page.dart @@ -1,3 +1,4 @@ +import 'package:apidash/screens/about_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/providers.dart'; @@ -37,10 +38,8 @@ class SettingsPage extends ConsumerWidget { Expanded( child: ListView( shrinkWrap: true, - padding: kPh20, children: [ SwitchListTile( - contentPadding: EdgeInsets.zero, hoverColor: kColorTransparent, title: const Text('Switch Theme Mode'), subtitle: Text( @@ -51,7 +50,6 @@ class SettingsPage extends ConsumerWidget { }, ), SwitchListTile( - contentPadding: EdgeInsets.zero, hoverColor: kColorTransparent, title: const Text('Collection Pane Scrollbar Visiblity'), subtitle: Text( @@ -64,7 +62,6 @@ class SettingsPage extends ConsumerWidget { }, ), ListTile( - contentPadding: kPb10, hoverColor: kColorTransparent, title: const Text('Default URI Scheme'), subtitle: Text( @@ -109,7 +106,6 @@ class SettingsPage extends ConsumerWidget { ), ), ListTile( - contentPadding: kPb10, hoverColor: kColorTransparent, title: const Text('Default Code Generator'), trailing: Container( @@ -151,7 +147,6 @@ class SettingsPage extends ConsumerWidget { ), ), CheckboxListTile( - contentPadding: EdgeInsets.zero, title: const Text("Save Responses"), subtitle: const Text("Save disk space by not storing API responses"), @@ -163,7 +158,6 @@ class SettingsPage extends ConsumerWidget { }, ), CheckboxListTile( - contentPadding: EdgeInsets.zero, title: const Text("Show Save Alert on App Close"), subtitle: const Text( "Show a confirmation dialog to save workspace when the user closes the app"), @@ -175,7 +169,6 @@ class SettingsPage extends ConsumerWidget { }, ), ListTile( - contentPadding: EdgeInsets.zero, hoverColor: kColorTransparent, title: const Text('Export Data'), subtitle: const Text( @@ -195,7 +188,6 @@ class SettingsPage extends ConsumerWidget { ), ), ListTile( - contentPadding: EdgeInsets.zero, hoverColor: kColorTransparent, title: const Text('Clear Data'), subtitle: const Text('Delete all requests data from the disk'), @@ -250,6 +242,15 @@ class SettingsPage extends ConsumerWidget { ), ), ), + ListTile( + title: const Text('About'), + subtitle: const Text( + 'Release Details, Support Channel, Report Bug / Request New Feature'), + onTap: () { + showAboutAppDialog(context); + }, + ), + kVSpacer20, ], ), ), diff --git a/lib/widgets/intro_message.dart b/lib/widgets/intro_message.dart index 21e209ae..2df9c979 100644 --- a/lib/widgets/intro_message.dart +++ b/lib/widgets/intro_message.dart @@ -4,7 +4,6 @@ import 'package:package_info_plus/package_info_plus.dart'; import '../consts.dart'; import 'markdown.dart'; import 'error_message.dart'; -import 'package:apidash/extensions/extensions.dart'; class IntroMessage extends StatelessWidget { const IntroMessage({ @@ -38,7 +37,7 @@ class IntroMessage extends StatelessWidget { return CustomMarkdown( data: text, - padding: !context.isMediumWindow ? kPh60 : kPh20, + padding: EdgeInsets.zero, ); } return const Center(child: CircularProgressIndicator()); diff --git a/test/providers/ui_providers_test.dart b/test/providers/ui_providers_test.dart index 41726dca..ff52c62e 100644 --- a/test/providers/ui_providers_test.dart +++ b/test/providers/ui_providers_test.dart @@ -11,7 +11,6 @@ import 'package:apidash/screens/home_page/editor_pane/editor_default.dart'; import 'package:apidash/screens/home_page/editor_pane/editor_pane.dart'; import 'package:apidash/screens/home_page/editor_pane/url_card.dart'; import 'package:apidash/screens/home_page/home_page.dart'; -import 'package:apidash/screens/intro_page.dart'; import 'package:apidash/screens/settings_page.dart'; import 'package:apidash/services/hive_services.dart'; import 'package:apidash/widgets/widgets.dart'; @@ -58,7 +57,7 @@ void main() { // Verify that the HomePage is displayed initially expect(find.byType(HomePage), findsOneWidget); expect(find.byType(EnvironmentPage), findsNothing); - expect(find.byType(IntroPage), findsNothing); + // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsNothing); }); @@ -79,32 +78,32 @@ void main() { // Verify that the EnvironmentPage is displayed expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsOneWidget); - expect(find.byType(IntroPage), findsNothing); + // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsNothing); }); - testWidgets( - "Dashboard should display IntroPage when navRailIndexStateProvider is 2", - (WidgetTester tester) async { - await tester.pumpWidget( - ProviderScope( - overrides: [ - navRailIndexStateProvider.overrideWith((ref) => 2), - ], - child: const Portal( - child: MaterialApp( - home: Dashboard(), - ), - ), - ), - ); + // testWidgets( + // "Dashboard should display IntroPage when navRailIndexStateProvider is 2", + // (WidgetTester tester) async { + // await tester.pumpWidget( + // ProviderScope( + // overrides: [ + // navRailIndexStateProvider.overrideWith((ref) => 2), + // ], + // child: const Portal( + // child: MaterialApp( + // home: Dashboard(), + // ), + // ), + // ), + // ); - // Verify that the IntroPage is displayed - expect(find.byType(HomePage), findsNothing); - expect(find.byType(EnvironmentPage), findsNothing); - expect(find.byType(IntroPage), findsOneWidget); - expect(find.byType(SettingsPage), findsNothing); - }); + // // Verify that the IntroPage is displayed + // expect(find.byType(HomePage), findsNothing); + // expect(find.byType(EnvironmentPage), findsNothing); + // expect(find.byType(IntroPage), findsOneWidget); + // expect(find.byType(SettingsPage), findsNothing); + // }); testWidgets( "Dashboard should display SettingsPage when navRailIndexStateProvider is 3", @@ -125,7 +124,7 @@ void main() { // Verify that the SettingsPage is displayed expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsNothing); - expect(find.byType(IntroPage), findsNothing); + // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsOneWidget); }); @@ -142,14 +141,14 @@ void main() { ), ); - // Tap on the Intro icon - await tester.tap(find.byIcon(Icons.help_outline)); + // Tap on the Settings icon + await tester.tap(find.byIcon(Icons.settings_outlined)); await tester.pump(); // Verify that the navRailIndexStateProvider is updated final dashboard = tester.element(find.byType(Dashboard)); final container = ProviderScope.containerOf(dashboard); - expect(container.read(navRailIndexStateProvider), 2); + expect(container.read(navRailIndexStateProvider), 3); }); testWidgets( @@ -188,7 +187,7 @@ void main() { // Verify that the SettingsPage is still displayed after the rebuild expect(find.byType(SettingsPage), findsOneWidget); - expect(find.byType(IntroPage), findsNothing); + // expect(find.byType(IntroPage), findsNothing); expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsNothing); }); @@ -219,14 +218,14 @@ void main() { // Verify that the selected icon is the filled version (selectedIcon) expect(find.byIcon(Icons.computer_rounded), findsOneWidget); - // Go to IntroPage - container.read(navRailIndexStateProvider.notifier).state = 2; - await tester.pump(); + // // Go to IntroPage + // container.read(navRailIndexStateProvider.notifier).state = 2; + // await tester.pump(); - // Verify that the IntroPage is displayed - expect(find.byType(IntroPage), findsOneWidget); - // Verify that the selected icon is the filled version (selectedIcon) - expect(find.byIcon(Icons.help), findsOneWidget); + // // Verify that the IntroPage is displayed + // expect(find.byType(IntroPage), findsOneWidget); + // // Verify that the selected icon is the filled version (selectedIcon) + // expect(find.byIcon(Icons.help), findsOneWidget); // Go to SettingsPage container.read(navRailIndexStateProvider.notifier).state = 3; From 58b5300f061e75e59201cf52ad13765890262721 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Thu, 4 Jul 2024 11:42:46 +0530 Subject: [PATCH 3/4] fix: ui_provider_tests --- lib/screens/about_dialog.dart | 2 +- lib/screens/dashboard.dart | 27 ++++++++-------- lib/screens/mobile/dashboard.dart | 12 +++---- lib/screens/mobile/navbar.dart | 18 +++++------ test/providers/ui_providers_test.dart | 46 +++------------------------ 5 files changed, 34 insertions(+), 71 deletions(-) diff --git a/lib/screens/about_dialog.dart b/lib/screens/about_dialog.dart index 692b6743..48362f44 100644 --- a/lib/screens/about_dialog.dart +++ b/lib/screens/about_dialog.dart @@ -9,7 +9,7 @@ showAboutAppDialog( context: context, builder: (context) { return AlertDialog( - contentPadding: kPt20 + kPh20, + contentPadding: kPt20 + kPh20 + kPb10, content: Container( width: double.infinity, height: double.infinity, diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 931092e9..92acda3e 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -54,18 +54,18 @@ class Dashboard extends ConsumerWidget { style: Theme.of(context).textTheme.labelSmall, ), kVSpacer10, - IconButton( - isSelected: railIdx == 2, - onPressed: () { - ref.read(navRailIndexStateProvider.notifier).state = 2; - }, - icon: const Icon(Icons.history_outlined), - selectedIcon: const Icon(Icons.history), - ), - Text( - 'History', - style: Theme.of(context).textTheme.labelSmall, - ), + // IconButton( + // isSelected: railIdx == 2, + // onPressed: () { + // ref.read(navRailIndexStateProvider.notifier).state = 2; + // }, + // icon: const Icon(Icons.history_outlined), + // selectedIcon: const Icon(Icons.history), + // ), + // Text( + // 'History', + // style: Theme.of(context).textTheme.labelSmall, + // ), ], ), Expanded( @@ -90,7 +90,7 @@ class Dashboard extends ConsumerWidget { padding: const EdgeInsets.only(bottom: 16.0), child: NavbarButton( railIdx: railIdx, - buttonIdx: 3, + buttonIdx: 2, selectedIcon: Icons.settings, icon: Icons.settings_outlined, label: 'Settings', @@ -117,7 +117,6 @@ class Dashboard extends ConsumerWidget { EnvironmentPage( scaffoldKey: mobileScaffoldKey, ), - const SizedBox(), const SettingsPage(), ], ), diff --git a/lib/screens/mobile/dashboard.dart b/lib/screens/mobile/dashboard.dart index d6e73490..c23c1cd2 100644 --- a/lib/screens/mobile/dashboard.dart +++ b/lib/screens/mobile/dashboard.dart @@ -72,13 +72,13 @@ class PageBranch extends ConsumerWidget { return EnvironmentPage( scaffoldKey: scaffoldKey, ); + // case 2: + // // TODO: Implement history page + // return const PageBase( + // title: 'History', + // scaffoldBody: SizedBox(), + // ); case 2: - // TODO: Implement history page - return const PageBase( - title: 'History', - scaffoldBody: SizedBox(), - ); - case 3: return const PageBase( title: 'Settings', scaffoldBody: SettingsPage(), diff --git a/lib/screens/mobile/navbar.dart b/lib/screens/mobile/navbar.dart index 5449f45f..438969b7 100644 --- a/lib/screens/mobile/navbar.dart +++ b/lib/screens/mobile/navbar.dart @@ -48,19 +48,19 @@ class BottomNavBar extends ConsumerWidget { label: 'Variables', ), ), + // Expanded( + // child: NavbarButton( + // railIdx: railIdx, + // buttonIdx: 2, + // selectedIcon: Icons.history, + // icon: Icons.history_outlined, + // label: 'History', + // ), + // ), Expanded( child: NavbarButton( railIdx: railIdx, buttonIdx: 2, - selectedIcon: Icons.history, - icon: Icons.history_outlined, - label: 'History', - ), - ), - Expanded( - child: NavbarButton( - railIdx: railIdx, - buttonIdx: 3, selectedIcon: Icons.settings, icon: Icons.settings_outlined, label: 'Settings', diff --git a/test/providers/ui_providers_test.dart b/test/providers/ui_providers_test.dart index ff52c62e..be1cd59b 100644 --- a/test/providers/ui_providers_test.dart +++ b/test/providers/ui_providers_test.dart @@ -57,7 +57,6 @@ void main() { // Verify that the HomePage is displayed initially expect(find.byType(HomePage), findsOneWidget); expect(find.byType(EnvironmentPage), findsNothing); - // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsNothing); }); @@ -78,40 +77,16 @@ void main() { // Verify that the EnvironmentPage is displayed expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsOneWidget); - // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsNothing); }); - // testWidgets( - // "Dashboard should display IntroPage when navRailIndexStateProvider is 2", - // (WidgetTester tester) async { - // await tester.pumpWidget( - // ProviderScope( - // overrides: [ - // navRailIndexStateProvider.overrideWith((ref) => 2), - // ], - // child: const Portal( - // child: MaterialApp( - // home: Dashboard(), - // ), - // ), - // ), - // ); - - // // Verify that the IntroPage is displayed - // expect(find.byType(HomePage), findsNothing); - // expect(find.byType(EnvironmentPage), findsNothing); - // expect(find.byType(IntroPage), findsOneWidget); - // expect(find.byType(SettingsPage), findsNothing); - // }); - testWidgets( - "Dashboard should display SettingsPage when navRailIndexStateProvider is 3", + "Dashboard should display SettingsPage when navRailIndexStateProvider is 2", (WidgetTester tester) async { await tester.pumpWidget( ProviderScope( overrides: [ - navRailIndexStateProvider.overrideWith((ref) => 3), + navRailIndexStateProvider.overrideWith((ref) => 2), ], child: const Portal( child: MaterialApp( @@ -124,7 +99,6 @@ void main() { // Verify that the SettingsPage is displayed expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsNothing); - // expect(find.byType(IntroPage), findsNothing); expect(find.byType(SettingsPage), findsOneWidget); }); @@ -148,7 +122,7 @@ void main() { // Verify that the navRailIndexStateProvider is updated final dashboard = tester.element(find.byType(Dashboard)); final container = ProviderScope.containerOf(dashboard); - expect(container.read(navRailIndexStateProvider), 3); + expect(container.read(navRailIndexStateProvider), 2); }); testWidgets( @@ -183,11 +157,10 @@ void main() { // Verify that the navRailIndexStateProvider still has the updated value final dashboard = tester.element(find.byType(Dashboard)); final container = ProviderScope.containerOf(dashboard); - expect(container.read(navRailIndexStateProvider), 3); + expect(container.read(navRailIndexStateProvider), 2); // Verify that the SettingsPage is still displayed after the rebuild expect(find.byType(SettingsPage), findsOneWidget); - // expect(find.byType(IntroPage), findsNothing); expect(find.byType(HomePage), findsNothing); expect(find.byType(EnvironmentPage), findsNothing); }); @@ -218,17 +191,8 @@ void main() { // Verify that the selected icon is the filled version (selectedIcon) expect(find.byIcon(Icons.computer_rounded), findsOneWidget); - // // Go to IntroPage - // container.read(navRailIndexStateProvider.notifier).state = 2; - // await tester.pump(); - - // // Verify that the IntroPage is displayed - // expect(find.byType(IntroPage), findsOneWidget); - // // Verify that the selected icon is the filled version (selectedIcon) - // expect(find.byIcon(Icons.help), findsOneWidget); - // Go to SettingsPage - container.read(navRailIndexStateProvider.notifier).state = 3; + container.read(navRailIndexStateProvider.notifier).state = 2; await tester.pump(); // Verify that the SettingsPage is displayed From a5845d606f21d3801d5593ffc862fa56846d8a2a Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Sat, 6 Jul 2024 15:36:39 +0530 Subject: [PATCH 4/4] refactor: move dialog to widgets --- lib/screens/dashboard.dart | 2 +- lib/screens/settings_page.dart | 1 - lib/{screens/about_dialog.dart => widgets/dialog_about.dart} | 0 lib/widgets/{dialogs.dart => dialog_rename.dart} | 0 lib/widgets/widgets.dart | 3 ++- 5 files changed, 3 insertions(+), 3 deletions(-) rename lib/{screens/about_dialog.dart => widgets/dialog_about.dart} (100%) rename lib/widgets/{dialogs.dart => dialog_rename.dart} (100%) diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 92acda3e..f6c7d0f8 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -1,7 +1,7 @@ -import 'package:apidash/screens/about_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; +import 'package:apidash/widgets/widgets.dart'; import 'package:apidash/consts.dart'; import 'common_widgets/common_widgets.dart'; import 'envvar/environment_page.dart'; diff --git a/lib/screens/settings_page.dart b/lib/screens/settings_page.dart index 98c9f529..c7426524 100644 --- a/lib/screens/settings_page.dart +++ b/lib/screens/settings_page.dart @@ -1,4 +1,3 @@ -import 'package:apidash/screens/about_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/providers.dart'; diff --git a/lib/screens/about_dialog.dart b/lib/widgets/dialog_about.dart similarity index 100% rename from lib/screens/about_dialog.dart rename to lib/widgets/dialog_about.dart diff --git a/lib/widgets/dialogs.dart b/lib/widgets/dialog_rename.dart similarity index 100% rename from lib/widgets/dialogs.dart rename to lib/widgets/dialog_rename.dart diff --git a/lib/widgets/widgets.dart b/lib/widgets/widgets.dart index 6b480b52..15f36376 100644 --- a/lib/widgets/widgets.dart +++ b/lib/widgets/widgets.dart @@ -10,7 +10,8 @@ export 'card_sidebar_request.dart'; export 'checkbox.dart'; export 'code_previewer.dart'; export 'codegen_previewer.dart'; -export 'dialogs.dart'; +export 'dialog_about.dart'; +export 'dialog_rename.dart'; export 'dropdown_codegen.dart'; export 'dropdown_content_type.dart'; export 'dropdown_formdata.dart';