From fcc940ec2e1cf338c2924db39cb9b32c35523c20 Mon Sep 17 00:00:00 2001 From: Jeet Dalal Date: Sun, 11 Aug 2024 13:40:47 +0530 Subject: [PATCH 01/14] resolved issue #178(switch from GET->POST if payload exists) --- .../request_pane/request_body.dart | 31 +++++++++++- .../request_pane/request_form_data.dart | 5 +- pubspec.yaml | 1 + test/providers/collection_providers_test.dart | 50 +++++++++++++++++++ test/providers/helpers.dart | 40 +++++++++++++++ test/providers/ui_providers_test.dart | 2 - 6 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 test/providers/collection_providers_test.dart create mode 100644 test/providers/helpers.dart diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart index 39011d81..065feefe 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart @@ -1,3 +1,6 @@ +import 'dart:developer'; + +import 'package:apidash/models/models.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; @@ -17,6 +20,25 @@ class EditRequestBody extends ConsumerWidget { final contentType = ref.watch(selectedRequestModelProvider .select((value) => value?.httpRequestModel?.bodyContentType)); + void changeToPostMethod() { + RequestModel? model = ref + .read(collectionStateNotifierProvider.notifier) + .getRequestModel(selectedId); + + if (model!.httpRequestModel!.method == HTTPVerb.get) { + ref + .read(collectionStateNotifierProvider.notifier) + .update(selectedId, method: HTTPVerb.post); + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text( + "Switched to POST method", + style: TextStyle(color: Colors.white), + ), + backgroundColor: Colors.black, + )); + } + } + return Column( children: [ const SizedBox( @@ -33,8 +55,11 @@ class EditRequestBody extends ConsumerWidget { ), Expanded( child: switch (contentType) { - ContentType.formdata => - const Padding(padding: kPh4, child: FormDataWidget()), + ContentType.formdata => Padding( + padding: kPh4, + child: FormDataWidget( + changeMethodToPost: changeToPostMethod, + )), // TODO: Fix JsonTextFieldEditor & plug it here ContentType.json => Padding( padding: kPt5o10, @@ -43,6 +68,7 @@ class EditRequestBody extends ConsumerWidget { fieldKey: "$selectedId-json-body-editor", initialValue: requestModel?.httpRequestModel?.body, onChanged: (String value) { + changeToPostMethod(); ref .read(collectionStateNotifierProvider.notifier) .update(selectedId, body: value); @@ -56,6 +82,7 @@ class EditRequestBody extends ConsumerWidget { fieldKey: "$selectedId-body-editor", initialValue: requestModel?.httpRequestModel?.body, onChanged: (String value) { + changeToPostMethod(); ref .read(collectionStateNotifierProvider.notifier) .update(selectedId, body: value); diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart index 5228c660..eff4c821 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart @@ -9,7 +9,8 @@ import 'package:apidash/utils/utils.dart'; import 'package:apidash/consts.dart'; class FormDataWidget extends ConsumerStatefulWidget { - const FormDataWidget({super.key}); + final Function changeMethodToPost; + const FormDataWidget({required this.changeMethodToPost, super.key}); @override ConsumerState createState() => _FormDataBodyState(); } @@ -27,6 +28,7 @@ class _FormDataBodyState extends ConsumerState { } void _onFieldChange(String selectedId) { + widget.changeMethodToPost(); ref.read(collectionStateNotifierProvider.notifier).update( selectedId, formData: formRows.sublist(0, formRows.length - 1), @@ -41,6 +43,7 @@ class _FormDataBodyState extends ConsumerState { .select((value) => value?.httpRequestModel?.formData?.length)); var rF = ref.read(selectedRequestModelProvider)?.httpRequestModel?.formData; bool isFormDataEmpty = rF == null || rF.isEmpty; + formRows = isFormDataEmpty ? [ kFormDataEmptyModel, diff --git a/pubspec.yaml b/pubspec.yaml index 7d119b21..36b5640c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -73,6 +73,7 @@ dependencies: git: url: https://github.com/foss42/curl_converter.git ref: 726e8cd04aeb326211af27f75920be5b21c90bb4 + dependency_overrides: web: ^0.5.0 diff --git a/test/providers/collection_providers_test.dart b/test/providers/collection_providers_test.dart new file mode 100644 index 00000000..7cabaae4 --- /dev/null +++ b/test/providers/collection_providers_test.dart @@ -0,0 +1,50 @@ +import 'package:apidash/consts.dart'; +import 'package:apidash/screens/home_page/editor_pane/details_card/request_pane/request_body.dart'; +import 'package:apidash/widgets/editor.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:apidash/providers/providers.dart'; +import 'helpers.dart'; + +void main() async { + setUp(() async => await testSetUp()); + + testWidgets( + 'Request method changes from GET to POST when body is added and Snackbar is shown', + (WidgetTester tester) async { + // Set up the test environment + final container = createContainer(); + final notifier = container.read(collectionStateNotifierProvider.notifier); + + // Ensure the initial request is a GET request with no body + final id = notifier.state!.entries.first.key; + expect( + notifier.getRequestModel(id)!.httpRequestModel!.method, HTTPVerb.get); + expect(notifier.getRequestModel(id)!.httpRequestModel!.body, isNull); + + // Build the EditRequestBody widget + await tester.pumpWidget( + ProviderScope( + // ignore: deprecated_member_use + parent: container, + child: const MaterialApp( + home: Scaffold( + body: EditRequestBody(), + ), + ), + ), + ); + + // Add a body to the request, which should trigger the method change + await tester.enterText(find.byType(TextFieldEditor), 'new body added'); + await tester.pump(); // Process the state change + + // Verify that the request method changed to POST + expect( + notifier.getRequestModel(id)!.httpRequestModel!.method, HTTPVerb.post); + + // Verify that the Snackbar is shown + expect(find.text('Switched to POST method'), findsOneWidget); + }); +} diff --git a/test/providers/helpers.dart b/test/providers/helpers.dart new file mode 100644 index 00000000..f0ab2915 --- /dev/null +++ b/test/providers/helpers.dart @@ -0,0 +1,40 @@ +import 'package:apidash/services/hive_services.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; + +/// A testing utility which creates a [ProviderContainer] and automatically +/// disposes it at the end of the test. +ProviderContainer createContainer({ + ProviderContainer? parent, + List overrides = const [], + List? observers, +}) { + // Create a ProviderContainer, and optionally allow specifying parameters. + final container = ProviderContainer( + parent: parent, + overrides: overrides, + observers: observers, + ); + + // When the test ends, dispose the container. + addTearDown(container.dispose); + + return container; +} + +Future testSetUp() async { + // override path_provider methodCall to point + // path to temporary location for all unit tests + TestWidgetsFlutterBinding.ensureInitialized(); + const MethodChannel channel = + MethodChannel('plugins.flutter.io/path_provider'); + + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, (MethodCall methodCall) async { + return './test/unit-test-hive-storage/'; + }); + + await openBoxes(); +} diff --git a/test/providers/ui_providers_test.dart b/test/providers/ui_providers_test.dart index ba2b2b85..ea2b5012 100644 --- a/test/providers/ui_providers_test.dart +++ b/test/providers/ui_providers_test.dart @@ -1,6 +1,4 @@ import 'dart:io'; -import 'package:spot/spot.dart'; -import 'package:apidash/consts.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/screens/common_widgets/common_widgets.dart'; import 'package:apidash/screens/dashboard.dart'; From 3b32877240e1e0bc00355930ba2505ca2f3c3f3e Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 15 Sep 2024 21:32:06 +0530 Subject: [PATCH 02/14] fix errors --- .../editor_pane/details_card/request_pane/request_body.dart | 2 -- test/providers/helpers.dart | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart index 065feefe..c70f54d3 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:apidash/models/models.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; diff --git a/test/providers/helpers.dart b/test/providers/helpers.dart index f0ab2915..73dff64a 100644 --- a/test/providers/helpers.dart +++ b/test/providers/helpers.dart @@ -2,7 +2,6 @@ import 'package:apidash/services/hive_services.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:test/test.dart'; /// A testing utility which creates a [ProviderContainer] and automatically /// disposes it at the end of the test. @@ -36,5 +35,5 @@ Future testSetUp() async { return './test/unit-test-hive-storage/'; }); - await openBoxes(); + await openBoxes(false, null); } From a87e7bf6b051a4a094956d60dd31041ad3261ab6 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 00:14:23 +0530 Subject: [PATCH 03/14] Update hive_services.dart --- lib/services/hive_services.dart | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index cc7f8960..192aeec7 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; const String kDataBox = "apidash-data"; @@ -35,6 +36,28 @@ Future openBoxes( } } +Future clearHiveBoxes() async { + try { + await Hive.box(kDataBox).clear(); + await Hive.box(kEnvironmentBox).clear(); + await Hive.box(kHistoryMetaBox).clear(); + await Hive.lazyBox(kHistoryLazyBox).clear(); + } catch (e) { + debugPrint("ERROR CLEAR HIVE BOXES: $e"); + } +} + +Future deleteHiveBoxes() async { + try { + await Hive.box(kDataBox).deleteFromDisk(); + await Hive.box(kEnvironmentBox).deleteFromDisk(); + await Hive.box(kHistoryMetaBox).deleteFromDisk(); + await Hive.lazyBox(kHistoryLazyBox).deleteFromDisk(); + } catch (e) { + debugPrint("ERROR DELETE HIVE BOXES: $e"); + } +} + final hiveHandler = HiveHandler(); class HiveHandler { @@ -93,6 +116,8 @@ class HiveHandler { Future clear() async { await dataBox.clear(); await environmentBox.clear(); + await historyMetaBox.clear(); + await historyLazyBox.clear(); } Future removeUnused() async { From f9801c8dc40fee040241c277cd91894d9b072fb2 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 00:18:21 +0530 Subject: [PATCH 04/14] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 4bdfd329..9a64d7c0 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ coverage/* installers/* .metadata .fvm/ + +# Testing Files & Folders +test-hive-storage From cba19ae6b182dc991f20c91e3fd15b99c11bb8f4 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 00:18:31 +0530 Subject: [PATCH 05/14] Update helpers.dart --- test/providers/helpers.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/providers/helpers.dart b/test/providers/helpers.dart index 73dff64a..2e57affb 100644 --- a/test/providers/helpers.dart +++ b/test/providers/helpers.dart @@ -32,8 +32,10 @@ Future testSetUp() async { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, (MethodCall methodCall) async { - return './test/unit-test-hive-storage/'; + return './test-hive-storage/'; }); await openBoxes(false, null); + await deleteHiveBoxes(); + await openBoxes(false, null); } From 7b848791c237938621aea6274f6565c0072bcb9c Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 03:03:17 +0530 Subject: [PATCH 06/14] dataTableShowLogs --- test/widgets/table_request_form_test.dart | 1 + test/widgets/table_request_test.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/test/widgets/table_request_form_test.dart b/test/widgets/table_request_form_test.dart index a1c67424..c21a9b70 100644 --- a/test/widgets/table_request_form_test.dart +++ b/test/widgets/table_request_form_test.dart @@ -6,6 +6,7 @@ import 'package:apidash/models/models.dart'; import 'package:apidash/consts.dart'; void main() { + dataTableShowLogs = false; testWidgets('Testing RequestFormDataTable', (WidgetTester tester) async { const List sampleData = [ FormDataModel(name: 'Key1', value: 'Value1', type: FormDataType.file), diff --git a/test/widgets/table_request_test.dart b/test/widgets/table_request_test.dart index 6e8c2c9f..cc0e3324 100644 --- a/test/widgets/table_request_test.dart +++ b/test/widgets/table_request_test.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + dataTableShowLogs = false; testWidgets('Testing RequestDataTable', (WidgetTester tester) async { final Map sampleData = { 'Key1': 'Value1', From a0d93082f4436ee66b437b7e30792186400c8d7a Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 03:03:26 +0530 Subject: [PATCH 07/14] hive updates --- lib/app.dart | 2 +- lib/main.dart | 2 +- lib/services/hive_services.dart | 46 ++++++++++++++----- test/providers/collection_providers_test.dart | 6 ++- test/providers/helpers.dart | 26 +++++++++-- test/providers/ui_providers_test.dart | 17 +------ 6 files changed, 65 insertions(+), 34 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index a2011dcd..48c49a86 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -120,7 +120,7 @@ class DashApp extends ConsumerWidget { home: showWorkspaceSelector ? WorkspaceSelector( onContinue: (val) async { - await openBoxes(kIsDesktop, val); + await initHiveBoxes(kIsDesktop, val); ref .read(settingsProvider.notifier) .update(workspaceFolderPath: val); diff --git a/lib/main.dart b/lib/main.dart index e1e70ec6..7e212dad 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,7 +42,7 @@ Future initApp( try { debugPrint("initializeUsingPath: $initializeUsingPath"); debugPrint("workspaceFolderPath: ${settingsModel?.workspaceFolderPath}"); - final openBoxesStatus = await openBoxes( + final openBoxesStatus = await initHiveBoxes( initializeUsingPath, settingsModel?.workspaceFolderPath, ); diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index 192aeec7..9f703ef3 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -11,7 +11,7 @@ const String kHistoryMetaBox = "apidash-history-meta"; const String kHistoryBoxIds = "historyIds"; const String kHistoryLazyBox = "apidash-history-lazy"; -Future openBoxes( +Future initHiveBoxes( bool initializeUsingPath, String? workspaceFolderPath, ) async { @@ -25,23 +25,38 @@ Future openBoxes( } else { await Hive.initFlutter(); } + await openHiveBoxes(); + return true; + } catch (e) { + return false; + } +} +Future openHiveBoxes() async { + try { await Hive.openBox(kDataBox); await Hive.openBox(kEnvironmentBox); await Hive.openBox(kHistoryMetaBox); await Hive.openLazyBox(kHistoryLazyBox); - return true; } catch (e) { - return false; + debugPrint("ERROR OPEN HIVE BOXES: $e"); } } Future clearHiveBoxes() async { try { - await Hive.box(kDataBox).clear(); - await Hive.box(kEnvironmentBox).clear(); - await Hive.box(kHistoryMetaBox).clear(); - await Hive.lazyBox(kHistoryLazyBox).clear(); + if (Hive.isBoxOpen(kDataBox)) { + await Hive.box(kDataBox).clear(); + } + if (Hive.isBoxOpen(kEnvironmentBox)) { + await Hive.box(kEnvironmentBox).clear(); + } + if (Hive.isBoxOpen(kHistoryMetaBox)) { + await Hive.box(kHistoryMetaBox).clear(); + } + if (Hive.isBoxOpen(kHistoryLazyBox)) { + await Hive.lazyBox(kHistoryLazyBox).clear(); + } } catch (e) { debugPrint("ERROR CLEAR HIVE BOXES: $e"); } @@ -49,10 +64,19 @@ Future clearHiveBoxes() async { Future deleteHiveBoxes() async { try { - await Hive.box(kDataBox).deleteFromDisk(); - await Hive.box(kEnvironmentBox).deleteFromDisk(); - await Hive.box(kHistoryMetaBox).deleteFromDisk(); - await Hive.lazyBox(kHistoryLazyBox).deleteFromDisk(); + if (Hive.isBoxOpen(kDataBox)) { + await Hive.box(kDataBox).deleteFromDisk(); + } + if (Hive.isBoxOpen(kEnvironmentBox)) { + await Hive.box(kEnvironmentBox).deleteFromDisk(); + } + if (Hive.isBoxOpen(kHistoryMetaBox)) { + await Hive.box(kHistoryMetaBox).deleteFromDisk(); + } + if (Hive.isBoxOpen(kHistoryLazyBox)) { + await Hive.lazyBox(kHistoryLazyBox).deleteFromDisk(); + } + await Hive.close(); } catch (e) { debugPrint("ERROR DELETE HIVE BOXES: $e"); } diff --git a/test/providers/collection_providers_test.dart b/test/providers/collection_providers_test.dart index 7cabaae4..1abd8123 100644 --- a/test/providers/collection_providers_test.dart +++ b/test/providers/collection_providers_test.dart @@ -8,7 +8,11 @@ import 'package:apidash/providers/providers.dart'; import 'helpers.dart'; void main() async { - setUp(() async => await testSetUp()); + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() async { + await testSetUpTempDirForHive(); + }); testWidgets( 'Request method changes from GET to POST when body is added and Snackbar is shown', diff --git a/test/providers/helpers.dart b/test/providers/helpers.dart index 2e57affb..568a849c 100644 --- a/test/providers/helpers.dart +++ b/test/providers/helpers.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'package:apidash/services/hive_services.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -23,10 +24,9 @@ ProviderContainer createContainer({ return container; } -Future testSetUp() async { +Future testSetUpForHive() async { // override path_provider methodCall to point // path to temporary location for all unit tests - TestWidgetsFlutterBinding.ensureInitialized(); const MethodChannel channel = MethodChannel('plugins.flutter.io/path_provider'); @@ -35,7 +35,23 @@ Future testSetUp() async { return './test-hive-storage/'; }); - await openBoxes(false, null); - await deleteHiveBoxes(); - await openBoxes(false, null); + await initHiveBoxes(false, null); + // await deleteHiveBoxes(); + // await openHiveBoxes(); +} + +Future testSetUpTempDirForHive() async { + const MethodChannel channel = + MethodChannel('plugins.flutter.io/path_provider'); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, (MethodCall methodCall) async { + if (methodCall.method == 'getApplicationDocumentsDirectory') { + // Create a mock app doc directory for testing + Directory tempDir = + await Directory.systemTemp.createTemp('mock_app_doc_dir'); + return tempDir.path; // Return the path to the mock directory + } + return null; + }); + await initHiveBoxes(false, null); } diff --git a/test/providers/ui_providers_test.dart b/test/providers/ui_providers_test.dart index 60b67241..e8fd0582 100644 --- a/test/providers/ui_providers_test.dart +++ b/test/providers/ui_providers_test.dart @@ -1,4 +1,3 @@ -import 'dart:io'; //import 'package:spot/spot.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/screens/common_widgets/common_widgets.dart'; @@ -12,7 +11,6 @@ import 'package:apidash/screens/home_page/editor_pane/url_card.dart'; import 'package:apidash/screens/home_page/home_page.dart'; import 'package:apidash/screens/settings_page.dart'; import 'package:apidash/screens/history/history_page.dart'; -import 'package:apidash/services/hive_services.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; @@ -22,24 +20,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import '../extensions/widget_tester_extensions.dart'; import '../test_consts.dart'; +import 'helpers.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); setUp(() async { - const MethodChannel channel = - MethodChannel('plugins.flutter.io/path_provider'); - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(channel, (MethodCall methodCall) async { - if (methodCall.method == 'getApplicationDocumentsDirectory') { - // Create a mock app doc directory for testing - Directory tempDir = - await Directory.systemTemp.createTemp('mock_app_doc_dir'); - return tempDir.path; // Return the path to the mock directory - } - return null; - }); - await openBoxes(false, null); + await testSetUpTempDirForHive(); final flamante = rootBundle.load('google_fonts/OpenSans-Medium.ttf'); final fontLoader = FontLoader('OpenSans')..addFont(flamante); await fontLoader.load(); From 5896ff71595f3476fbf516f5baf9d91bc7cf7a73 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 05:15:49 +0530 Subject: [PATCH 08/14] update --- pubspec.lock | 18 +++++++++--------- pubspec.yaml | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 2c257859..c17219a4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -259,10 +259,10 @@ packages: dependency: "direct main" description: name: dart_style - sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" url: "https://pub.dev" source: hosted - version: "2.3.6" + version: "2.3.7" dartx: dependency: transitive description: @@ -596,10 +596,10 @@ packages: dependency: "direct main" description: name: fvp - sha256: "6462fd078de4478a0990d437463897036cff98aff3f0ac9efbbf817c99654c87" + sha256: "040aa12beccd5bc60631259f27a481c4abc11a389aa4f57a47b643f58fe0b060" url: "https://pub.dev" source: hosted - version: "0.24.1" + version: "0.26.1" glob: dependency: transitive description: @@ -778,10 +778,10 @@ packages: dependency: "direct main" description: name: just_audio - sha256: ee50602364ba83fa6308f5512dd560c713ec3e1f2bc75f0db43618f0d82ef71a + sha256: d8e8aaf417d33e345299c17f6457f72bd4ba0c549dc34607abb5183a354edc4d url: "https://pub.dev" source: hosted - version: "0.9.39" + version: "0.9.40" just_audio_mpv: dependency: "direct main" description: @@ -1552,10 +1552,10 @@ packages: dependency: "direct main" description: name: uuid - sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" + sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77 url: "https://pub.dev" source: hosted - version: "4.4.2" + version: "4.5.0" vector_graphics: dependency: transitive description: @@ -1727,4 +1727,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.5.0-259.0.dev <3.999.0" - flutter: ">=3.22.0" + flutter: ">=3.24.3" diff --git a/pubspec.yaml b/pubspec.yaml index a9bf5998..41d4f3d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.4.0+4 environment: sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.19.0" + flutter: ">=3.24.3" dependencies: flutter: @@ -18,7 +18,7 @@ dependencies: url: https://github.com/foss42/curl_converter.git ref: 726e8cd04aeb326211af27f75920be5b21c90bb4 data_table_2: ^2.5.15 - dart_style: ^2.3.6 + dart_style: ^2.3.7 desktop_drop: ^0.4.4 extended_text_field: ^16.0.0 file_selector: ^1.0.3 @@ -30,7 +30,7 @@ dependencies: flutter_svg: ^2.0.10+1 flutter_typeahead: ^5.2.0 freezed_annotation: ^2.4.1 - fvp: ^0.24.1 + fvp: ^0.26.1 google_fonts: ^6.2.1 highlighter: ^0.1.1 hive_flutter: ^1.1.0 @@ -45,7 +45,7 @@ dependencies: url: https://github.com/foss42/json_data_explorer.git ref: b7dde2f85dff4f482eed7eda4ef2a71344ef8b3a json_text_field: ^1.2.0 - just_audio: ^0.9.34 + just_audio: ^0.9.40 just_audio_mpv: ^0.1.7 just_audio_windows: ^0.2.0 lottie: ^3.1.0 @@ -65,7 +65,7 @@ dependencies: scrollable_positioned_list: ^0.3.8 shared_preferences: ^2.3.2 url_launcher: ^6.2.5 - uuid: ^4.3.3 + uuid: ^4.5.0 vector_graphics_compiler: ^1.1.9+1 video_player: ^2.8.7 video_player_platform_interface: ^6.2.2 From 552d735da786803593ea73b9ec4c5af4b2a340b2 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 05:19:08 +0530 Subject: [PATCH 09/14] Update request_form_data.dart --- .../editor_pane/details_card/request_pane/request_form_data.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart index 35c34066..41671bc7 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart @@ -43,7 +43,6 @@ class _FormDataBodyState extends ConsumerState { .select((value) => value?.httpRequestModel?.formData?.length)); var rF = ref.read(selectedRequestModelProvider)?.httpRequestModel?.formData; bool isFormDataEmpty = rF == null || rF.isEmpty; - formRows = isFormDataEmpty ? [ kFormDataEmptyModel, From edf8c523c823df723243470918ac1b2bdb3ee085 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 15:55:22 +0530 Subject: [PATCH 10/14] Update hive_services.dart --- lib/services/hive_services.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/services/hive_services.dart b/lib/services/hive_services.dart index 9f703ef3..cec74101 100644 --- a/lib/services/hive_services.dart +++ b/lib/services/hive_services.dart @@ -25,21 +25,23 @@ Future initHiveBoxes( } else { await Hive.initFlutter(); } - await openHiveBoxes(); - return true; + final openHiveBoxesStatus = await openHiveBoxes(); + return openHiveBoxesStatus; } catch (e) { return false; } } -Future openHiveBoxes() async { +Future openHiveBoxes() async { try { await Hive.openBox(kDataBox); await Hive.openBox(kEnvironmentBox); await Hive.openBox(kHistoryMetaBox); await Hive.openLazyBox(kHistoryLazyBox); + return true; } catch (e) { debugPrint("ERROR OPEN HIVE BOXES: $e"); + return false; } } From 31c84da762941c1ba48fb05289820901b27d1a55 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 16:52:25 +0530 Subject: [PATCH 11/14] Update request_body.dart --- .../details_card/request_pane/request_body.dart | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart index c70f54d3..e0e39628 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart @@ -18,21 +18,16 @@ class EditRequestBody extends ConsumerWidget { final contentType = ref.watch(selectedRequestModelProvider .select((value) => value?.httpRequestModel?.bodyContentType)); + final sm = ScaffoldMessenger.of(context); void changeToPostMethod() { - RequestModel? model = ref - .read(collectionStateNotifierProvider.notifier) - .getRequestModel(selectedId); - - if (model!.httpRequestModel!.method == HTTPVerb.get) { + if (requestModel?.httpRequestModel!.method == HTTPVerb.get) { ref .read(collectionStateNotifierProvider.notifier) .update(selectedId, method: HTTPVerb.post); - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text( - "Switched to POST method", - style: TextStyle(color: Colors.white), - ), - backgroundColor: Colors.black, + sm.hideCurrentSnackBar(); + sm.showSnackBar(getSnackBar( + "Switched to POST method", + small: false, )); } } From d9ec943d4055523f8949b94c382c4d3c0a46d59c Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 17:01:16 +0530 Subject: [PATCH 12/14] Update request_form_data.dart --- .../details_card/request_pane/request_form_data.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart index 41671bc7..9b0bb123 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart @@ -9,8 +9,7 @@ import 'package:apidash/utils/utils.dart'; import 'package:apidash/consts.dart'; class FormDataWidget extends ConsumerStatefulWidget { - final Function changeMethodToPost; - const FormDataWidget({required this.changeMethodToPost, super.key}); + const FormDataWidget({super.key}); @override ConsumerState createState() => _FormDataBodyState(); } @@ -28,7 +27,6 @@ class _FormDataBodyState extends ConsumerState { } void _onFieldChange(String selectedId) { - widget.changeMethodToPost(); ref.read(collectionStateNotifierProvider.notifier).update( selectedId, formData: formRows.sublist(0, formRows.length - 1), From c6c215ace138e22abf5bd1e508ba4f2386c070a2 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 17:02:43 +0530 Subject: [PATCH 13/14] Update request_body.dart --- .../request_pane/request_body.dart | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart index e0e39628..86ac5a2f 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart @@ -1,4 +1,3 @@ -import 'package:apidash/models/models.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:apidash/providers/providers.dart'; @@ -18,19 +17,20 @@ class EditRequestBody extends ConsumerWidget { final contentType = ref.watch(selectedRequestModelProvider .select((value) => value?.httpRequestModel?.bodyContentType)); - final sm = ScaffoldMessenger.of(context); - void changeToPostMethod() { - if (requestModel?.httpRequestModel!.method == HTTPVerb.get) { - ref - .read(collectionStateNotifierProvider.notifier) - .update(selectedId, method: HTTPVerb.post); - sm.hideCurrentSnackBar(); - sm.showSnackBar(getSnackBar( - "Switched to POST method", - small: false, - )); - } - } + // TODO: #178 GET->POST Currently switches to POST everytime user edits body even if the user intentionally chooses GET + // final sm = ScaffoldMessenger.of(context); + // void changeToPostMethod() { + // if (requestModel?.httpRequestModel!.method == HTTPVerb.get) { + // ref + // .read(collectionStateNotifierProvider.notifier) + // .update(selectedId, method: HTTPVerb.post); + // sm.hideCurrentSnackBar(); + // sm.showSnackBar(getSnackBar( + // "Switched to POST method", + // small: false, + // )); + // } + // } return Column( children: [ @@ -48,11 +48,12 @@ class EditRequestBody extends ConsumerWidget { ), Expanded( child: switch (contentType) { - ContentType.formdata => Padding( + ContentType.formdata => const Padding( padding: kPh4, child: FormDataWidget( - changeMethodToPost: changeToPostMethod, - )), + // TODO: See changeToPostMethod above + // changeMethodToPost: changeToPostMethod, + )), // TODO: Fix JsonTextFieldEditor & plug it here ContentType.json => Padding( padding: kPt5o10, @@ -61,7 +62,7 @@ class EditRequestBody extends ConsumerWidget { fieldKey: "$selectedId-json-body-editor", initialValue: requestModel?.httpRequestModel?.body, onChanged: (String value) { - changeToPostMethod(); + // changeToPostMethod(); ref .read(collectionStateNotifierProvider.notifier) .update(selectedId, body: value); @@ -75,7 +76,7 @@ class EditRequestBody extends ConsumerWidget { fieldKey: "$selectedId-body-editor", initialValue: requestModel?.httpRequestModel?.body, onChanged: (String value) { - changeToPostMethod(); + // changeToPostMethod(); ref .read(collectionStateNotifierProvider.notifier) .update(selectedId, body: value); From c1a937497d429fcdf4ea1d8d4535b6095f2aa214 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 16 Sep 2024 17:05:40 +0530 Subject: [PATCH 14/14] Update collection_providers_test.dart --- test/providers/collection_providers_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/providers/collection_providers_test.dart b/test/providers/collection_providers_test.dart index 1abd8123..fb939522 100644 --- a/test/providers/collection_providers_test.dart +++ b/test/providers/collection_providers_test.dart @@ -50,5 +50,5 @@ void main() async { // Verify that the Snackbar is shown expect(find.text('Switched to POST method'), findsOneWidget); - }); + }, skip: true); }